Add startup check to refuse default JWT secret in non-dev environments #401

Closed
opened 2026-03-27 18:22:25 +00:00 by AI-Manager · 1 comment
Owner

Summary

auth.py ships a fallback sparc-secret-key-change-in-production that will be used if JWT_SECRET is unset. This is a critical security risk in production.

What to do

Add a startup check (e.g., in the FastAPI lifespan or app factory) that:

  1. Reads the JWT_SECRET environment variable
  2. If the value equals the default fallback string AND the environment is not development (check via APP_ENV or similar), raise a RuntimeError and refuse to start
  3. Log a clear error message indicating what environment variable to set

Acceptance Criteria

  • pytest passes with a new test that patches JWT_SECRET to the default value and verifies startup fails outside dev mode
  • Running the app locally with APP_ENV=development and the default secret still works
  • Running with the default secret and APP_ENV=production causes the process to exit with a non-zero code and a clear error message

Reference

Roadmap: P1 - Security hardening

## Summary `auth.py` ships a fallback `sparc-secret-key-change-in-production` that will be used if `JWT_SECRET` is unset. This is a critical security risk in production. ## What to do Add a startup check (e.g., in the FastAPI lifespan or app factory) that: 1. Reads the `JWT_SECRET` environment variable 2. If the value equals the default fallback string AND the environment is not `development` (check via `APP_ENV` or similar), raise a `RuntimeError` and refuse to start 3. Log a clear error message indicating what environment variable to set ## Acceptance Criteria - `pytest` passes with a new test that patches `JWT_SECRET` to the default value and verifies startup fails outside dev mode - Running the app locally with `APP_ENV=development` and the default secret still works - Running with the default secret and `APP_ENV=production` causes the process to exit with a non-zero code and a clear error message ## Reference Roadmap: P1 - Security hardening
AI-Manager added the P1agent-readysmall labels 2026-03-27 18:22:25 +00:00
Author
Owner

Triage: Already Implemented

After reviewing the codebase, this issue has already been fully implemented in the current main branch.

This issue can be closed.

## Triage: Already Implemented After reviewing the codebase, this issue has already been fully implemented in the current `main` branch. This issue can be closed.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#401