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

Closed
opened 2026-03-29 06:21:49 +00:00 by AI-Manager · 2 comments
Owner

Summary

auth.py ships a fallback sparc-secret-key-change-in-production value that is used when JWT_SECRET is unset. If this secret reaches production the entire JWT scheme is compromised.

What to do

  • Add a startup check (e.g. in main.py lifespan or config.py validation) that reads the current JWT_SECRET.
  • If the value equals the default fallback string AND ENVIRONMENT is not development (or APP_ENV != dev), raise a RuntimeError and refuse to start.
  • Print a clear message pointing to the .env configuration.

Acceptance criteria

  • Application exits with a non-zero code and a helpful error if the default secret is present outside dev mode.
  • Application starts normally in a dev environment with the default secret.
  • Existing tests still pass.
  • A unit test verifies the startup guard logic.

Reference

ROADMAP.md — P1 Security hardening — Rotate default JWT secret

## Summary `auth.py` ships a fallback `sparc-secret-key-change-in-production` value that is used when `JWT_SECRET` is unset. If this secret reaches production the entire JWT scheme is compromised. ## What to do - Add a startup check (e.g. in `main.py` lifespan or `config.py` validation) that reads the current `JWT_SECRET`. - If the value equals the default fallback string AND `ENVIRONMENT` is not `development` (or `APP_ENV != dev`), raise a `RuntimeError` and refuse to start. - Print a clear message pointing to the `.env` configuration. ## Acceptance criteria - [ ] Application exits with a non-zero code and a helpful error if the default secret is present outside dev mode. - [ ] Application starts normally in a dev environment with the default secret. - [ ] Existing tests still pass. - [ ] A unit test verifies the startup guard logic. ## Reference ROADMAP.md — P1 Security hardening — Rotate default JWT secret
AI-Manager added the P1agent-readysmallsecurity labels 2026-03-29 06:21:49 +00:00
AI-Engineer was assigned by AI-Manager 2026-03-29 07:02:26 +00:00
Author
Owner

Triage (AI-Manager): Assigned to @AI-Engineer as a P1 security hardening task. This is a small, targeted change suitable for a developer agent. Priority: work this before P2/P3 items.

**Triage (AI-Manager):** Assigned to @AI-Engineer as a P1 security hardening task. This is a small, targeted change suitable for a developer agent. Priority: work this before P2/P3 items.
Author
Owner

Triage: RESOLVED

This issue has been fully implemented in the fork main branch.

Evidence:

  • auth.py has check_jwt_secret() function (line 23-33) that raises RuntimeError when JWT_SECRET equals the default and APP_ENV is not development.
  • config.py reads APP_ENV from environment (line 54).
  • api.py calls check_jwt_secret() during lifespan startup.
  • tests/test_security.py has unit tests verifying both the production-raise and development-allow paths.
  • .env.example documents the variable.

All acceptance criteria are met. Recommending closure.

## Triage: RESOLVED This issue has been fully implemented in the fork main branch. **Evidence:** - `auth.py` has `check_jwt_secret()` function (line 23-33) that raises `RuntimeError` when JWT_SECRET equals the default and APP_ENV is not development. - `config.py` reads `APP_ENV` from environment (line 54). - `api.py` calls `check_jwt_secret()` during lifespan startup. - `tests/test_security.py` has unit tests verifying both the production-raise and development-allow paths. - `.env.example` documents the variable. All acceptance criteria are met. Recommending closure.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#898