From e0b41243b413c841d84f2e85d7ba3e71382febf4 Mon Sep 17 00:00:00 2001 From: comfyanonymous Date: Mon, 9 Sep 2024 03:18:17 -0400 Subject: [PATCH] Fix issue where sometimes origin doesn't contain the port. --- server.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/server.py b/server.py index 4f8053fc..93147f6c 100644 --- a/server.py +++ b/server.py @@ -87,7 +87,12 @@ def create_origin_only_middleware(): host = request.headers['Host'] origin = request.headers['Origin'] host_domain = host.lower() - origin_domain = urllib.parse.urlparse(origin).netloc.lower() + parsed = urllib.parse.urlparse(origin) + origin_domain = parsed.netloc.lower() + if parsed.port is None: #if origin doesn't have a port strip it from the host to handle weird browsers + result = urllib.parse.urlsplit('//' + host_domain) + host_domain = result.hostname + if len(host_domain) > 0 and len(origin_domain) > 0: if host_domain != origin_domain: logging.warning("WARNING: request with non matching host and origin {} != {}, returning 403".format(host_domain, origin_domain))