Skip to content
Snippets Groups Projects
Commit 18e3f840 authored by Xavier Morel's avatar Xavier Morel
Browse files

[FIX] core: compatibility with Werkzeug 0.15 ProxyFix


Werkzeug 0.15 modified ProxyFix such that by default it only forwards
the REMOTE_ADDR when enabled, whereas before 0.15 it would also
forward scheme and host. This breaks proxied odoo as the base url
becomes incorrect (cf #34412).

Use properly configured ProxyFix when running with werkzeug 0.15, old
configuration otherwise.

Backport of 4057227d which was merged
in master, because many people apparently run 0.15 now.

Closes #35085
closes odoo/odoo#36212

closes odoo/odoo#37708

Signed-off-by: default avatarXavier Morel (xmo) <xmo@odoo.com>
parent 780c8571
No related branches found
No related tags found
No related merge requests found
......@@ -121,8 +121,22 @@ def application_unproxied(environ, start_response):
# We never returned from the loop.
return werkzeug.exceptions.NotFound("No handler found.\n")(environ, start_response)
try:
# werkzeug >= 0.15
from werkzeug.middleware.proxy_fix import ProxyFix as ProxyFix_
# 0.15 also supports port and prefix, but 0.14 only forwarded for, proto
# and host so replicate that
ProxyFix = lambda app: ProxyFix_(app, x_for=1, x_proto=1, x_host=1)
except ImportError:
# werkzeug < 0.15
from werkzeug.contrib.fixers import ProxyFix
def application(environ, start_response):
# FIXME: is checking for the presence of HTTP_X_FORWARDED_HOST really useful?
# we're ignoring the user configuration, and that means we won't
# support the standardised Forwarded header once werkzeug supports
# it
if config['proxy_mode'] and 'HTTP_X_FORWARDED_HOST' in environ:
return werkzeug.contrib.fixers.ProxyFix(application_unproxied)(environ, start_response)
return ProxyFix(application_unproxied)(environ, start_response)
else:
return application_unproxied(environ, start_response)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment