From 2b91b203b0b4956803ef21c28d9ce31d6e08f432 Mon Sep 17 00:00:00 2001 From: Abdullah AlOsaimi <189027247+osaimi@users.noreply.github.com> Date: Tue, 28 Jan 2025 18:29:00 +0300 Subject: [PATCH] add support for X-Forwarded-Port in ProxyFix middleware --- api/configs/feature/__init__.py | 4 ++-- api/extensions/ext_proxy_fix.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/api/configs/feature/__init__.py b/api/configs/feature/__init__.py index 9e2ba417801477..4e67e71b32c38a 100644 --- a/api/configs/feature/__init__.py +++ b/api/configs/feature/__init__.py @@ -315,8 +315,8 @@ def WEB_API_CORS_ALLOW_ORIGINS(self) -> list[str]: ) RESPECT_XFORWARD_HEADERS_ENABLED: bool = Field( - description="Enable or disable the X-Forwarded-For Proxy Fix middleware from Werkzeug" - " to respect X-* headers to redirect clients", + description="Enable handling of X-Forwarded-For, X-Forwarded-Proto, and X-Forwarded-Port headers" + " when the app is behind a single trusted reverse proxy.", default=False, ) diff --git a/api/extensions/ext_proxy_fix.py b/api/extensions/ext_proxy_fix.py index 514e0658257293..c085aed98643d3 100644 --- a/api/extensions/ext_proxy_fix.py +++ b/api/extensions/ext_proxy_fix.py @@ -6,4 +6,4 @@ def init_app(app: DifyApp): if dify_config.RESPECT_XFORWARD_HEADERS_ENABLED: from werkzeug.middleware.proxy_fix import ProxyFix - app.wsgi_app = ProxyFix(app.wsgi_app) # type: ignore + app.wsgi_app = ProxyFix(app.wsgi_app, x_port=1) # type: ignore