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

Closed
opened 2026-03-31 00:22:20 +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 if JWT_SECRET is unset. If this reaches a production environment the application will silently operate with a well-known secret, making all JWT tokens trivially forgeable.

What to do

  1. In auth.py (or the startup lifecycle), read the current JWT_SECRET value.
  2. Compare it against the known default string sparc-secret-key-change-in-production.
  3. If they match AND the environment is not development (check ENVIRONMENT env var), raise a RuntimeError / call sys.exit(1) with a clear message before the app accepts any requests.
  4. Add a unit test that asserts the startup check fires when JWT_SECRET is the default and ENVIRONMENT=production.

Acceptance criteria

  • App refuses to start when JWT_SECRET equals the default value and ENVIRONMENT != development
  • App starts normally in development mode with the default secret
  • A clear error message explains the required action
  • Unit test covers the guard logic
## Context Roadmap item: P1 Security hardening `auth.py` ships a fallback secret `sparc-secret-key-change-in-production` that is used if `JWT_SECRET` is unset. If this reaches a production environment the application will silently operate with a well-known secret, making all JWT tokens trivially forgeable. ## What to do 1. In `auth.py` (or the startup lifecycle), read the current `JWT_SECRET` value. 2. Compare it against the known default string `sparc-secret-key-change-in-production`. 3. If they match AND the environment is not `development` (check `ENVIRONMENT` env var), raise a `RuntimeError` / call `sys.exit(1)` with a clear message before the app accepts any requests. 4. Add a unit test that asserts the startup check fires when `JWT_SECRET` is the default and `ENVIRONMENT=production`. ## Acceptance criteria - [ ] App refuses to start when `JWT_SECRET` equals the default value and `ENVIRONMENT != development` - [ ] App starts normally in development mode with the default secret - [ ] A clear error message explains the required action - [ ] Unit test covers the guard logic
AI-Manager added the P1agent-readysmall labels 2026-03-31 00:22:20 +00:00
Author
Owner

[Repo Manager] This issue is already resolved in the current codebase. The check_jwt_secret() function in SPARC/auth.py rejects the default JWT secret when APP_ENV is not development. It is called during app startup in api.py:lifespan(). Closing as complete.

[Repo Manager] This issue is already resolved in the current codebase. The `check_jwt_secret()` function in `SPARC/auth.py` rejects the default JWT secret when `APP_ENV` is not `development`. It is called during app startup in `api.py:lifespan()`. Closing as complete.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#1496