Skip to content

Commit

Permalink
checks XForeward-host
Browse files Browse the repository at this point in the history
  • Loading branch information
pcrespov committed Oct 10, 2024
1 parent a153ff1 commit 0d52645
Showing 1 changed file with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,18 @@

def _discover_product_by_hostname(request: web.Request) -> str | None:
products: OrderedDict[str, Product] = request.app[APP_PRODUCTS_KEY]
#
# SEE https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-Host
# SEE https://doc.traefik.io/traefik/getting-started/faq/#what-are-the-forwarded-headers-when-proxying-http-requests
originating_hosts = [
request.headers.get("X-Forwarded-Host"),
request.host,
]
for product in products.values():
if product.host_regex.search(request.host):
product_name: str = product.name
return product_name
for host in originating_hosts:
if host and product.host_regex.search(host):
product_name: str = product.name
return product_name
return None


Expand Down

0 comments on commit 0d52645

Please sign in to comment.