3.5 KiB
Project: API Security Hardening (V3)
Status: Complete / Archived (Reviewed March 18, 2026) Date: Jan 18, 2026 Owner: Scott / Aether API Team
This plan was fully implemented and reviewed on March 18, 2026. All critical and high vulnerabilities described have been addressed in the current codebase. See dependencies in
app/routers/dependencies_v3.pyand JWT logic inapp/lib_jwt.pyfor details.
1. Executive Summary
This project aims to close a critical security vulnerability in the Aether API V3 dependencies where the x_no_account_id header allows unauthorized "Superuser/Bypass" access without validation. Additionally, it addresses the lack of cryptographic verification for JWTs in the V3 CRUD layer.
2. The Vulnerabilities
A. The "Bypass Header" (Critical)
- Issue: The
get_account_context_optionaldependency inapp/routers/dependencies_v3.pyaccepts a headerx_no_account_id. If present, it setsauth_method = 'bypass'and grants full administrative privileges (super=True). - Note: This header may be sent as
x_no_account_idorx-no-account-id. FastAPI'sHeaderlogic should handle the conversion, but validation must be explicit. - Current State: There is no validation of this header. Sending
x_no_account_id: anythingworks. - Risk: Total system compromise via simple header injection.
B. JWT Verification (High)
- Issue: The system validates users by looking up the
x_account_idstring in the database (Redis/MariaDB). - Current State: It does not cryptographically verify the JWT signature or expiration in the V3 dependency chain.
- Risk: Account impersonation if an Account ID is leaked.
3. Implementation Plan
Phase 1: Secure the Bypass Header (Immediate)
Goal: Restrict "Bypass Mode" to clients possessing a valid, active API Key.
-
Refactor Dependencies:
- Update
get_account_context_optionalto acceptx_aether_api_key. - Logic Change: If
x_no_account_idheader is detected:- Require
x_aether_api_key. - Lookup key in
api_keytable. - Verify
enable = 1andnow()is betweenenable_fromandenable_to.
- Require
- Failure Behavior: If key is invalid/missing, log warning and deny 'bypass' status (fall back to 'guest').
- Update
-
Verification:
- Test
curlwith header only -> Expect 403/Forbidden. - Test
curlwith header + valid Key -> Expect 200/OK. - Test Frontend File Download (uses
x_no_account_id_tokenparam) -> Expect 200/OK (No regression).
- Test
Phase 2: JWT Verification (Subsequent)
Goal: Replace DB-lookup auth with cryptographic JWT validation.
- Audit: Confirm
app/lib_jwt.pylogic is sound. - Middleware/Dependency: Integrate
decode_jwtinto theget_account_contextflow. - Transition: Allow dual-mode (DB lookup OR JWT) for a transition period if necessary, or cut over if frontend sends valid JWTs.
4. Impact Analysis
- Frontend (SvelteKit):
- Audit confirmed no usage of
x_no_account_idheader in active source code. - Usage of
x_no_account_id_token(Query Param) is safe and distinct from the header logic.
- Audit confirmed no usage of
- Scripts/External Tools:
- Any external scripts using the "Bypass" header must be updated to send a valid API Key.
5. Action Items
- Create
PROJECT_SECURITY_HARDENING.md(This document). - Refactor
app/routers/dependencies_v3.py. - Verify fix with
curltests. - Commit changes.