From 360484e2d515f746755c355ae0aecc1d4f2852fa Mon Sep 17 00:00:00 2001 From: Unrud Date: Wed, 8 Mar 2023 15:49:46 +0100 Subject: [PATCH] Use X-Forwarded-* for server netloc when available Closes #1271 --- radicale/app/move.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/radicale/app/move.py b/radicale/app/move.py index 0c990e3f..0c38eed5 100644 --- a/radicale/app/move.py +++ b/radicale/app/move.py @@ -28,9 +28,14 @@ from radicale.log import logger def get_server_netloc(environ: types.WSGIEnviron, force_port: bool = False): - host = environ.get("HTTP_HOST") or environ["SERVER_NAME"] - proto = environ["wsgi.url_scheme"] - port = environ["SERVER_PORT"] + if environ.get("HTTP_X_FORWARDED_HOST"): + host = environ["HTTP_X_FORWARDED_HOST"] + proto = environ.get("HTTP_X_FORWARDED_PROTO") or "http" + port = "443" if proto == "https" else "80" + else: + host = environ.get("HTTP_HOST") or environ["SERVER_NAME"] + proto = environ["wsgi.url_scheme"] + port = environ["SERVER_PORT"] if (not force_port and port == ("443" if proto == "https" else "80") or re.search(r":\d+$", host)): return host