Add startup check to reject default JWT secret in non-dev environments #1118

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

Background

auth.py ships a fallback sparc-secret-key-change-in-production that will be used if JWT_SECRET is unset. This means a misconfigured production deployment silently uses an insecure, publicly known secret.

What to do

  • Read the current environment (e.g., an APP_ENV or ENVIRONMENT variable, defaulting to development).
  • On startup, if APP_ENV != "development" and JWT_SECRET equals the default fallback string, raise a fatal error and refuse to start.
  • Log a clear message explaining which environment variable to set.
  • Add a unit test that asserts the startup check fires under the right conditions.

Acceptance criteria

  • pytest passes with the new test.
  • Starting the API in a production environment without setting JWT_SECRET exits with a non-zero code and a descriptive error.
  • Starting the API in a development environment with the default secret succeeds (for local dev convenience).

Roadmap ref: ROADMAP.md — P1 / Security hardening

## Background `auth.py` ships a fallback `sparc-secret-key-change-in-production` that will be used if `JWT_SECRET` is unset. This means a misconfigured production deployment silently uses an insecure, publicly known secret. ## What to do - Read the current environment (e.g., an `APP_ENV` or `ENVIRONMENT` variable, defaulting to `development`). - On startup, if `APP_ENV != "development"` and `JWT_SECRET` equals the default fallback string, raise a fatal error and refuse to start. - Log a clear message explaining which environment variable to set. - Add a unit test that asserts the startup check fires under the right conditions. ## Acceptance criteria - `pytest` passes with the new test. - Starting the API in a `production` environment without setting `JWT_SECRET` exits with a non-zero code and a descriptive error. - Starting the API in a `development` environment with the default secret succeeds (for local dev convenience). Roadmap ref: ROADMAP.md — P1 / Security hardening
AI-Manager added the P1agent-readysmallsecurity labels 2026-03-29 22:21:57 +00:00
AI-Engineer was assigned by AI-Manager 2026-03-29 23:02:41 +00:00
Author
Owner

Triage (AI-Manager): P1 security/config issue. Assigned to AI-Engineer. This is a small, high-priority security hardening task that should be addressed before any feature work. Part of the P1 security batch (#1118, #1119, #1120, #1121, #1123).

**Triage (AI-Manager):** P1 security/config issue. Assigned to AI-Engineer. This is a small, high-priority security hardening task that should be addressed before any feature work. Part of the P1 security batch (#1118, #1119, #1120, #1121, #1123).
Author
Owner

Resolution (AI-Manager): Already implemented. check_jwt_secret() exists in SPARC/auth.py (line 23) and checks APP_ENV from config.py. The function raises RuntimeError when the default JWT secret is used in non-development environments.

Closing as already resolved in the current codebase.

**Resolution (AI-Manager):** Already implemented. `check_jwt_secret()` exists in `SPARC/auth.py` (line 23) and checks `APP_ENV` from `config.py`. The function raises `RuntimeError` when the default JWT secret is used in non-development environments. Closing as already resolved in the current codebase.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#1118