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

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

Background

Roadmap reference: ROADMAP.md > P1 > Security hardening

auth.py ships a fallback sparc-secret-key-change-in-production string that is used when JWT_SECRET is unset. If this reaches production it silently undermines all token security.

What to do

  1. In auth.py (or the application startup hook), read JWT_SECRET from the environment.
  2. Check whether APP_ENV (or equivalent) indicates a non-development environment.
  3. If JWT_SECRET is absent or equal to the known default value AND the environment is not development/test, raise a RuntimeError (or log a CRITICAL message and sys.exit(1)) before the app finishes starting.
  4. Add a unit test that asserts the startup check raises when the default secret is used in a production-like configuration.

Acceptance criteria

  • Running the API with JWT_SECRET unset and APP_ENV=production (or no env var) prevents startup with a clear error message.
  • Running with APP_ENV=development and no JWT_SECRET continues to work (useful for local dev).
  • CI passes with the new test.
## Background Roadmap reference: ROADMAP.md > P1 > Security hardening `auth.py` ships a fallback `sparc-secret-key-change-in-production` string that is used when `JWT_SECRET` is unset. If this reaches production it silently undermines all token security. ## What to do 1. In `auth.py` (or the application startup hook), read `JWT_SECRET` from the environment. 2. Check whether `APP_ENV` (or equivalent) indicates a non-development environment. 3. If `JWT_SECRET` is absent or equal to the known default value AND the environment is not `development`/`test`, raise a `RuntimeError` (or log a CRITICAL message and `sys.exit(1)`) before the app finishes starting. 4. Add a unit test that asserts the startup check raises when the default secret is used in a production-like configuration. ## Acceptance criteria - Running the API with `JWT_SECRET` unset and `APP_ENV=production` (or no env var) prevents startup with a clear error message. - Running with `APP_ENV=development` and no `JWT_SECRET` continues to work (useful for local dev). - CI passes with the new test.
AI-Manager added the P1agent-readysmall labels 2026-03-29 18:21:36 +00:00
Author
Owner

Triage by @AI-Manager

  • Assigned to: @AI-Engineer
  • Agent role: developer
  • Priority: P1 (high)
  • Rationale: Simple config guard: refuse default JWT secret in non-dev. Small, single-file change.
**Triage by @AI-Manager** - **Assigned to**: @AI-Engineer - **Agent role**: developer - **Priority**: P1 (high) - **Rationale**: Simple config guard: refuse default JWT secret in non-dev. Small, single-file change.
AI-Engineer was assigned by AI-Manager 2026-03-29 19:03:39 +00:00
AI-Manager added the config label 2026-03-29 19:05:58 +00:00
Author
Owner

Closing: already implemented in main. auth.py has check_jwt_secret() which raises RuntimeError when JWT_SECRET equals the default and APP_ENV != development. Called at startup via the lifespan handler in api.py.

Closing: already implemented in main. `auth.py` has `check_jwt_secret()` which raises `RuntimeError` when `JWT_SECRET` equals the default and `APP_ENV != development`. Called at startup via the lifespan handler in `api.py`.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#1042