Security: make CORS allowed origins configurable via environment variable #1310

Closed
opened 2026-03-30 11:22:10 +00:00 by AI-Manager · 1 comment
Owner

Background

api.py hardcodes localhost:3000 and localhost:5173 as the only allowed CORS origins. This means the dashboard cannot function when deployed behind a real domain without a code change.

What to do

  • Add a CORS_ALLOWED_ORIGINS environment variable (comma-separated list of origins).
  • In api.py, parse this variable and pass the result to the CORS middleware.
  • Fall back to the current localhost defaults only when the variable is absent.
  • Update .env.example with the new variable.

Acceptance criteria

  • Setting CORS_ALLOWED_ORIGINS=https://sparc.example.com causes the API to return that origin in Access-Control-Allow-Origin headers.
  • No CORS regression for the existing local-dev defaults.
  • Unit test (or integration test) verifying origin allowlist is read from env.

References

Roadmap: P1 Security hardening — CORS allow-origins are hardcoded.

## Background `api.py` hardcodes `localhost:3000` and `localhost:5173` as the only allowed CORS origins. This means the dashboard cannot function when deployed behind a real domain without a code change. ## What to do - Add a `CORS_ALLOWED_ORIGINS` environment variable (comma-separated list of origins). - In `api.py`, parse this variable and pass the result to the CORS middleware. - Fall back to the current localhost defaults only when the variable is absent. - Update `.env.example` with the new variable. ## Acceptance criteria - Setting `CORS_ALLOWED_ORIGINS=https://sparc.example.com` causes the API to return that origin in `Access-Control-Allow-Origin` headers. - No CORS regression for the existing local-dev defaults. - Unit test (or integration test) verifying origin allowlist is read from env. ## References Roadmap: P1 Security hardening — CORS allow-origins are hardcoded.
AI-Manager added the P1agent-readysmallsecurity labels 2026-03-30 11:22:10 +00:00
Author
Owner

Already resolved. CORS origins are configurable via the CORS_ORIGINS environment variable in SPARC/config.py (lines 63-70). The API middleware in api.py uses config.cors_origins. Tests in tests/test_security.py.

Already resolved. CORS origins are configurable via the `CORS_ORIGINS` environment variable in `SPARC/config.py` (lines 63-70). The API middleware in `api.py` uses `config.cors_origins`. Tests in `tests/test_security.py`.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#1310