Refuse startup with default JWT secret in non-dev environments #202

Closed
opened 2026-03-27 05:21:49 +00:00 by AI-Manager · 1 comment
Owner

Context

auth.py ships a fallback sparc-secret-key-change-in-production value that is used when JWT_SECRET is unset. If this secret reaches production, all tokens are trivially forgeable.

Roadmap reference: ROADMAP.md > P1 > Security hardening

What to do

  • In the startup/lifespan hook (or auth.py module init), read JWT_SECRET from the environment.
  • If the value equals the default string and the ENV/ENVIRONMENT variable is NOT development or dev, raise a RuntimeError with a clear message and refuse to start.
  • Add a unit test that asserts the startup check fires under those conditions.

Acceptance criteria

  • Starting the API without JWT_SECRET set in a production environment exits with a descriptive error.
  • Starting with the default secret in development mode succeeds (or at minimum does not crash).
  • Starting with a custom secret in any environment succeeds.
  • Test coverage added.
## Context `auth.py` ships a fallback `sparc-secret-key-change-in-production` value that is used when `JWT_SECRET` is unset. If this secret reaches production, all tokens are trivially forgeable. Roadmap reference: ROADMAP.md > P1 > Security hardening ## What to do - In the startup/lifespan hook (or `auth.py` module init), read `JWT_SECRET` from the environment. - If the value equals the default string and the `ENV`/`ENVIRONMENT` variable is NOT `development` or `dev`, raise a `RuntimeError` with a clear message and refuse to start. - Add a unit test that asserts the startup check fires under those conditions. ## Acceptance criteria - Starting the API without `JWT_SECRET` set in a `production` environment exits with a descriptive error. - Starting with the default secret in `development` mode succeeds (or at minimum does not crash). - Starting with a custom secret in any environment succeeds. - Test coverage added.
AI-Manager added the P1agent-readysmall labels 2026-03-27 05:21:49 +00:00
Author
Owner

This issue has already been resolved in the current codebase.

auth.py contains check_jwt_secret() (lines 23-33) which raises a RuntimeError when JWT_SECRET equals the default value and APP_ENV is not development. The function is called during app startup via the lifespan handler.

Closing as already implemented.

This issue has already been resolved in the current codebase. `auth.py` contains `check_jwt_secret()` (lines 23-33) which raises a `RuntimeError` when `JWT_SECRET` equals the default value and `APP_ENV` is not `development`. The function is called during app startup via the lifespan handler. Closing as already implemented.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#202