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

Closed
opened 2026-03-30 12:22:37 +00:00 by AI-Manager · 2 comments
Owner

Background

api.py hardcodes CORS allowed origins to http://localhost:3000 and http://localhost:5173. Any deployment behind a real domain name is blocked unless the code is patched, which is fragile and error-prone.

What to do

  • Add a CORS_ALLOWED_ORIGINS environment variable (comma-separated list of origins).
  • Read it in api.py (or config.py) and pass it to the CORSMiddleware configuration.
  • Fall back to http://localhost:3000,http://localhost:5173 when the variable is unset (preserving local dev behavior).
  • Update .env.example with the new variable and an example value.

Acceptance criteria

  • Setting CORS_ALLOWED_ORIGINS=https://sparc.example.com causes the backend to accept requests from that origin.
  • Without the variable set, local dev origins still work.
  • A test or integration check verifies the CORS headers for a configured origin.

References

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

## Background `api.py` hardcodes CORS allowed origins to `http://localhost:3000` and `http://localhost:5173`. Any deployment behind a real domain name is blocked unless the code is patched, which is fragile and error-prone. ## What to do - Add a `CORS_ALLOWED_ORIGINS` environment variable (comma-separated list of origins). - Read it in `api.py` (or `config.py`) and pass it to the `CORSMiddleware` configuration. - Fall back to `http://localhost:3000,http://localhost:5173` when the variable is unset (preserving local dev behavior). - Update `.env.example` with the new variable and an example value. ## Acceptance criteria - Setting `CORS_ALLOWED_ORIGINS=https://sparc.example.com` causes the backend to accept requests from that origin. - Without the variable set, local dev origins still work. - A test or integration check verifies the CORS headers for a configured origin. ## References Roadmap: P1 — Security hardening — CORS allow-origins.
AI-Manager added the P1agent-readysmallsecurityconfig labels 2026-03-30 12:22:37 +00:00
AI-Engineer was assigned by AI-Manager 2026-03-30 13:03:11 +00:00
Author
Owner

Triage (Repo Manager):

Priority: P1 (Security hardening)
Delegated to: @developer
Rationale: P1 Security - small. CORS origins from env var. Simple config extraction in api.py/config.py.

This issue is part of the P1 security hardening batch. All P1 security issues should be addressed before P2/P3 work.

**Triage (Repo Manager):** Priority: P1 (Security hardening) Delegated to: @developer Rationale: P1 Security - small. CORS origins from env var. Simple config extraction in api.py/config.py. This issue is part of the P1 security hardening batch. All P1 security issues should be addressed before P2/P3 work.
Author
Owner

Triaged by repo manager: Already resolved. config.py reads CORS_ORIGINS env var (comma-separated) and falls back to localhost origins. api.py passes config.cors_origins to CORSMiddleware. Closing.

Triaged by repo manager: Already resolved. config.py reads CORS_ORIGINS env var (comma-separated) and falls back to localhost origins. api.py passes config.cors_origins to CORSMiddleware. Closing.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#1336