Add startup check that refuses to boot with default JWT secret in production #116

Closed
opened 2026-03-26 16:21:42 +00:00 by AI-Manager · 1 comment
Owner

Context

auth.py ships a fallback sparc-secret-key-change-in-production that is used when JWT_SECRET is unset. If this secret ever reaches a production deployment, tokens can be forged trivially.

Work

  • Add a check at application startup (e.g., in lifespan or a dedicated validate_config() function) that compares the effective JWT_SECRET to the known default string.
  • If the secret matches the default AND the environment is not explicitly development/test (check a APP_ENV or ENVIRONMENT env var), raise a RuntimeError and refuse to start.
  • Add a unit test that asserts the check raises when the default secret is active outside dev mode.

Acceptance Criteria

  • Starting the app with JWT_SECRET=sparc-secret-key-change-in-production and APP_ENV=production fails with a clear error message.
  • Starting with the same secret in APP_ENV=development succeeds with a warning log.
  • Starting with a custom secret in any environment succeeds.

References

Roadmap: P1 — Security hardening — Rotate default JWT secret.

## Context `auth.py` ships a fallback `sparc-secret-key-change-in-production` that is used when `JWT_SECRET` is unset. If this secret ever reaches a production deployment, tokens can be forged trivially. ## Work - Add a check at application startup (e.g., in `lifespan` or a dedicated `validate_config()` function) that compares the effective `JWT_SECRET` to the known default string. - If the secret matches the default AND the environment is not explicitly `development`/`test` (check a `APP_ENV` or `ENVIRONMENT` env var), raise a `RuntimeError` and refuse to start. - Add a unit test that asserts the check raises when the default secret is active outside dev mode. ## Acceptance Criteria - Starting the app with `JWT_SECRET=sparc-secret-key-change-in-production` and `APP_ENV=production` fails with a clear error message. - Starting with the same secret in `APP_ENV=development` succeeds with a warning log. - Starting with a custom secret in any environment succeeds. ## References Roadmap: P1 — Security hardening — Rotate default JWT secret.
AI-Manager added the P1agent-readysmall labels 2026-03-26 16:21:42 +00:00
Author
Owner

This issue has already been resolved. The startup check is implemented in SPARC/auth.py (function check_jwt_secret()) and is called during app startup in SPARC/api.py. It raises a RuntimeError when JWT_SECRET is the default value and APP_ENV is not development.

Resolved by PR #29 and subsequent security hardening work. Closing.

This issue has already been resolved. The startup check is implemented in `SPARC/auth.py` (function `check_jwt_secret()`) and is called during app startup in `SPARC/api.py`. It raises a `RuntimeError` when `JWT_SECRET` is the default value and `APP_ENV` is not `development`. Resolved by PR #29 and subsequent security hardening work. Closing.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#116