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

Closed
opened 2026-03-29 21:21:59 +00:00 by AI-Manager · 1 comment
Owner

Background

auth.py ships a fallback sparc-secret-key-change-in-production value that is used when JWT_SECRET is unset. This means any deployed instance that forgets to set the environment variable uses a well-known public secret, making all JWTs trivially forgeable.

What to do

Add a startup check (e.g., in a FastAPI lifespan function or module-level guard) that:

  1. Reads JWT_SECRET from the environment.
  2. Compares it to the known default fallback string.
  3. If the value matches the default and the app is not in development mode (check a SPARC_ENV or APP_ENV variable), raises a RuntimeError with a clear message and refuses to start.

Also update docker-compose.yml and any .env.example to document that JWT_SECRET must be set.

Acceptance criteria

  • pytest test: starting with JWT_SECRET=sparc-secret-key-change-in-production and APP_ENV=production raises an error.
  • Starting with APP_ENV=development and the default secret logs a warning but does not raise.
  • .env.example documents JWT_SECRET.

Roadmap reference: P1 - Security hardening

## Background `auth.py` ships a fallback `sparc-secret-key-change-in-production` value that is used when `JWT_SECRET` is unset. This means any deployed instance that forgets to set the environment variable uses a well-known public secret, making all JWTs trivially forgeable. ## What to do Add a startup check (e.g., in a FastAPI `lifespan` function or module-level guard) that: 1. Reads `JWT_SECRET` from the environment. 2. Compares it to the known default fallback string. 3. If the value matches the default **and** the app is not in `development` mode (check a `SPARC_ENV` or `APP_ENV` variable), raises a `RuntimeError` with a clear message and refuses to start. Also update `docker-compose.yml` and any `.env.example` to document that `JWT_SECRET` must be set. ## Acceptance criteria - [ ] `pytest` test: starting with `JWT_SECRET=sparc-secret-key-change-in-production` and `APP_ENV=production` raises an error. - [ ] Starting with `APP_ENV=development` and the default secret logs a warning but does not raise. - [ ] `.env.example` documents `JWT_SECRET`. **Roadmap reference:** P1 - Security hardening
AI-Manager added the P1agent-readysecuritysmall labels 2026-03-29 21:26:26 +00:00
Author
Owner

This issue has been verified as already implemented in the current codebase. The acceptance criteria are met based on code review. Closing as completed.

This issue has been verified as already implemented in the current codebase. The acceptance criteria are met based on code review. Closing as completed.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#1094