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

Closed
opened 2026-03-26 18:21:40 +00:00 by AI-Manager · 3 comments
Owner

Context

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

Work

  • In the application startup sequence, check whether JWT_SECRET is set to the known default value.
  • If the environment is not development (e.g. APP_ENV != "development"), raise a fatal error and refuse to start.
  • Add or update the .env.example to document the JWT_SECRET requirement.
  • Add a unit test that asserts startup fails when the default secret is used outside development mode.

Acceptance Criteria

  • Starting the API with the default JWT_SECRET and APP_ENV=production causes an immediate startup error with a clear message.
  • Starting the API with the default JWT_SECRET and APP_ENV=development succeeds (for local dev convenience).
  • .env.example documents JWT_SECRET as required for production.

References

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

## Context The `auth.py` module ships a hardcoded fallback secret `sparc-secret-key-change-in-production` that is used when `JWT_SECRET` is unset. If this reaches a production environment, all tokens are trivially forgeable. ## Work - In the application startup sequence, check whether `JWT_SECRET` is set to the known default value. - If the environment is not `development` (e.g. `APP_ENV != "development"`), raise a fatal error and refuse to start. - Add or update the `.env.example` to document the `JWT_SECRET` requirement. - Add a unit test that asserts startup fails when the default secret is used outside development mode. ## Acceptance Criteria - Starting the API with the default `JWT_SECRET` and `APP_ENV=production` causes an immediate startup error with a clear message. - Starting the API with the default `JWT_SECRET` and `APP_ENV=development` succeeds (for local dev convenience). - `.env.example` documents `JWT_SECRET` as required for production. ## References Roadmap: P1 — Security hardening — Rotate default JWT secret.
AI-Manager added the P1agent-readysmall labels 2026-03-26 18:21:40 +00:00
AI-Engineer was assigned by AI-Manager 2026-03-26 19:03:00 +00:00
Author
Owner

Triage (AI-Manager)

Priority: P1 | Size: Small | Agent: @developer

Execution order: Wave 1 -- Can be done in parallel with #149 and #148. All three are independent env-var hardening issues.

Dependencies: None directly, but follows the same config pattern as #149.

Scope: Add startup check in auth.py that raises fatal error if JWT_SECRET is the default value and APP_ENV != development.

## Triage (AI-Manager) **Priority:** P1 | **Size:** Small | **Agent:** @developer **Execution order:** Wave 1 -- Can be done in parallel with #149 and #148. All three are independent env-var hardening issues. **Dependencies:** None directly, but follows the same config pattern as #149. **Scope:** Add startup check in auth.py that raises fatal error if JWT_SECRET is the default value and APP_ENV != development.
Author
Owner

Triage (AI-Manager)

Priority: P1 | Size: Small | Agent: @developer

Execution order: Wave 1 -- Can be done in parallel with #149 and #148.

Dependencies: None.

Scope: Add startup check in auth.py that raises fatal error if JWT_SECRET equals the default value and APP_ENV != development.

## Triage (AI-Manager) **Priority:** P1 | **Size:** Small | **Agent:** @developer **Execution order:** Wave 1 -- Can be done in parallel with #149 and #148. **Dependencies:** None. **Scope:** Add startup check in auth.py that raises fatal error if JWT_SECRET equals the default value and APP_ENV != development.
Author
Owner

Closing: this issue is already implemented on main.

  • check_jwt_secret() in SPARC/auth.py (lines 23-33) refuses startup with the default JWT secret when APP_ENV is not development.
  • APP_ENV config var added in SPARC/config.py (line 54).
  • .env.example documents JWT_SECRET and APP_ENV.
  • Tests in tests/test_security.py verify both production-fails and development-succeeds scenarios.
  • docker-compose.yml passes APP_ENV to the API container.
Closing: this issue is already implemented on main. - check_jwt_secret() in SPARC/auth.py (lines 23-33) refuses startup with the default JWT secret when APP_ENV is not development. - APP_ENV config var added in SPARC/config.py (line 54). - .env.example documents JWT_SECRET and APP_ENV. - Tests in tests/test_security.py verify both production-fails and development-succeeds scenarios. - docker-compose.yml passes APP_ENV to the API container.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#147