fix(api): restrict CORS origins via ALLOWED_ORIGINS env

allow_origins was ["*"] together with allow_credentials=True, which is
both insecure and rejected by browsers for credentialed requests. Read a
comma-separated ALLOWED_ORIGINS env var instead, defaulting to the Vite
dev origin http://localhost:5173. Documented in .env.example.
This commit is contained in:
dextmorgn
2026-05-30 18:49:44 +02:00
parent dd00bae9ce
commit ee06d6cf3e
2 changed files with 9 additions and 1 deletions
+2
View File
@@ -6,5 +6,7 @@ NEO4J_URI_BOLT=bolt://neo4j:7687
NEO4J_USERNAME=neo4j
NEO4J_PASSWORD=password
VITE_API_URL=http://127.0.0.1:5001
# Comma-separated CORS allowed origins. Defaults to http://localhost:5173 (Vite dev) when unset.
ALLOWED_ORIGINS=http://localhost:5173
DATABASE_URL=postgresql://flowsint:flowsint@localhost:5433/flowsint
REDIS_URL=redis://redis:6379/0
+7 -1
View File
@@ -1,3 +1,5 @@
import os
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
@@ -16,8 +18,12 @@ from app.api.routes import types
from app.api.routes import custom_types
from app.api.routes import enricher_templates
# Comma-separated list of allowed origins, e.g. "https://app.example.com,https://staging.example.com"
# Falls back to localhost dev origin when unset. Never use "*" with allow_credentials=True.
origins = [
"*",
o.strip()
for o in os.getenv("ALLOWED_ORIGINS", "http://localhost:5173").split(",")
if o.strip()
]