Security & Authentication
Relevant source files
The following files were used as context for generating this wiki page:
OpenAlgo is a self-hosted algorithmic trading platform designed with a single-user deployment model, meaning there is no multi-user support or privilege escalation within a single instance. Security is a critical pillar of the architecture given the sensitive nature of financial operations and broker credentials. The system employs a defense-in-depth strategy encompassing password hashing, encrypted storage for broker tokens, and localized execution environments to ensure that data remains under the user's control.
Sources: CLAUDE.md:65-66, README.md:162-171
Core Security Architecture
The platform's security is built on the principle of "Privacy First," ensuring zero data collection where all information stays on the user's server. The architecture utilizes several layers of protection, from the web server down to the database level.
Authentication Mechanisms
- Administrator Setup: The initial setup requires the creation of an administrator account with strict password requirements, including length, case sensitivity, and special characters. Sources: frontend/src/pages/Setup.tsx:186-224
- Two-Factor Authentication (2FA): OpenAlgo supports TOTP (Time-based One-Time Password) via authenticator apps for secure login and account recovery. Sources: CLAUDE.md:70, README.md:165
- Password Hashing: Passwords are secured using Argon2 or Bcrypt hashing algorithms to prevent unauthorized access even if the database is compromised. Sources: SECURITY.md:68, README.md:163
Request Protection
The request pipeline involves multiple layers of middleware to sanitize and validate incoming traffic before it reaches the application logic.
The request flow starts with traffic logging and security middleware (handling IP bans and 403 errors), followed by Flask's internal routing, CSRF protection, and session management before finally reaching the API key authentication layer for external platforms. Sources: CLAUDE.md:129-136
Data Protection and Encryption
Sensitive information, particularly broker credentials and API keys, are never stored in plain text. OpenAlgo utilizes industry-standard encryption methods to protect data at rest and in transit.
Encryption Standards
| Component | Protection Method | Description |
|---|---|---|
| Passwords | Argon2 / Bcrypt | High-entropy hashing for user credentials. |
| Broker Tokens | Fernet / AES | Encrypted at rest; tokens typically expire daily. |
| API Keys | Hashed with Pepper | Keys are hashed with a unique server-side pepper before storage. |
| Sessions | Secure Cookies | Encrypted session cookies with CSRF protection. |
Sources: SECURITY.md:64-70, README.md:163-164, CLAUDE.md:214-215
Secret Management
Official installation scripts auto-generate unique APP_KEY and API_KEY_PEPPER values using secrets.token_hex(32). These secrets are stored in the .env file and are critical for the encryption and hashing operations performed by the platform. Sources: CLAUDE.md:68-69, blueprints/admin.py:649-688
API and Integration Security
OpenAlgo exposes multiple surfaces (REST API, WebSocket, and MCP) that each require specific security protocols.
Unified Broker API (/api/v1/)
External platforms like TradingView or Amibroker send API keys either in the JSON body or as URL query parameters. This is an architectural trade-off as these platforms often cannot set custom HTTP headers. API keys are generated via the /apikey route and are stored as salted hashes. Sources: CLAUDE.md:73-75, CLAUDE.md:214-216
Remote MCP (Model Context Protocol)
The Remote MCP feature allows AI clients to connect via OAuth 2.1 with PKCE. It includes a robust threat model to prevent unauthorized order placement.
The Remote MCP security model enforces a 15-minute Time-To-Live (TTL) for access tokens, mandatory PKCE, and an admin approval gate for every newly registered client. Sources: install/Remote-MCP-readme.md:16-25, install/Remote-MCP-readme.md:233-247
Administrative Security Controls
The administrator dashboard provides tools for monitoring the security posture of the instance and responding to threats.
Security Monitoring
- IP Ban System: Admins can manually ban suspicious IP addresses via the
/securitydashboard. Sources: README.md:167 - Audit Logs: The system maintains detailed audit logs for various operations, including the
log/mcp.jsonlfor tool calls andlog/errors.jsonlfor system errors. Sources: blueprints/admin.py:605-645, install/Remote-MCP-readme.md:215-225 - Diagnostics: The platform includes built-in diagnostics to check the strength of secrets (e.g., ensuring
APP_KEYis not a default placeholder) and verifying that sensitive environment variables are correctly set. Sources: blueprints/admin.py:649-688
Critical Security Constraints
- FLASK_DEBUG: Remote MCP cannot be enabled if
FLASK_DEBUG=True, as debug-mode tracebacks could leak bearer tokens. Sources: install/Remote-MCP-readme.md:246 - Single Worker: Production deployments must run with a single Gunicorn worker (
-w 1) to ensure Flask-SocketIO state remains consistent and secure within a single process. Sources: CLAUDE.md:84-86
Summary
Security in OpenAlgo is centered on the user's server as the ultimate source of trust. By combining modern hashing techniques, deterministic token encryption, and a strictly controlled administrative layer, the platform mitigates common web vulnerabilities and protects sensitive broker integrations. Users are responsible for maintaining the security of their own hosting environment, including rotating API keys if compromised and ensuring the registered static IP for transactional orders remains secure. Sources: SECURITY.md:29-39, CLAUDE.md:70-72