forked from Rockachopa/Timmy-time-dashboard
Compare commits
1 Commits
main
...
kimi/issue
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9578330c87 |
@@ -138,7 +138,12 @@ class Settings(BaseSettings):
|
|||||||
|
|
||||||
# CORS allowed origins for the web chat interface (Gitea Pages, etc.)
|
# CORS allowed origins for the web chat interface (Gitea Pages, etc.)
|
||||||
# Set CORS_ORIGINS as a comma-separated list, e.g. "http://localhost:3000,https://example.com"
|
# Set CORS_ORIGINS as a comma-separated list, e.g. "http://localhost:3000,https://example.com"
|
||||||
cors_origins: list[str] = ["*"]
|
cors_origins: list[str] = [
|
||||||
|
"http://localhost:3000",
|
||||||
|
"http://localhost:8000",
|
||||||
|
"http://127.0.0.1:3000",
|
||||||
|
"http://127.0.0.1:8000",
|
||||||
|
]
|
||||||
|
|
||||||
# Trusted hosts for the Host header check (TrustedHostMiddleware).
|
# Trusted hosts for the Host header check (TrustedHostMiddleware).
|
||||||
# Set TRUSTED_HOSTS as a comma-separated list. Wildcards supported (e.g. "*.ts.net").
|
# Set TRUSTED_HOSTS as a comma-separated list. Wildcards supported (e.g. "*.ts.net").
|
||||||
|
|||||||
@@ -484,15 +484,19 @@ app = FastAPI(
|
|||||||
|
|
||||||
|
|
||||||
def _get_cors_origins() -> list[str]:
|
def _get_cors_origins() -> list[str]:
|
||||||
"""Get CORS origins from settings, with sensible defaults."""
|
"""Get CORS origins from settings, rejecting wildcards in production."""
|
||||||
origins = settings.cors_origins
|
origins = settings.cors_origins
|
||||||
if settings.debug and origins == ["*"]:
|
if not settings.debug and "*" in origins:
|
||||||
return [
|
logger.warning(
|
||||||
"http://localhost:3000",
|
"Wildcard '*' in CORS_ORIGINS ignored in production — "
|
||||||
"http://localhost:8000",
|
"set explicit origins via CORS_ORIGINS env var"
|
||||||
"http://127.0.0.1:3000",
|
)
|
||||||
"http://127.0.0.1:8000",
|
origins = [o for o in origins if o != "*"]
|
||||||
]
|
if not origins:
|
||||||
|
origins = [
|
||||||
|
"http://localhost:3000",
|
||||||
|
"http://localhost:8000",
|
||||||
|
]
|
||||||
return origins
|
return origins
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user