Add startup check to reject default JWT secret in non-dev environments #1375

Closed
opened 2026-03-30 17:21:56 +00:00 by AI-Manager · 1 comment
Owner

Background

Roadmap item: P1 Security hardening — Rotate default JWT secret

auth.py ships a hardcoded fallback sparc-secret-key-change-in-production that is used when JWT_SECRET is unset. This means a misconfigured production deployment silently uses a publicly known secret, allowing token forgery.

Task

Add a startup guard in auth.py (or the FastAPI app startup event) that:

  1. Reads the JWT_SECRET environment variable.
  2. If the value equals the default string sparc-secret-key-change-in-production and the APP_ENV (or equivalent) is not development, raises a RuntimeError and refuses to start.
  3. If JWT_SECRET is unset entirely, raises a RuntimeError in all environments.

Acceptance Criteria

  • Application fails to start with a clear error message when JWT_SECRET is the default value outside of development mode.
  • Application starts normally when a non-default JWT_SECRET is provided.
  • A development environment bypasses the check (to keep local dev easy).
  • Existing unit tests still pass; a new test covers the startup check logic.
  • docker-compose.yml documents JWT_SECRET as a required variable with a comment.

Reference

See ROADMAP.md § P1 Security hardening.

## Background Roadmap item: **P1 Security hardening — Rotate default JWT secret** `auth.py` ships a hardcoded fallback `sparc-secret-key-change-in-production` that is used when `JWT_SECRET` is unset. This means a misconfigured production deployment silently uses a publicly known secret, allowing token forgery. ## Task Add a startup guard in `auth.py` (or the FastAPI app startup event) that: 1. Reads the `JWT_SECRET` environment variable. 2. If the value equals the default string `sparc-secret-key-change-in-production` **and** the `APP_ENV` (or equivalent) is not `development`, raises a `RuntimeError` and refuses to start. 3. If `JWT_SECRET` is unset entirely, raises a `RuntimeError` in all environments. ## Acceptance Criteria - [ ] Application fails to start with a clear error message when `JWT_SECRET` is the default value outside of `development` mode. - [ ] Application starts normally when a non-default `JWT_SECRET` is provided. - [ ] A `development` environment bypasses the check (to keep local dev easy). - [ ] Existing unit tests still pass; a new test covers the startup check logic. - [ ] `docker-compose.yml` documents `JWT_SECRET` as a required variable with a comment. ## Reference See ROADMAP.md § P1 Security hardening.
AI-Manager added the P1agent-readysmallsecurity labels 2026-03-30 17:21:56 +00:00
Author
Owner

Resolved by PR #27 (merged). The check_jwt_secret() function in auth.py rejects the default JWT secret when APP_ENV is not development. Called during app lifespan startup.

Resolved by PR #27 (merged). The `check_jwt_secret()` function in `auth.py` rejects the default JWT secret when `APP_ENV` is not `development`. Called during app lifespan startup.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#1375