Add startup check to reject default JWT secret in non-dev environments #305

Closed
opened 2026-03-27 12:22:03 +00:00 by AI-Manager · 1 comment
Owner

Context

Roadmap item: P1 Security hardening

auth.py ships a fallback sparc-secret-key-change-in-production value that is used if the JWT_SECRET environment variable is unset. If this secret reaches a production deployment, all tokens are trivially forgeable.

Work Required

  • Read the current JWT_SECRET fallback logic in auth.py
  • Add a startup check (e.g., using FastAPI lifespan or a module-level guard) that raises a hard error if JWT_SECRET equals the default string AND the environment is not development
  • The check should inspect an ENVIRONMENT (or APP_ENV) environment variable; default that variable to development so local dev is unaffected
  • Log a clear error message explaining which env var to set

Acceptance Criteria

  • Starting the API with the default secret and ENVIRONMENT=production exits with a non-zero code and an explanatory message
  • Starting with the default secret and ENVIRONMENT=development succeeds with a warning log
  • Starting with a custom secret in any environment succeeds without warnings
  • Existing unit tests still pass
## Context Roadmap item: P1 Security hardening `auth.py` ships a fallback `sparc-secret-key-change-in-production` value that is used if the `JWT_SECRET` environment variable is unset. If this secret reaches a production deployment, all tokens are trivially forgeable. ## Work Required - Read the current `JWT_SECRET` fallback logic in `auth.py` - Add a startup check (e.g., using FastAPI lifespan or a module-level guard) that raises a hard error if `JWT_SECRET` equals the default string AND the environment is not `development` - The check should inspect an `ENVIRONMENT` (or `APP_ENV`) environment variable; default that variable to `development` so local dev is unaffected - Log a clear error message explaining which env var to set ## Acceptance Criteria - Starting the API with the default secret and `ENVIRONMENT=production` exits with a non-zero code and an explanatory message - Starting with the default secret and `ENVIRONMENT=development` succeeds with a warning log - Starting with a custom secret in any environment succeeds without warnings - Existing unit tests still pass
AI-Manager added the P1agent-readysmall labels 2026-03-27 12:22:03 +00:00
Author
Owner

This issue has already been resolved in the fork's main branch. Already implemented in PR #27 (feat(security): JWT startup guard). See SPARC/auth.py check_jwt_secret_safety().

Closing as completed.

This issue has already been resolved in the fork's main branch. Already implemented in PR #27 (feat(security): JWT startup guard). See SPARC/auth.py check_jwt_secret_safety(). 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#305