encode / uvicorn

An ASGI web server, for Python. 🦄
https://www.uvicorn.org/
BSD 3-Clause "New" or "Revised" License
8.57k stars 745 forks source link

Add support for multiple values for the x-forwarded-proto header #2104

Closed vanschelven closed 8 months ago

vanschelven commented 1 year ago

See #2102

When uvicorn is deployed behind more than one proxy, the proxy behavior is sometimes to list the protocol as a comma-separated list.

However, currently, uvicorn expects only one value for the x-forwarded-proto header, instead of parsing it as a list of values and setting the protocol accordingly.

x-forwarded-proto is a non-standard header, so there isn't a specification for its use, but different reverse-proxy vendors do use it in different ways, and some append the protocol as a comma-separated value from left-to-right (left being the furthermost proxy and rightmost being the closest).

Checklist

Kludex commented 8 months ago

I don't see much literature about receiving a comma-separated list. The main references I could find have either "https" or "http".

vanschelven commented 8 months ago

Do you not consider the list in the linked resource sufficiently authoritative enough or did you perhaps miss it? Quoted below:

Similar issues have been raised and implemented in other projects, for example:

Tornado:

Ruby:

Reactor-Netty:

Common example of this behavior is when using mulitple AWS proxies such as API Gateway proxying to an elastic load balancer.