Security: refuse to start with default JWT secret in non-development environments #1309

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

Background

auth.py ships a fallback sparc-secret-key-change-in-production value that will be used if JWT_SECRET is unset. This is a critical security risk if the application is accidentally deployed to production without setting the secret.

What to do

  • In auth.py (or startup/lifespan code), read the JWT_SECRET environment variable.
  • If the value equals the default sparc-secret-key-change-in-production AND the ENVIRONMENT (or APP_ENV) variable is not development, raise a clear RuntimeError that prevents the application from starting.
  • Add a note in .env.example / documentation explaining the requirement.

Acceptance criteria

  • pytest passes with APP_ENV=development and the default secret.
  • Starting the app in any other env with the default secret logs a clear fatal error and exits non-zero.
  • No regression in existing auth tests.

References

Roadmap: P1 Security hardening — Rotate default JWT secret.

## Background `auth.py` ships a fallback `sparc-secret-key-change-in-production` value that will be used if `JWT_SECRET` is unset. This is a critical security risk if the application is accidentally deployed to production without setting the secret. ## What to do - In `auth.py` (or startup/lifespan code), read the `JWT_SECRET` environment variable. - If the value equals the default `sparc-secret-key-change-in-production` AND the `ENVIRONMENT` (or `APP_ENV`) variable is not `development`, raise a clear `RuntimeError` that prevents the application from starting. - Add a note in `.env.example` / documentation explaining the requirement. ## Acceptance criteria - `pytest` passes with `APP_ENV=development` and the default secret. - Starting the app in any other env with the default secret logs a clear fatal error and exits non-zero. - No regression in existing auth tests. ## References Roadmap: P1 Security hardening — Rotate default JWT secret.
AI-Manager added the P1agent-readysmallsecurity labels 2026-03-30 11:21:57 +00:00
Author
Owner

Already resolved. check_jwt_secret() in SPARC/auth.py raises RuntimeError when JWT_SECRET is the default value and APP_ENV != development. Called at startup in api.py lifespan. Tests in tests/test_security.py.

Already resolved. `check_jwt_secret()` in `SPARC/auth.py` raises `RuntimeError` when `JWT_SECRET` is the default value and `APP_ENV != development`. Called at startup in `api.py` lifespan. Tests in `tests/test_security.py`.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#1309