ProxyHeadersMiddleware does not handle multiple values of X-Forwarded-Proto header #2310
Unanswered
pmeier
asked this question in
Potential Issue
Replies: 2 comments
-
|
|
Beta Was this translation helpful? Give feedback.
0 replies
-
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
While the
X-Forwarded-*headers are not standardized, the RFC 7239 states the following about theForwarded-*headers, which are supposed to be a replacement for the former (see #2237):Meaning, the value cannot just be
httporhttps, but alsohttp,https.Currently
ProxyHeadersMiddlewarejust uses the value as is:https://github.com/encode/uvicorn/blob/0efd3835da6dcc713f74aadf7b52779d0d1fa17d/uvicorn/middleware/proxy_headers.py#L55-L58
When building a URL from this, i.e. by FastAPI / starlette, we are effectively doing
url = f"{scheme}://...".When trying to process this further,
starlette.datastructures.URLprovides thereplacemethod, which allows users to replace parts of the URL. Internally this relies onurllib.parse.urlsplitand the._replacemethod of its result. However, in turn, this doesn't recognize the scheme and puts all the information into the path and ultimately losing the information:Contrast this with the case of a valid scheme:
We should process the header and only select one of the options for the scheme. For example, here is how Tornado is doing it:
I'm happy to provide a patch for this if we deem this an issue to be fixed.
Beta Was this translation helpful? Give feedback.
All reactions