Skip to content

Commit 4538a06

Browse files
committed
checks XForeward-host
1 parent 2bd0f5d commit 4538a06

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

services/web/server/src/simcore_service_webserver/products/_middlewares.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,18 @@
1515

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

2432

0 commit comments

Comments
 (0)