Skip to content

Commit 9577319

Browse files
PttCodingManclaude
andcommitted
fix: allow configurable CSRF/CORS origins via env.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 18a089f commit 9577319

3 files changed

Lines changed: 11 additions & 1 deletion

File tree

.env.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ MEDIA_DIR=./data/media
1010

1111
# ── Security ──
1212
COOKIE_SECURE=false # Set to true in production with HTTPS
13+
# Extra origins allowed for CSRF/CORS (comma-separated). localhost:5173 and
14+
# localhost:3000 are always allowed. Set your public URL here in prod.
15+
ALLOWED_ORIGINS=
1316

1417
# ── Frontend ──
1518
VITE_API_URL=http://localhost:8000

backend/app/config.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ class Settings(BaseSettings):
1414
VITE_API_URL: str = "http://localhost:8000"
1515
COOKIE_SECURE: bool = False # Set to True in production with HTTPS
1616

17+
# Comma-separated list of origins allowed for CSRF/CORS on top of the
18+
# always-included localhost dev origins. Set this to your public URL(s)
19+
# in production, e.g. "https://wiki.example.com".
20+
ALLOWED_ORIGINS: str = ""
21+
1722
# ── AI chat (optional, OpenAI-compatible) ──
1823
# Default targets Gemini's OpenAI-compatible endpoint, but any provider
1924
# that speaks the same wire format works (OpenAI, Ollama, Groq, DeepSeek…).

backend/app/main.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313

1414
logger = logging.getLogger("justwiki")
1515

16-
_ALLOWED_ORIGINS = {"http://localhost:5173", "http://localhost:3000"}
16+
_ALLOWED_ORIGINS = {"http://localhost:5173", "http://localhost:3000"} | {
17+
o.strip() for o in settings.ALLOWED_ORIGINS.split(",") if o.strip()
18+
}
1719
_SAFE_METHODS = {"GET", "HEAD", "OPTIONS"}
1820
_CSRF_EXEMPT_PATHS = {"/api/auth/login", "/api/auth/logout"}
1921

0 commit comments

Comments
 (0)