mirror of
https://github.com/bytedance/deer-flow.git
synced 2026-05-06 00:38:23 +00:00
* fix(security): allow disabling API docs in production via GATEWAY_ENABLE_DOCS Expose /docs, /redoc, and /openapi.json only when GATEWAY_ENABLE_DOCS=true (default). Setting GATEWAY_ENABLE_DOCS=false disables all three endpoints, preventing unauthorized API surface discovery in production deployments. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * test(security): add unit tests and docs for GATEWAY_ENABLE_DOCS Add 7 tests covering default behavior, env var parsing (case-insensitive, fail-closed), endpoint visibility, and health endpoint independence. Update CONFIGURATION.md and CLAUDE.md with the new toggle. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * style(security): apply ruff formatting to gateway app.py Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> Co-authored-by: Willem Jiang <willem.jiang@gmail.com>
30 lines
1.1 KiB
Python
30 lines
1.1 KiB
Python
import os
|
|
|
|
from pydantic import BaseModel, Field
|
|
|
|
|
|
class GatewayConfig(BaseModel):
|
|
"""Configuration for the API Gateway."""
|
|
|
|
host: str = Field(default="0.0.0.0", description="Host to bind the gateway server")
|
|
port: int = Field(default=8001, description="Port to bind the gateway server")
|
|
cors_origins: list[str] = Field(default_factory=lambda: ["http://localhost:3000"], description="Allowed CORS origins")
|
|
enable_docs: bool = Field(default=True, description="Enable Swagger/ReDoc/OpenAPI endpoints")
|
|
|
|
|
|
_gateway_config: GatewayConfig | None = None
|
|
|
|
|
|
def get_gateway_config() -> GatewayConfig:
|
|
"""Get gateway config, loading from environment if available."""
|
|
global _gateway_config
|
|
if _gateway_config is None:
|
|
cors_origins_str = os.getenv("CORS_ORIGINS", "http://localhost:3000")
|
|
_gateway_config = GatewayConfig(
|
|
host=os.getenv("GATEWAY_HOST", "0.0.0.0"),
|
|
port=int(os.getenv("GATEWAY_PORT", "8001")),
|
|
cors_origins=cors_origins_str.split(","),
|
|
enable_docs=os.getenv("GATEWAY_ENABLE_DOCS", "true").lower() == "true",
|
|
)
|
|
return _gateway_config
|