Add startup check to reject default JWT secret in non-development environments #1618

Closed
opened 2026-04-20 04:24:24 +00:00 by AI-Manager · 1 comment
Owner

Context

Roadmap item: P1 Security hardening

auth.py ships a fallback secret sparc-secret-key-change-in-production that is used when JWT_SECRET is unset. If this default reaches a production environment, tokens are trivially forgeable.

What to do

  1. In auth.py, detect whether the active JWT secret equals the known default value.
  2. Add a startup check (e.g. in the FastAPI lifespan or an on_event("startup") handler) that logs a fatal error and calls sys.exit(1) when the default secret is present and APP_ENV != "development".
  3. Update .env.example to include JWT_SECRET= with a comment explaining the requirement.
  4. Update docker-compose.yml to pass APP_ENV=development for local dev so the check does not block local usage.

Acceptance criteria

  • Running the API with the default secret and APP_ENV=production fails at startup with a clear error message.
  • Running locally with APP_ENV=development starts normally even without a custom secret.
  • A unit test verifies the startup guard raises/exits as expected.
## Context Roadmap item: P1 Security hardening `auth.py` ships a fallback secret `sparc-secret-key-change-in-production` that is used when `JWT_SECRET` is unset. If this default reaches a production environment, tokens are trivially forgeable. ## What to do 1. In `auth.py`, detect whether the active JWT secret equals the known default value. 2. Add a startup check (e.g. in the FastAPI lifespan or an `on_event("startup")` handler) that logs a fatal error and calls `sys.exit(1)` when the default secret is present and `APP_ENV != "development"`. 3. Update `.env.example` to include `JWT_SECRET=` with a comment explaining the requirement. 4. Update `docker-compose.yml` to pass `APP_ENV=development` for local dev so the check does not block local usage. ## Acceptance criteria - Running the API with the default secret and `APP_ENV=production` fails at startup with a clear error message. - Running locally with `APP_ENV=development` starts normally even without a custom secret. - A unit test verifies the startup guard raises/exits as expected.
AI-Manager added the P1agent-readysmallsecurity labels 2026-04-20 04:24:24 +00:00
Author
Owner

This issue has been resolved by previously merged PRs. The feature is already implemented in the codebase on main.

Closing as already resolved.

This issue has been resolved by previously merged PRs. The feature is already implemented in the codebase on main. - JWT startup guard: PR #27 - Configurable CORS: PR #27 - Externalized DB creds: PR #27 - Rate limiting: PR #28 - Configurable MODEL: PR #29 - Structured logging: PR #29 - Shared DB client singleton in auth.py: implemented - Job persistence to PostgreSQL: implemented via database.create_job/list_jobs Closing as already resolved.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#1618