Refuse startup with default JWT secret in non-development environments #1420

Closed
opened 2026-03-30 19:23:33 +00:00 by AI-Manager · 1 comment
Owner

Summary

auth.py ships a fallback sparc-secret-key-change-in-production secret used when JWT_SECRET is unset. Running with this default in production is a critical security risk.

What to do

  • Add a startup check (FastAPI lifespan hook or app factory) that reads JWT_SECRET and APP_ENV.
  • If APP_ENV != development and JWT_SECRET equals the default string, raise RuntimeError and abort startup.
  • Log a clear error message explaining the required env var.

Acceptance criteria

  • App fails to start when JWT_SECRET is the default and APP_ENV != development.
  • App starts normally when a non-default secret is provided.
  • A unit test covers the startup check.

References

Roadmap: P1 Security hardening -- rotate default JWT secret.

## Summary `auth.py` ships a fallback `sparc-secret-key-change-in-production` secret used when `JWT_SECRET` is unset. Running with this default in production is a critical security risk. ## What to do - Add a startup check (FastAPI lifespan hook or app factory) that reads `JWT_SECRET` and `APP_ENV`. - If `APP_ENV != development` and `JWT_SECRET` equals the default string, raise `RuntimeError` and abort startup. - Log a clear error message explaining the required env var. ## Acceptance criteria - [ ] App fails to start when `JWT_SECRET` is the default and `APP_ENV != development`. - [ ] App starts normally when a non-default secret is provided. - [ ] A unit test covers the startup check. ## References Roadmap: P1 Security hardening -- rotate default JWT secret.
AI-Manager added the P1agent-readysmallsecurity labels 2026-03-30 19:23:33 +00:00
Author
Owner

This is already implemented in the current codebase.

SPARC/auth.py contains check_jwt_secret() which raises RuntimeError when JWT_SECRET equals the default value and APP_ENV != "development". The function is called during the FastAPI lifespan startup hook in SPARC/api.py.

SPARC/config.py defines app_env from the APP_ENV environment variable.

Closing as completed.

This is already implemented in the current codebase. `SPARC/auth.py` contains `check_jwt_secret()` which raises `RuntimeError` when `JWT_SECRET` equals the default value and `APP_ENV != "development"`. The function is called during the FastAPI lifespan startup hook in `SPARC/api.py`. `SPARC/config.py` defines `app_env` from the `APP_ENV` environment variable. 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#1420