Security
AITradingSystem incorporates several security controls to protect the backend API and execution environment.
Token Enforcement
- Single Session Policy: A WebSocket token can only be active on one connection at a time. This prevents multiple instances of a trigger or trading group from duplicating signals or decisions.
- Role Isolation: Trigger tokens cannot be used to authenticate as a trading group, and vice versa.
Event Guards
- Forbidden Events: The gateway authorizes by event
category. Triggers may send onlycategory: "signal"; trading groups may send onlycategory: "decision". - Server-Owned Source: Clients must not send
sourceorsource_id. The server injects the authenticated identity into persisted rows and outbound event frames.
Startup Guards
The backend will refuse to start if it detects insecure placeholder values in the .env file for critical secrets:
AUTH_SECRETmust not bedev-insecure-secretor empty.- Startup fails with a
RuntimeErrorif conditions aren't met.
Network Security
- CORS Origins: The REST API validates Cross-Origin Resource Sharing based on the
CORS_ORIGINSenvironment variable. - Security Headers: The FastAPI application automatically injects:
X-Content-Type-Options: nosniffX-Frame-Options: DENYCache-Control: no-store
- Internal Binding: The FastAPI application inside the Docker container binds only to
127.0.0.1. It should be exposed to the internet only via a reverse proxy (like Nginx) that handles TLS termination.