Fix CORS default: restrict allowed origins from wildcard to explicit list #8

Open
opened 2026-04-20 09:34:50 +00:00 by sharang · 0 comments
Owner

Problem

backend-compliance/main.py:70:

ALLOWED_ORIGINS = os.getenv("CORS_ORIGINS", "*").split(",")

When CORS_ORIGINS is not set, every origin is allowed. Combined with the missing auth middleware (#4), this means any webpage can make authenticated API requests on behalf of a logged-in user.

Required Actions

  1. Change default to "" — no origins allowed unless explicitly configured
  2. Add allow_credentials=True only if using httpOnly cookie auth (see M5 frontend issue)
  3. Validate that configured origins are well-formed URLs at startup
  4. Apply same fix to any other FastAPI apps in the repo (dsms-gateway, document-crawler)

Acceptance Criteria

  • Missing CORS_ORIGINS env var causes startup warning and allows zero cross-origin requests
  • CORS headers are absent on responses when origin is not in the allowlist
  • Depends on: #7 (env var enforcement)
## Problem `backend-compliance/main.py:70`: ```python ALLOWED_ORIGINS = os.getenv("CORS_ORIGINS", "*").split(",") ``` When `CORS_ORIGINS` is not set, every origin is allowed. Combined with the missing auth middleware (#4), this means any webpage can make authenticated API requests on behalf of a logged-in user. ## Required Actions 1. Change default to `""` — no origins allowed unless explicitly configured 2. Add `allow_credentials=True` only if using httpOnly cookie auth (see M5 frontend issue) 3. Validate that configured origins are well-formed URLs at startup 4. Apply same fix to any other FastAPI apps in the repo (dsms-gateway, document-crawler) ## Acceptance Criteria - Missing `CORS_ORIGINS` env var causes startup warning and allows zero cross-origin requests - CORS headers are absent on responses when origin is not in the allowlist - Depends on: #7 (env var enforcement)
sharang added this to the M1: Security Foundation milestone 2026-04-20 09:34:50 +00:00
sharang added the severity: highsecurity labels 2026-04-20 09:34:50 +00:00
Sign in to join this conversation.