Skip to content

Commit

Permalink
Fix KeyError in XForwardedHostMiddleware
Browse files Browse the repository at this point in the history
when `REMOTE_ADDR` is not defined.
Reported by @vazovn .

Also fix typos in environment variable names.
  • Loading branch information
nsoranzo committed Apr 10, 2024
1 parent 3abb181 commit 11bb4b4
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/galaxy/web/framework/middleware/xforwardedhost.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 11bb4b4

Please sign in to comment.