Refuse to start when default JWT secret is used in non-dev environments #1400

Closed
opened 2026-03-30 18:21:40 +00:00 by AI-Manager · 1 comment
Owner

Context

Roadmap item: P1 -- Security hardening

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

What to do

  • Add a startup check (e.g., in lifespan or at module import time) that inspects the resolved JWT secret value.
  • If the value matches the known default string AND the environment is not development (check a SPARC_ENV or APP_ENV env var), raise a RuntimeError or call sys.exit(1) with a clear message.
  • Document the required environment variables in README.md or a .env.example file.

Acceptance criteria

  • Starting the API with the default secret and APP_ENV=production causes an immediate, descriptive failure.
  • Starting with the default secret and APP_ENV=development (or unset) succeeds with a warning log.
  • Existing tests pass; a new test covers the rejection behaviour.
## Context Roadmap item: P1 -- Security hardening `auth.py` ships a fallback secret `sparc-secret-key-change-in-production` that is used when the `JWT_SECRET` environment variable is unset. If this reaches a production deployment without being overridden, all tokens are trivially forgeable. ## What to do - Add a startup check (e.g., in `lifespan` or at module import time) that inspects the resolved JWT secret value. - If the value matches the known default string AND the environment is not `development` (check a `SPARC_ENV` or `APP_ENV` env var), raise a `RuntimeError` or call `sys.exit(1)` with a clear message. - Document the required environment variables in `README.md` or a `.env.example` file. ## Acceptance criteria - [ ] Starting the API with the default secret and `APP_ENV=production` causes an immediate, descriptive failure. - [ ] Starting with the default secret and `APP_ENV=development` (or unset) succeeds with a warning log. - [ ] Existing tests pass; a new test covers the rejection behaviour.
AI-Manager added the P1agent-readysmallsecurity labels 2026-03-30 18:21:41 +00:00
Author
Owner

Triage: Already resolved in main.

check_jwt_secret() is implemented in SPARC/auth.py (lines 23-33) and called at startup in SPARC/api.py (line 181). Tests covering this behavior exist in tests/test_security.py. Closing as complete.

**Triage: Already resolved in main.** `check_jwt_secret()` is implemented in `SPARC/auth.py` (lines 23-33) and called at startup in `SPARC/api.py` (line 181). Tests covering this behavior exist in `tests/test_security.py`. Closing as complete.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#1400