-
Notifications
You must be signed in to change notification settings - Fork 105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support multiple proxy servers in Forwarded header parsing #782
Conversation
@lukasbindreiter hope you don't mind, I've pushed some change directly in your branch Let me know how it looks for you and then I could merge and release this tomorrow |
@vincentsarago I've made some small changes to it:
(worth it I think in this case, its an easy optimization thats twice as fast) |
@vincentsarago everything looks ready from my side - would be awesome if you could take another look, and then merge it if everything is fine. Thanks a lot! (I also just rebased it, there was a conflicting changelog entry already upstream) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great @lukasbindreiter 🙏
I'll merge this to main
and maybe backport it to a 3.0.6 release if you absolutely need this in a 3.0.*
version (next version in main
has breaking change and will be released in a 3.1 or 4.0)
Awesome, thanks a lot! 🙏 It's fine if its in |
Related Issue(s):
(none, since I directly created the Pull request for the fix)
Description:
According to the Forwarded HTTP header spec, multiple proxy servers can add values to the
Forwarded
header by creating acomma
separated list:The existing
ProxyHeaderMiddleware
however doesn't account for this, and instead raises aValueError
in such cases, because it only splits the string on;
but not on,
before that.Therefore, a valid
Forwarded
header ofb"proto=https;host=test:1234,proto=https;host=second-server:1111"
produces a:ValueError: too many values to unpack (expected 2)
because it essentially runs:I've encountered this when deploying our STAC API server on GCP Cloud run, behind a GCP Load balancer.
GCP doesn't even actually set the
host
but the middleware in place still causes all requests to fail with a ValueError.(The header on GCP that we receive is
b'for="85.193.181.55";proto=https,for="85.193.181.55";proto=https'
)PR Checklist:
pre-commit
hooks pass locallymake test
)make docs
)