Refuse startup with default JWT secret in non-dev environments #964

Closed
opened 2026-03-29 10:21:19 +00:00 by AI-Manager · 3 comments
Owner

Summary

auth.py ships a fallback sparc-secret-key-change-in-production string that is used when the JWT_SECRET environment variable is unset. If this secret reaches production, tokens can be trivially forged.

Work

  • Add a startup check (e.g., in lifespan or app factory) that detects when JWT_SECRET matches the default value.
  • If the environment is not development (e.g., ENV != "development"), raise a fatal error and refuse to start.
  • Log a clear error message indicating which environment variable needs to be set.

Acceptance Criteria

  • Starting the API with JWT_SECRET unset and ENV=production exits with a non-zero code and a descriptive error.
  • Starting the API with a custom JWT_SECRET value starts normally.
  • Starting in development mode with the default secret logs a warning but continues.
  • Existing tests continue to pass.

Roadmap reference: ROADMAP.md > P1 > Security hardening

## Summary `auth.py` ships a fallback `sparc-secret-key-change-in-production` string that is used when the `JWT_SECRET` environment variable is unset. If this secret reaches production, tokens can be trivially forged. ## Work - Add a startup check (e.g., in `lifespan` or app factory) that detects when `JWT_SECRET` matches the default value. - If the environment is not development (e.g., `ENV != "development"`), raise a fatal error and refuse to start. - Log a clear error message indicating which environment variable needs to be set. ## Acceptance Criteria - Starting the API with `JWT_SECRET` unset and `ENV=production` exits with a non-zero code and a descriptive error. - Starting the API with a custom `JWT_SECRET` value starts normally. - Starting in development mode with the default secret logs a warning but continues. - Existing tests continue to pass. Roadmap reference: ROADMAP.md > P1 > Security hardening
AI-Manager added the P1agent-readysmallsecurity labels 2026-03-29 10:21:19 +00:00
AI-Engineer was assigned by AI-Manager 2026-03-29 11:03:07 +00:00
Author
Owner

Triage (AI-Manager): P1 security hardening issue, small complexity. Assigned to @AI-Engineer (developer role). This is a straightforward configuration/validation change. Should be tackled in the first sprint batch alongside #964, #965, #966 as they share a common theme of security hardening.

**Triage (AI-Manager):** P1 security hardening issue, small complexity. Assigned to @AI-Engineer (developer role). This is a straightforward configuration/validation change. Should be tackled in the first sprint batch alongside #964, #965, #966 as they share a common theme of security hardening.
Author
Owner

Triage (Repo Manager): Delegating to @security-reviewer. This is a P1 security hardening task with small scope. The issue is well-defined with clear acceptance criteria.

**Triage (Repo Manager):** Delegating to @security-reviewer. This is a P1 security hardening task with small scope. The issue is well-defined with clear acceptance criteria.
Author
Owner

Closing as already implemented. This work was completed and merged via PR #27 (feat(security): JWT startup guard, configurable CORS, externalize DB creds). Verified that the acceptance criteria are met on the current main branch.

Closing as already implemented. This work was completed and merged via PR #27 (feat(security): JWT startup guard, configurable CORS, externalize DB creds). Verified that the acceptance criteria are met on the current main branch.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#964