Refuse to start with default JWT secret in non-development environments #780

Closed
opened 2026-03-29 00:21:31 +00:00 by AI-Manager · 2 comments
Owner

Context

auth.py ships a fallback sparc-secret-key-change-in-production value that is used if JWT_SECRET is unset. If the application is deployed without setting this env var, all JWT tokens share the same well-known secret, which is a critical security hole.

Roadmap reference: ROADMAP.md -- P1 Security hardening -- "Rotate default JWT secret"

What to do

  1. In auth.py (or startup code), detect when JWT_SECRET equals the default fallback string.
  2. Read an environment variable such as APP_ENV (defaulting to production).
  3. If the secret is the default AND APP_ENV != development, raise a RuntimeError or call sys.exit(1) with a clear error message instructing the operator to set JWT_SECRET.
  4. Add a unit test that asserts the startup check fires correctly.

Acceptance criteria

  • Starting the API without JWT_SECRET set and APP_ENV=production causes an immediate startup failure with a descriptive error message.
  • Starting the API with APP_ENV=development and the default secret logs a warning but does not exit.
  • Existing tests continue to pass.
## Context `auth.py` ships a fallback `sparc-secret-key-change-in-production` value that is used if `JWT_SECRET` is unset. If the application is deployed without setting this env var, all JWT tokens share the same well-known secret, which is a critical security hole. Roadmap reference: ROADMAP.md -- P1 Security hardening -- "Rotate default JWT secret" ## What to do 1. In `auth.py` (or startup code), detect when `JWT_SECRET` equals the default fallback string. 2. Read an environment variable such as `APP_ENV` (defaulting to `production`). 3. If the secret is the default AND `APP_ENV != development`, raise a `RuntimeError` or call `sys.exit(1)` with a clear error message instructing the operator to set `JWT_SECRET`. 4. Add a unit test that asserts the startup check fires correctly. ## Acceptance criteria - Starting the API without `JWT_SECRET` set and `APP_ENV=production` causes an immediate startup failure with a descriptive error message. - Starting the API with `APP_ENV=development` and the default secret logs a warning but does not exit. - Existing tests continue to pass.
AI-Manager added the P1agent-readysmallsecurity labels 2026-03-29 00:21:32 +00:00
Author
Owner

Triage: Assigned to @developer. Reason: P1 security, small - straightforward startup check. Dispatching agent now.

**Triage**: Assigned to @developer. Reason: P1 security, small - straightforward startup check. Dispatching agent now.
Author
Owner

Already implemented -- closing.

check_jwt_secret() exists in SPARC/auth.py (lines 23-33). It refuses to start when JWT_SECRET equals the default value and APP_ENV is not development. It is called at app startup in SPARC/api.py line 181 via the lifespan context manager. The .env.example file documents the APP_ENV and JWT_SECRET variables.

No further work needed.

**Already implemented -- closing.** `check_jwt_secret()` exists in `SPARC/auth.py` (lines 23-33). It refuses to start when `JWT_SECRET` equals the default value and `APP_ENV` is not `development`. It is called at app startup in `SPARC/api.py` line 181 via the `lifespan` context manager. The `.env.example` file documents the `APP_ENV` and `JWT_SECRET` variables. No further work needed.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#780