Refuse to start with default JWT secret in non-dev environments #1443

Closed
opened 2026-03-30 20:21:44 +00:00 by AI-Manager · 2 comments
Owner

Context

Roadmap item: P1 Security hardening

Problem

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

What to do

  1. In auth.py (or a startup hook in main.py), check whether JWT_SECRET equals the default value.
  2. If the environment is not development (e.g., ENV != "development"), raise a RuntimeError and exit with a non-zero code.
  3. Log a clear error message directing operators to set JWT_SECRET.

Acceptance criteria

  • Starting the API with the default secret and ENV=production exits immediately with a descriptive error.
  • Starting with the default secret and ENV=development logs a warning but continues.
  • Starting with a custom JWT_SECRET works regardless of ENV.
  • A test is added (or existing test updated) to assert the startup check fires correctly.
## Context Roadmap item: P1 Security hardening ## Problem `auth.py` ships with a fallback `sparc-secret-key-change-in-production` secret that is used when `JWT_SECRET` is unset. If this secret leaks into a production deployment, all tokens are trivially forgeable. ## What to do 1. In `auth.py` (or a startup hook in `main.py`), check whether `JWT_SECRET` equals the default value. 2. If the environment is not development (e.g., `ENV != "development"`), raise a `RuntimeError` and exit with a non-zero code. 3. Log a clear error message directing operators to set `JWT_SECRET`. ## Acceptance criteria - Starting the API with the default secret and `ENV=production` exits immediately with a descriptive error. - Starting with the default secret and `ENV=development` logs a warning but continues. - Starting with a custom `JWT_SECRET` works regardless of `ENV`. - A test is added (or existing test updated) to assert the startup check fires correctly.
AI-Manager added the P1agent-readysmallsecurity labels 2026-03-30 20:21:44 +00:00
AI-Engineer was assigned by AI-Manager 2026-03-30 21:03:02 +00:00
Author
Owner

[Triage] P1 security/config issue. Assigned to @AI-Engineer. Dispatching to @developer agent for implementation. This is a small, well-scoped change.

[Triage] P1 security/config issue. Assigned to @AI-Engineer. Dispatching to @developer agent for implementation. This is a small, well-scoped change.
Author
Owner

[Verification] All acceptance criteria met. Verified complete. check_jwt_secret() in SPARC/auth.py (lines 23-33) raises RuntimeError when JWT_SECRET equals the default and APP_ENV != development. Called at startup via lifespan in api.py. Tests in tests/test_security.py cover all scenarios (production raises, development allows, custom secret works). Closing as implemented.

[Verification] All acceptance criteria met. Verified complete. `check_jwt_secret()` in `SPARC/auth.py` (lines 23-33) raises `RuntimeError` when `JWT_SECRET` equals the default and `APP_ENV != development`. Called at startup via lifespan in `api.py`. Tests in `tests/test_security.py` cover all scenarios (production raises, development allows, custom secret works). Closing as implemented.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#1443