Skip to content

Commit 2d64c6a

Browse files
continue
1 parent 856e7fc commit 2d64c6a

File tree

1 file changed

+10
-19
lines changed

1 file changed

+10
-19
lines changed

services/web/server/src/simcore_service_webserver/utils_aiohttp.py

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -137,40 +137,31 @@ def iter_origins(request: web.Request) -> Iterator[str]:
137137
# SEE https://doc.traefik.io/traefik/getting-started/faq/#what-are-the-forwarded-headers-when-proxying-http-requests
138138
seen = set()
139139

140+
# X-Forwarded-Proto and X-Forwarded-Host can contain a comma-separated list of protocols and hosts
141+
# (when the request passes through multiple proxies)fwd_protos = [
140142
fwd_protos = [
141143
p.strip()
142-
for p in request.headers.get("X-Forwarded-Proto").split(",")
144+
for p in request.headers.get("X-Forwarded-Proto", "").split(",")
143145
if p.strip()
144146
]
145147
fwd_hosts = [
146148
h.strip()
147-
for h in request.headers.get("X-Forwarded-Host").split(",")
149+
for h in request.headers.get("X-Forwarded-Host", "").split(",")
148150
if h.strip()
149151
]
150-
fwd_ports = [
151-
pt.strip()
152-
for pt in request.headers.get("X-Forwarded-Port").split(",")
153-
if pt.strip()
154-
]
155152

156-
fwd_origins = [
157-
f"{proto}://{host}:{port}"
158-
for proto, host, port in zip(fwd_protos, fwd_hosts, fwd_ports, strict=False)
159-
]
160-
if fwd_origins:
161-
# X-Forwarded-Host can contain a comma-separated list of hosts
162-
# (when the request passes through multiple proxies)
153+
if fwd_protos and fwd_hosts:
154+
fwd_origins = [
155+
f"{proto}://{host}"
156+
for proto, host in zip(fwd_protos, fwd_hosts, strict=False)
157+
]
163158
for origin in fwd_origins:
164159
if origin and origin not in seen:
165160
seen.add(origin)
166161
yield origin
167162

168163
# Fallback to request.host
169-
if request.url:
170-
origin = f"{request.url.scheme}://{request.url.host}"
171-
if request.url.port:
172-
origin += f":{request.url.port}"
173-
yield origin
164+
yield f"{request.url.scheme}://{request.url.host}"
174165

175166

176167
def get_api_base_url(request: web.Request) -> str:

0 commit comments

Comments
 (0)