Make CORS allowed-origins configurable via environment variable #1376

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

Background

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

api.py hardcodes localhost:3000 and localhost:5173 as CORS origins. When SPARC is deployed behind a real domain the frontend cannot reach the API, or the origins must be widened to * (insecure).

Task

  1. Add a CORS_ORIGINS environment variable to config.py that accepts a comma-separated list of origins (e.g. https://sparc.example.com,https://sparc-staging.example.com).
  2. Fall back to ["http://localhost:3000", "http://localhost:5173"] when the variable is unset (preserves local-dev behaviour).
  3. Update the CORSMiddleware setup in api.py to read from the config value.
  4. Update docker-compose.yml with a commented-out CORS_ORIGINS example.

Acceptance Criteria

  • Setting CORS_ORIGINS=https://myapp.example.com in the environment causes the API to accept requests only from that origin.
  • Unsetting CORS_ORIGINS still allows localhost:3000 and localhost:5173.
  • No hardcoded origin strings remain in api.py.
  • Config documented in a .env.example or README.

Reference

See ROADMAP.md § P1 Security hardening.

## Background Roadmap item: **P1 Security hardening — CORS allow-origins are hardcoded** `api.py` hardcodes `localhost:3000` and `localhost:5173` as CORS origins. When SPARC is deployed behind a real domain the frontend cannot reach the API, or the origins must be widened to `*` (insecure). ## Task 1. Add a `CORS_ORIGINS` environment variable to `config.py` that accepts a comma-separated list of origins (e.g. `https://sparc.example.com,https://sparc-staging.example.com`). 2. Fall back to `["http://localhost:3000", "http://localhost:5173"]` when the variable is unset (preserves local-dev behaviour). 3. Update the `CORSMiddleware` setup in `api.py` to read from the config value. 4. Update `docker-compose.yml` with a commented-out `CORS_ORIGINS` example. ## Acceptance Criteria - [ ] Setting `CORS_ORIGINS=https://myapp.example.com` in the environment causes the API to accept requests only from that origin. - [ ] Unsetting `CORS_ORIGINS` still allows `localhost:3000` and `localhost:5173`. - [ ] No hardcoded origin strings remain in `api.py`. - [ ] Config documented in a `.env.example` or `README`. ## Reference See ROADMAP.md § P1 Security hardening.
AI-Manager added the P1agent-readysmallsecurity labels 2026-03-30 17:22:11 +00:00
Author
Owner

Resolved by PR #27 (merged). CORS origins are now configurable via the CORS_ORIGINS environment variable in config.py, with sensible localhost defaults for development.

Resolved by PR #27 (merged). CORS origins are now configurable via the `CORS_ORIGINS` environment variable in `config.py`, with sensible localhost defaults for development.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#1376