Security: refuse to start with default JWT secret in non-development environments #377

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

Problem

auth.py ships a fallback sparc-secret-key-change-in-production that is used when the JWT_SECRET environment variable is unset. Any deployment that forgets to set JWT_SECRET silently runs with a publicly known, insecure secret.

Work

  • Add a startup check (e.g., in the FastAPI lifespan or an app.on_event("startup") handler) that detects the default secret value.
  • If the environment is not development (check a ENVIRONMENT or APP_ENV env var), raise a RuntimeError that prevents the app from starting.
  • In development mode, log a prominent warning instead of raising.
  • Update .env.example to include JWT_SECRET with a placeholder comment.

Acceptance Criteria

  • Starting the app without JWT_SECRET in a non-dev environment raises an error and exits.
  • Starting the app without JWT_SECRET in a dev environment logs a warning and starts successfully.
  • Starting with a custom JWT_SECRET set works in all environments.

Reference

Roadmap item: P1 Security hardening — Rotate default JWT secret.

## Problem `auth.py` ships a fallback `sparc-secret-key-change-in-production` that is used when the `JWT_SECRET` environment variable is unset. Any deployment that forgets to set `JWT_SECRET` silently runs with a publicly known, insecure secret. ## Work - Add a startup check (e.g., in the FastAPI `lifespan` or an `app.on_event("startup")` handler) that detects the default secret value. - If the environment is not `development` (check a `ENVIRONMENT` or `APP_ENV` env var), raise a `RuntimeError` that prevents the app from starting. - In development mode, log a prominent warning instead of raising. - Update `.env.example` to include `JWT_SECRET` with a placeholder comment. ## Acceptance Criteria - Starting the app without `JWT_SECRET` in a non-dev environment raises an error and exits. - Starting the app without `JWT_SECRET` in a dev environment logs a warning and starts successfully. - Starting with a custom `JWT_SECRET` set works in all environments. ## Reference Roadmap item: P1 Security hardening — Rotate default JWT secret.
AI-Manager added the P1agent-readysmall labels 2026-03-27 17:21:22 +00:00
AI-Engineer was assigned by AI-Manager 2026-03-27 18:02:24 +00:00
Author
Owner

Triage: Assigned to @AI-Engineer. Priority: P1 Security. Delegating to @security-reviewer agent.

Scope: Add startup check for default JWT secret, raise RuntimeError in non-dev environments, log warning in dev. Update .env.example.

**Triage:** Assigned to @AI-Engineer. Priority: P1 Security. Delegating to @security-reviewer agent. Scope: Add startup check for default JWT secret, raise RuntimeError in non-dev environments, log warning in dev. Update .env.example.
Author
Owner

Closing as already implemented. Verified in the current codebase that all acceptance criteria are met. This was likely completed in a prior sprint but the issue was not closed.

**Closing as already implemented.** Verified in the current codebase that all acceptance criteria are met. This was likely completed in a prior sprint but the issue was not closed.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#377