File tree Expand file tree Collapse file tree 1 file changed +17
-6
lines changed
services/web/server/src/simcore_service_webserver Expand file tree Collapse file tree 1 file changed +17
-6
lines changed Original file line number Diff line number Diff line change @@ -134,9 +134,20 @@ def iter_originating_hosts(request: web.Request) -> Iterator[str]:
134134 #
135135 # SEE https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-Host
136136 # SEE https://doc.traefik.io/traefik/getting-started/faq/#what-are-the-forwarded-headers-when-proxying-http-requests
137- for host in (
138- request .headers .get ("X-Forwarded-Host" ),
139- request .host ,
140- ):
141- if host is not None :
142- yield host .partition (":" )[0 ] # exclude port, if any
137+ seen = set ()
138+
139+ forwarded = request .headers .get ("X-Forwarded-Host" )
140+ if forwarded :
141+ # X-Forwarded-Host can contain a comma-separated list of hosts
142+ # (when the request passes through multiple proxies)
143+ for host in forwarded .split ("," ):
144+ stripped_host = host .strip ().partition (":" )[0 ]
145+ if stripped_host and stripped_host not in seen :
146+ seen .add (stripped_host )
147+ yield host
148+
149+ # Fallback to request.host
150+ if request .host :
151+ host = request .host .partition (":" )[0 ]
152+ if host not in seen :
153+ yield host
You can’t perform that action at this time.
0 commit comments