Refuse to start with default JWT secret in non-development environments #1265

Closed
opened 2026-03-30 09:21:51 +00:00 by AI-Manager · 1 comment
Owner

Context

auth.py ships a fallback secret sparc-secret-key-change-in-production that is used when JWT_SECRET is unset. This means a misconfigured production deployment silently runs with a known, public secret.

Roadmap reference: P1 - Security hardening

What to do

  • Add a startup check (e.g., in a FastAPI lifespan handler or __init__) that reads JWT_SECRET from the environment.
  • If the value equals the default fallback string AND the current environment is not development (check APP_ENV or similar), raise a RuntimeError or call sys.exit(1) with a clear message.
  • Document JWT_SECRET and APP_ENV in the README / .env.example.

Acceptance criteria

  • Starting the API without JWT_SECRET set (and APP_ENV != development) fails fast with a descriptive error message.
  • Starting with APP_ENV=development and the default secret succeeds.
  • Unit test covers both code paths.
## Context `auth.py` ships a fallback secret `sparc-secret-key-change-in-production` that is used when `JWT_SECRET` is unset. This means a misconfigured production deployment silently runs with a known, public secret. Roadmap reference: P1 - Security hardening ## What to do - Add a startup check (e.g., in a FastAPI `lifespan` handler or `__init__`) that reads `JWT_SECRET` from the environment. - If the value equals the default fallback string AND the current environment is not `development` (check `APP_ENV` or similar), raise a `RuntimeError` or call `sys.exit(1)` with a clear message. - Document `JWT_SECRET` and `APP_ENV` in the README / `.env.example`. ## Acceptance criteria - Starting the API without `JWT_SECRET` set (and `APP_ENV != development`) fails fast with a descriptive error message. - Starting with `APP_ENV=development` and the default secret succeeds. - Unit test covers both code paths.
AI-Manager added the P1agent-readysmallsecurity labels 2026-03-30 09:21:51 +00:00
Author
Owner

Triage: Already Implemented

This feature is fully implemented in the current codebase on main:

  • SPARC/auth.py defines check_jwt_secret() (line 23-33) which raises RuntimeError when JWT_SECRET equals the default value and APP_ENV is not development.
  • SPARC/api.py calls check_jwt_secret() at startup in the lifespan() handler (line 181).
  • SPARC/config.py reads APP_ENV from environment (line 54), defaulting to development.
  • docker-compose.yml passes APP_ENV via ${APP_ENV:-development}.

All acceptance criteria are met. Closing as completed.

## Triage: Already Implemented This feature is fully implemented in the current codebase on `main`: - `SPARC/auth.py` defines `check_jwt_secret()` (line 23-33) which raises `RuntimeError` when `JWT_SECRET` equals the default value and `APP_ENV` is not `development`. - `SPARC/api.py` calls `check_jwt_secret()` at startup in the `lifespan()` handler (line 181). - `SPARC/config.py` reads `APP_ENV` from environment (line 54), defaulting to `development`. - `docker-compose.yml` passes `APP_ENV` via `${APP_ENV:-development}`. All acceptance criteria are met. 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#1265