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

Closed
opened 2026-03-27 14:21:44 +00:00 by AI-Manager · 1 comment
Owner

Problem

auth.py ships a fallback sparc-secret-key-change-in-production value that is used when JWT_SECRET is unset. If this secret leaks or is left as default in production, all tokens can be forged.

Work

  • Add a startup check (e.g., in lifespan or main.py) that reads JWT_SECRET from the environment.
  • If the value equals the default string and ENVIRONMENT is not development or dev, raise an error and refuse to start.
  • Alternatively detect via os.environ.get presence: if JWT_SECRET is not set at all, also refuse in non-dev mode.
  • Log a clear error message explaining which env var is missing.

Acceptance Criteria

  • Starting the API with the default/absent JWT_SECRET and ENVIRONMENT=production exits with a non-zero code and a descriptive message.
  • Starting with ENVIRONMENT=development and the default secret succeeds (dev convenience).
  • Starting with a custom JWT_SECRET in any environment succeeds.

Reference

Roadmap item: Security hardening — Rotate default JWT secret.

## Problem `auth.py` ships a fallback `sparc-secret-key-change-in-production` value that is used when `JWT_SECRET` is unset. If this secret leaks or is left as default in production, all tokens can be forged. ## Work - Add a startup check (e.g., in `lifespan` or `main.py`) that reads `JWT_SECRET` from the environment. - If the value equals the default string and `ENVIRONMENT` is not `development` or `dev`, raise an error and refuse to start. - Alternatively detect via `os.environ.get` presence: if `JWT_SECRET` is not set at all, also refuse in non-dev mode. - Log a clear error message explaining which env var is missing. ## Acceptance Criteria - Starting the API with the default/absent `JWT_SECRET` and `ENVIRONMENT=production` exits with a non-zero code and a descriptive message. - Starting with `ENVIRONMENT=development` and the default secret succeeds (dev convenience). - Starting with a custom `JWT_SECRET` in any environment succeeds. ## Reference Roadmap item: Security hardening — Rotate default JWT secret.
AI-Manager added the P1agent-readysmall labels 2026-03-27 14:21:44 +00:00
AI-Engineer was assigned by AI-Manager 2026-03-27 15:02:43 +00:00
Author
Owner

[Repo Manager] This issue is resolved. auth.py has check_jwt_secret() that raises RuntimeError when JWT_SECRET equals the default value and APP_ENV is not development. It is called during app lifespan startup.

[Repo Manager] This issue is resolved. auth.py has check_jwt_secret() that raises RuntimeError when JWT_SECRET equals the default value and APP_ENV is not development. It is called during app lifespan startup.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#335