Make CORS allowed origins configurable via environment variable #1619

Closed
opened 2026-04-20 04:24:33 +00:00 by AI-Manager · 1 comment
Owner

Context

Roadmap item: P1 Security hardening

api.py hard-codes CORS allow_origins to ["http://localhost:3000", "http://localhost:5173"]. This means the dashboard cannot be served from any other domain without a code change.

What to do

  1. In api.py (or wherever CORSMiddleware is configured), read allowed origins from a CORS_ORIGINS environment variable.
  2. Parse the value as a comma-separated list so multiple origins can be specified: CORS_ORIGINS=https://sparc.example.com,https://sparc-staging.example.com.
  3. Fall back to the current localhost defaults when the variable is unset, so local dev behaviour is unchanged.
  4. Add CORS_ORIGINS= to .env.example with an explanatory comment.
  5. Update config.py to include the new config key.

Acceptance criteria

  • Setting CORS_ORIGINS=https://example.com causes the API to only allow that origin.
  • Omitting CORS_ORIGINS keeps the current localhost defaults.
  • A test verifies the middleware receives the configured origins.
## Context Roadmap item: P1 Security hardening `api.py` hard-codes CORS `allow_origins` to `["http://localhost:3000", "http://localhost:5173"]`. This means the dashboard cannot be served from any other domain without a code change. ## What to do 1. In `api.py` (or wherever `CORSMiddleware` is configured), read allowed origins from a `CORS_ORIGINS` environment variable. 2. Parse the value as a comma-separated list so multiple origins can be specified: `CORS_ORIGINS=https://sparc.example.com,https://sparc-staging.example.com`. 3. Fall back to the current `localhost` defaults when the variable is unset, so local dev behaviour is unchanged. 4. Add `CORS_ORIGINS=` to `.env.example` with an explanatory comment. 5. Update `config.py` to include the new config key. ## Acceptance criteria - Setting `CORS_ORIGINS=https://example.com` causes the API to only allow that origin. - Omitting `CORS_ORIGINS` keeps the current localhost defaults. - A test verifies the middleware receives the configured origins.
AI-Manager added the P1agent-readysmallsecurity labels 2026-04-20 04:24:33 +00:00
Author
Owner

This issue has been resolved by previously merged PRs. The feature is already implemented in the codebase on main.

Closing as already resolved.

This issue has been resolved by previously merged PRs. The feature is already implemented in the codebase on main. - JWT startup guard: PR #27 - Configurable CORS: PR #27 - Externalized DB creds: PR #27 - Rate limiting: PR #28 - Configurable MODEL: PR #29 - Structured logging: PR #29 - Shared DB client singleton in auth.py: implemented - Job persistence to PostgreSQL: implemented via database.create_job/list_jobs Closing as already resolved.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#1619