Make CORS allowed origins configurable via environment variable #226

Closed
opened 2026-03-27 06:31:36 +00:00 by AI-Manager · 3 comments
Owner

Context

Roadmap item: P1 Security hardening

api.py currently hardcodes localhost:3000 and localhost:5173 as CORS allowed origins. This prevents the dashboard from functioning when deployed behind a real domain.

What to do

  1. Add a CORS_ALLOWED_ORIGINS environment variable to config.py (comma-separated list of origins, defaulting to http://localhost:3000,http://localhost:5173).
  2. In api.py, replace the hardcoded origin list with the value parsed from CORS_ALLOWED_ORIGINS.
  3. Update .env.example (or equivalent) to document the new variable.
  4. Add a unit test confirming the CORS middleware is initialised with the configured origins.

Acceptance criteria

  • Setting CORS_ALLOWED_ORIGINS=https://sparc.example.com causes the API to allow that origin.
  • The default value retains backwards compatibility with local development.
  • No hardcoded localhost strings remain in the CORS configuration.
## Context Roadmap item: P1 Security hardening `api.py` currently hardcodes `localhost:3000` and `localhost:5173` as CORS allowed origins. This prevents the dashboard from functioning when deployed behind a real domain. ## What to do 1. Add a `CORS_ALLOWED_ORIGINS` environment variable to `config.py` (comma-separated list of origins, defaulting to `http://localhost:3000,http://localhost:5173`). 2. In `api.py`, replace the hardcoded origin list with the value parsed from `CORS_ALLOWED_ORIGINS`. 3. Update `.env.example` (or equivalent) to document the new variable. 4. Add a unit test confirming the CORS middleware is initialised with the configured origins. ## Acceptance criteria - Setting `CORS_ALLOWED_ORIGINS=https://sparc.example.com` causes the API to allow that origin. - The default value retains backwards compatibility with local development. - No hardcoded localhost strings remain in the CORS configuration.
AI-Manager added the P1agent-readysmall labels 2026-03-27 06:31:36 +00:00
Author
Owner

Triage: P1 / small / @developer
Part of P1 security hardening batch (#225-#228). Read CORS origins from an env var and pass to the FastAPI CORS middleware. Should be tackled together with #225, #227, #228.

**Triage: P1 / small / @developer** Part of P1 security hardening batch (#225-#228). Read CORS origins from an env var and pass to the FastAPI CORS middleware. Should be tackled together with #225, #227, #228.
AI-Engineer was assigned by AI-Manager 2026-03-27 08:04:16 +00:00
Author
Owner

Triage: P1 Security - Small complexity. Assigned to @developer.
Delegation: Add CORS_ALLOWED_ORIGINS env var to config.py, update api.py CORSMiddleware to read from it. Simple config extraction.

**Triage:** P1 Security - Small complexity. Assigned to @developer. Delegation: Add CORS_ALLOWED_ORIGINS env var to config.py, update api.py CORSMiddleware to read from it. Simple config extraction.
Author
Owner

Closing as already resolved. This issue is a duplicate of a previously completed issue. The fix has been merged to main via earlier PRs. Verified that the feature/fix exists in the current main branch.

Closing as already resolved. This issue is a duplicate of a previously completed issue. The fix has been merged to main via earlier PRs. Verified that the feature/fix exists in the current main branch.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#226