From 11bb4b414b7351d8d23a3319d38105d52dfb703a Mon Sep 17 00:00:00 2001 From: Nicola Soranzo Date: Wed, 10 Apr 2024 12:08:11 +0100 Subject: [PATCH] Fix KeyError in ``XForwardedHostMiddleware`` when `REMOTE_ADDR` is not defined. Reported by @vazovn . Also fix typos in environment variable names. --- lib/galaxy/web/framework/middleware/xforwardedhost.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/galaxy/web/framework/middleware/xforwardedhost.py b/lib/galaxy/web/framework/middleware/xforwardedhost.py index 3e0e11958632..d47d741bc9c1 100644 --- a/lib/galaxy/web/framework/middleware/xforwardedhost.py +++ b/lib/galaxy/web/framework/middleware/xforwardedhost.py @@ -10,11 +10,11 @@ def __init__(self, app, global_conf=None): def __call__(self, environ, start_response): x_forwarded_host = environ.get("HTTP_X_FORWARDED_HOST", None) if x_forwarded_host: - environ["ORGINAL_HTTP_HOST"] = environ["HTTP_HOST"] + environ["ORIGINAL_HTTP_HOST"] = environ.get("HTTP_HOST") environ["HTTP_HOST"] = x_forwarded_host.split(", ", 1)[0] x_forwarded_for = environ.get("HTTP_X_FORWARDED_FOR", None) if x_forwarded_for: - environ["ORGINAL_REMOTE_ADDR"] = environ["REMOTE_ADDR"] + environ["ORIGINAL_REMOTE_ADDR"] = environ.get("REMOTE_ADDR") environ["REMOTE_ADDR"] = x_forwarded_for.split(",", 1)[0].strip() x_forwarded_proto = environ.get("HTTP_X_FORWARDED_PROTO", None) if x_forwarded_proto: