Conversation
support multiple values for all headers configure trust for each header separately store original values in dict in environ parametrize tests for ProxyFix and get_host rewrite docs for ProxyFix and get_host
yajo
added a commit
to Tecnativa/odoo
that referenced
this pull request
Feb 28, 2019
Without this patch, Odoo is compatible only with one single inverse proxy in front of it.
However, when several proxies are chained in front of it, and all of them use the [proxy protocol][1], Odoo would understand the latest one's IP is the remote IP that is originating the HTTP request.
When several proxies are chained, Werkzeug receives this HTTP header:
X-Forwarded-For: 1.2.3.4, 5.6.7.8
It means that 1.2.3.4 is the request originator, and 5.6.7.8 is the 1st proxy.
If using [Werkzeug >= 0.14.1][2], which logs the correct IP, the logs would end up with:
2019-02-14 10:15:09,042 37 INFO prod werkzeug: 5.6.7.8 - - [14/Feb/2019 10:15:09] "GET /web/login HTTP/1.1" 200 -
After this patch, if you use the proper Werkzeug version and configure Odoo with `--proxy-trusted-x-for=2`, you'd get instead:
2019-02-14 10:15:09,042 37 INFO prod werkzeug: 1.2.3.4 - - [14/Feb/2019 10:15:09] "GET /web/login HTTP/1.1" 200 -
This patch is prepared to be expanded later, when Werkzeug 0.15 is released, with the `ProxyFix` refactoring made in pallets/werkzeug#1314 available, and further options for other proxy protocol headers can be added in a similar fashion.
[1]: https://www.haproxy.org/download/1.8/doc/proxy-protocol.txt
[2]: odoo#18052 (comment)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
num_proxiesis deprecated. For backwards compatibility with the common case,x_fordefaults to 1.werkzeug.proxy_fix.originstead of individual keys. The keys in the dict match the environ keys.ProxyFixandget_host.I want to add support for the standard
Forwardedheader.I considered refactoring the somewhat repetitious code in
__call__with a for loop, but it ended up being about as complicated and seemed harder to follow.Eventually this should be moved out of contrib into a new
werkzeug.middleware.proxy_fixmodule.