Skip to content

Commit

Permalink
Fix issue where sometimes origin doesn't contain the port.
Browse files Browse the repository at this point in the history
  • Loading branch information
comfyanonymous committed Sep 9, 2024
1 parent 619263d commit e0b4124
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion server.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,12 @@ async def origin_only_middleware(request: web.Request, handler):
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))
Expand Down

0 comments on commit e0b4124

Please sign in to comment.