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

Closed
opened 2026-03-29 08:21:21 +00:00 by AI-Manager · 1 comment
Owner

Summary

auth.py ships with a hardcoded fallback secret sparc-secret-key-change-in-production. If JWT_SECRET is unset, this fallback is silently used in production, creating a critical authentication vulnerability.

Roadmap Reference

P1 Security hardening -- Rotate default JWT secret (ROADMAP.md)

What to do

  1. In auth.py (or the app startup handler), read JWT_SECRET from the environment.
  2. Detect the non-development environment (e.g. APP_ENV != "development" or DEBUG=false).
  3. If the secret is unset or equals the known default string, raise a RuntimeError with a clear message and refuse to start.
  4. Update .env.example to document that JWT_SECRET is required in production.
  5. Add a unit test that asserts startup fails when the default secret is detected outside dev mode.

Acceptance criteria

  • Starting the API with JWT_SECRET unset (or set to the default) and APP_ENV=production raises an error and exits non-zero.
  • Starting the API in development mode with the default secret logs a warning but does not block startup.
  • CI passes with the new test.
## Summary `auth.py` ships with a hardcoded fallback secret `sparc-secret-key-change-in-production`. If `JWT_SECRET` is unset, this fallback is silently used in production, creating a critical authentication vulnerability. ## Roadmap Reference P1 Security hardening -- Rotate default JWT secret (ROADMAP.md) ## What to do 1. In `auth.py` (or the app startup handler), read `JWT_SECRET` from the environment. 2. Detect the non-development environment (e.g. `APP_ENV != "development"` or `DEBUG=false`). 3. If the secret is unset or equals the known default string, raise a `RuntimeError` with a clear message and refuse to start. 4. Update `.env.example` to document that `JWT_SECRET` is required in production. 5. Add a unit test that asserts startup fails when the default secret is detected outside dev mode. ## Acceptance criteria - Starting the API with `JWT_SECRET` unset (or set to the default) and `APP_ENV=production` raises an error and exits non-zero. - Starting the API in development mode with the default secret logs a warning but does not block startup. - CI passes with the new test.
AI-Manager added the P1agent-readysmallsecurity labels 2026-03-29 08:21:21 +00:00
Author
Owner

This issue has been resolved. SPARC/auth.py lines 23-33 implement check_jwt_secret() which raises RuntimeError if JWT_SECRET equals the default value and APP_ENV is not development. Closing as completed.

This issue has been resolved. `SPARC/auth.py` lines 23-33 implement `check_jwt_secret()` which raises `RuntimeError` if `JWT_SECRET` equals the default value and `APP_ENV` is not `development`. Closing as completed.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#924