2.2 KiB
Auth Threat Model (Bot Service)
Date: 2026-02-15
Scope: REST API (/api/trade, /api/close, /api/chat) + websocket auth path + Supabase token verification
Security Objectives
- Only authenticated users can execute profile-bound trading actions.
- No cross-profile privilege escalation is allowed.
- Stolen/forged JWTs are rejected by issuer/audience policy when configured.
- Runtime controls produce auditable logs for rejected and accepted trade actions.
Trust Boundaries
- Browser/dashboard client (untrusted input boundary).
- Bot service API/websocket layer (authz/authn enforcement boundary).
- Supabase auth/token service (identity trust boundary).
- Exchange connectors (execution boundary).
Key Threats and Controls
-
Unauthenticated trade execution
Control:requireAuthmiddleware on sensitive REST routes and websocket auth middleware. -
Token replay/forgery with mismatched issuer/audience
Control:verifyAccessTokenvalidates via Supabaseauth.getUser(token)and optional claim checks:
SUPABASE_JWT_ISSUERSUPABASE_JWT_AUDIENCE
-
Cross-profile access (
profile_idnot owned by caller)
Control: profile ownership checks via Supabase before routing manual trade/close actions. -
Privilege abuse and request flooding
Control: route-level rate limits + audit logging (trade_request,close_request,chat_profile_control). -
Missing lifecycle accountability after execution
Control: deterministictrade_idflow, lifecycle reconciliation scripts, and websocket payload contract checks.
Assumptions
- Supabase access-token signature validation remains source-of-truth via
auth.getUser. - Service role key stays server-side only.
- TLS is enforced at deployment ingress.
Residual Risks
- If issuer/audience env vars are unset, claim restrictions are not enforced (intentional compatibility mode).
- Secret hygiene and repository history purge are operational tasks and remain outside runtime code controls.
Operational Requirements
- Set
SUPABASE_JWT_ISSUERandSUPABASE_JWT_AUDIENCEin production. - Keep route audit logs retained and monitored.
- Run CI security checks and gitleaks on every main branch change.