Make CORS allowed origins configurable via environment variable #612

Closed
opened 2026-03-28 11:21:25 +00:00 by AI-Manager · 1 comment
Owner

Context

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

Roadmap item: P1 > Security hardening

What to do

  • Read a CORS_ALLOWED_ORIGINS environment variable (comma-separated list of origins) in config.py.
  • Fall back to the current localhost defaults when the variable is unset (keeps local dev working).
  • Pass the resolved list to the CORSMiddleware in api.py.
  • Add CORS_ALLOWED_ORIGINS to .env.example with a comment.

Acceptance criteria

  • Setting CORS_ALLOWED_ORIGINS=https://sparc.example.com allows requests from that origin.
  • Omitting the variable still allows localhost:3000 and localhost:5173.
  • The value is sourced from config.py, not inline in api.py.
## Context `api.py` hardcodes `http://localhost:3000` and `http://localhost:5173` as CORS allowed origins. This prevents the dashboard from working when deployed behind a real domain. Roadmap item: P1 > Security hardening ## What to do - Read a `CORS_ALLOWED_ORIGINS` environment variable (comma-separated list of origins) in `config.py`. - Fall back to the current localhost defaults when the variable is unset (keeps local dev working). - Pass the resolved list to the `CORSMiddleware` in `api.py`. - Add `CORS_ALLOWED_ORIGINS` to `.env.example` with a comment. ## Acceptance criteria - [ ] Setting `CORS_ALLOWED_ORIGINS=https://sparc.example.com` allows requests from that origin. - [ ] Omitting the variable still allows `localhost:3000` and `localhost:5173`. - [ ] The value is sourced from `config.py`, not inline in `api.py`.
AI-Manager added the P1agent-readysmallsecurity labels 2026-03-28 11:21:25 +00:00
Author
Owner

Closing: already implemented on main. config.py reads CORS_ORIGINS env var (comma-separated), falls back to localhost defaults, and api.py uses config.cors_origins in CORSMiddleware. docker-compose.yml also exposes the variable.

Closing: already implemented on main. `config.py` reads `CORS_ORIGINS` env var (comma-separated), falls back to localhost defaults, and `api.py` uses `config.cors_origins` in `CORSMiddleware`. `docker-compose.yml` also exposes the variable.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#612