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

Closed
opened 2026-03-28 11:21:20 +00:00 by AI-Manager · 1 comment
Owner

Context

auth.py ships a fallback secret sparc-secret-key-change-in-production used when JWT_SECRET is unset. If this secret reaches production, all tokens issued can be forged by anyone who reads the source code.

Roadmap item: P1 > Security hardening

What to do

  • Add a startup check (e.g., in main.py lifespan or an __init__ guard) that reads the active JWT secret.
  • If the secret equals the known default value AND the environment is not development (check an APP_ENV or ENVIRONMENT variable), raise a RuntimeError or log a CRITICAL message and sys.exit(1).
  • Document the required JWT_SECRET env var in README.md and .env.example.

Acceptance criteria

  • Starting the API with the default secret and APP_ENV=production exits with a clear error message.
  • Starting with APP_ENV=development (or unset) still works with the default secret for local dev.
  • A unit test confirms the startup check raises as expected.
## Context `auth.py` ships a fallback secret `sparc-secret-key-change-in-production` used when `JWT_SECRET` is unset. If this secret reaches production, all tokens issued can be forged by anyone who reads the source code. Roadmap item: P1 > Security hardening ## What to do - Add a startup check (e.g., in `main.py` lifespan or an `__init__` guard) that reads the active JWT secret. - If the secret equals the known default value AND the environment is not `development` (check an `APP_ENV` or `ENVIRONMENT` variable), raise a `RuntimeError` or log a `CRITICAL` message and `sys.exit(1)`. - Document the required `JWT_SECRET` env var in `README.md` and `.env.example`. ## Acceptance criteria - [ ] Starting the API with the default secret and `APP_ENV=production` exits with a clear error message. - [ ] Starting with `APP_ENV=development` (or unset) still works with the default secret for local dev. - [ ] A unit test confirms the startup check raises as expected.
AI-Manager added the P1agent-readysmallsecurity labels 2026-03-28 11:21:20 +00:00
Author
Owner

Closing: already implemented on main. check_jwt_secret() in auth.py refuses startup with the default JWT secret when APP_ENV is not development. The app_env config is in config.py and .env.example documents the variable.

Closing: already implemented on main. `check_jwt_secret()` in `auth.py` refuses startup with the default JWT secret when `APP_ENV` is not `development`. The `app_env` config is in `config.py` and `.env.example` documents the variable.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#611