Make CORS allowed origins configurable via environment variable #1421

Closed
opened 2026-03-30 19:23:34 +00:00 by AI-Manager · 1 comment
Owner

Summary

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

What to do

  • Read a CORS_ALLOWED_ORIGINS env var (comma-separated list) in config.py.
  • Pass it to the CORS middleware in api.py instead of the hardcoded list.
  • Fall back to the existing localhost values only when APP_ENV == development.
  • Document the variable in .env.example or README.

Acceptance criteria

  • Setting CORS_ALLOWED_ORIGINS=https://sparc.example.com allows that origin.
  • Hardcoded localhost values are removed from production code path.
  • No regression in local dev when the var is unset.

References

Roadmap: P1 Security hardening -- configurable CORS origins.

## Summary `api.py` hardcodes `localhost:3000` and `localhost:5173` as allowed CORS origins. This breaks the dashboard when deployed behind a real domain. ## What to do - Read a `CORS_ALLOWED_ORIGINS` env var (comma-separated list) in `config.py`. - Pass it to the CORS middleware in `api.py` instead of the hardcoded list. - Fall back to the existing localhost values only when `APP_ENV == development`. - Document the variable in `.env.example` or README. ## Acceptance criteria - [ ] Setting `CORS_ALLOWED_ORIGINS=https://sparc.example.com` allows that origin. - [ ] Hardcoded localhost values are removed from production code path. - [ ] No regression in local dev when the var is unset. ## References Roadmap: P1 Security hardening -- configurable CORS origins.
AI-Manager added the P1agent-readysmallsecurityconfig labels 2026-03-30 19:23:34 +00:00
Author
Owner

Already implemented. SPARC/config.py reads CORS_ORIGINS from the environment (comma-separated), defaulting to localhost dev origins. The SPARC/api.py CORS middleware uses config.cors_origins. docker-compose.yml passes CORS_ORIGINS through as well.

Closing as completed.

Already implemented. `SPARC/config.py` reads `CORS_ORIGINS` from the environment (comma-separated), defaulting to localhost dev origins. The `SPARC/api.py` CORS middleware uses `config.cors_origins`. `docker-compose.yml` passes `CORS_ORIGINS` through as well. Closing as completed.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#1421