Architecture, Security and Limits
Last verified against: commit 6f2f20b (v1.0)
Estimated Read Time: 6 min
Status: built
This document covers operational limits, authentication boundaries, tenancy roles, and security architecture in Locus.
1. Rate Limiting Architecture
Locus enforces rate limits using a sliding window counter stored in the PostgreSQL database table rate_limit_events, guarded by transactional advisory locks (pg_advisory_xact_lock):
- Chat Sessions: 60 requests per minute per session token.
- Hosted Public Chat: 15 requests per minute per client IP.
- Secret API Keys: Configurable per key in
ApiKey.rate_limit_rpm(default 60 RPM). - Concurrency Isolation: Because rate checks use hash-keyed advisory locks (
hashtext(:bucket_key)), concurrent calls for the same bucket serialize cleanly without race conditions.
2. Vault Envelope Encryption
External database credentials and connector secrets are protected by envelope encryption:
- Secrets are encrypted with a per-tenant AES key using
AES-256-GCM. - The tenant key is encrypted under a master key sourced from the
LOCUS_MASTER_KEYSenvironment variable. - Additional Authenticated Data (AAD) binds the ciphertext to
f"{tenant_id}|{connector_id}|{purpose}", rendering ciphertexts unreadable if moved across tenant or connector boundaries. - Nonces are fresh 96-bit values generated via cryptographically random byte generation.
3. Session Authentication & CSRF Defense
- Console Sessions: Browser authentication uses an
HttpOnly,SameSite=Laxcookie namedlocus_session(flagged for HTTPS-only transport in production environments). - CSRF Defense: Mutating requests (POST, PUT, DELETE) require non-simple HTTP headers (such as
X-Requested-WithorContent-Type: application/json) to block cross-site execution.
4. Tenancy Roles and Permissions
Locus workspaces enforce strict role hierarchy:
| Role | Permissions |
|---|---|
owner | Full administrative control, billing, tenant deletion, member invitation |
admin | Connector configuration, assistant management, API key issuance |
member | Knowledge space exploration, evaluation runs, querying |
viewer | Read-only access to assistants and evaluation metrics |
Platform operators can be assigned is_platform_admin = True on the user record to manage system-wide settings across tenants.
5. Security Invariant Defect Disclosures
In accordance with Locus documentation standards, the following codebase behaviors deviate from recommended security baselines and are documented as known defects:
- Assistant System Prompt Editing: The endpoints
POST /assistantsandPUT /assistants/{id}currently permit callers to submit arbitrary raw strings forsystem_prompt. - Dev HMAC Token Acceptance: The end-user JWT verifier permits HMAC symmetric signatures (
HS256,HS384,HS512) whenALLOW_INSECURE_DEV_TOKENS=1or whenAPP_ENVis set todevortest. - JWKS Network Fetching: The end-user token validator will perform HTTP requests if a
jwks_urlis provided. Static PEM public keys should be configured instead to avoid network dependencies during token verification.
6. System Boundaries (What is NOT Built)
To maintain architectural focus, the following capabilities are explicitly outside the current system boundaries:
- Client SDKs: No native Python, Go, Java, or npm client packages exist; integrations use HTTP clients.
- Real-Time Token Generation:
/v1/chatsupports Server-Sent Events (SSE) transport, but chunks a completed response; real-time generation token delivery is not implemented. - Live Interactive Playground: No embedded code execution container is hosted inside the app.
- Analytics and Comments: No comment threads or telemetry tracking scripts exist.