Add startup check to refuse default JWT secret in non-dev environments #39

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

Problem

auth.py ships a fallback secret sparc-secret-key-change-in-production that is used when JWT_SECRET is unset. If this default is left in place in a production deployment, all issued tokens are trivially forgeable.

Task

  • Add a startup check (e.g., in a FastAPI lifespan event or __init__) that detects when the configured JWT secret matches the known default value.
  • In non-development environments (i.e., when ENV != "development" or similar), raise a fatal error and refuse to start.
  • Update .env.example or documentation to clearly indicate JWT_SECRET must be set.

Acceptance Criteria

  • Starting the API with the default secret and ENV=production causes an immediate startup failure with a clear error message.
  • Starting with a custom secret in any environment succeeds.
  • Starting with the default secret in ENV=development only emits a warning (does not block startup).
  • Unit test covers the startup check logic.

References

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

## Problem `auth.py` ships a fallback secret `sparc-secret-key-change-in-production` that is used when `JWT_SECRET` is unset. If this default is left in place in a production deployment, all issued tokens are trivially forgeable. ## Task - Add a startup check (e.g., in a FastAPI lifespan event or `__init__`) that detects when the configured JWT secret matches the known default value. - In non-development environments (i.e., when `ENV != "development"` or similar), raise a fatal error and refuse to start. - Update `.env.example` or documentation to clearly indicate `JWT_SECRET` must be set. ## Acceptance Criteria - Starting the API with the default secret and `ENV=production` causes an immediate startup failure with a clear error message. - Starting with a custom secret in any environment succeeds. - Starting with the default secret in `ENV=development` only emits a warning (does not block startup). - Unit test covers the startup check logic. ## References Roadmap: P1 -- Security hardening -- Rotate default JWT secret.
AI-Manager added the P1agent-readysmall labels 2026-03-26 08:21:38 +00:00
Author
Owner

Closing: Already implemented in PR #27 (feat(security): JWT startup guard, configurable CORS, externalize DB creds). config.py contains the startup check that refuses the default JWT secret in non-development environments.

Closing: Already implemented in PR #27 (feat(security): JWT startup guard, configurable CORS, externalize DB creds). config.py contains the startup check that refuses the default JWT secret in non-development environments.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#39