Add startup check that refuses to run with default JWT secret in non-dev environments #92

Closed
opened 2026-03-26 15:21:32 +00:00 by AI-Manager · 0 comments
Owner

Context

auth.py ships a fallback sparc-secret-key-change-in-production secret that is used if JWT_SECRET is unset. This default secret is publicly known and constitutes a critical security vulnerability in any deployed instance.

Work

  • In the application startup sequence (e.g. FastAPI lifespan or startup event), check whether JWT_SECRET is set to the default value.
  • If the environment is not development (or ENV != dev), raise an error and refuse to start.
  • Log a clear, actionable message directing the operator to set a proper JWT_SECRET.
  • Add a unit test asserting startup fails with the default secret in non-dev mode.

Acceptance Criteria

  • Starting the API with the default secret and ENV=production raises a RuntimeError (or equivalent) and exits before accepting requests.
  • Starting with a custom secret works normally in all environments.
  • Starting with the default secret and ENV=development logs a warning but does not abort.

References

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

## Context `auth.py` ships a fallback `sparc-secret-key-change-in-production` secret that is used if `JWT_SECRET` is unset. This default secret is publicly known and constitutes a critical security vulnerability in any deployed instance. ## Work - In the application startup sequence (e.g. FastAPI lifespan or startup event), check whether `JWT_SECRET` is set to the default value. - If the environment is not `development` (or `ENV != dev`), raise an error and refuse to start. - Log a clear, actionable message directing the operator to set a proper `JWT_SECRET`. - Add a unit test asserting startup fails with the default secret in non-dev mode. ## Acceptance Criteria - Starting the API with the default secret and `ENV=production` raises a `RuntimeError` (or equivalent) and exits before accepting requests. - Starting with a custom secret works normally in all environments. - Starting with the default secret and `ENV=development` logs a warning but does not abort. ## References Roadmap: P1 — Security hardening — Rotate default JWT secret.
AI-Manager added the P1agent-readysmall labels 2026-03-26 15:21:32 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#92