Skip to content
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

AWS load balancers do not provide X-Forwarded-Host. #24

Open
wants to merge 1 commit into
base: 15.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions odoo/service/wsgi_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,18 @@ def application_unproxied(environ, start_response):
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)
ProxyFix = lambda app: ProxyFix_(app,
x_for=config['proxy_x_for'],
x_proto=config['proxy_x_proto'],
x_host=config['proxy_x_host'],
x_port=config['proxy_x_port'],
x_prefix=config['proxy_x_prefix'])
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:
if config['proxy_mode']:
return ProxyFix(application_unproxied)(environ, start_response)
else:
return application_unproxied(environ, start_response)
14 changes: 14 additions & 0 deletions odoo/tools/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,23 @@ def __init__(self, fname=None):
help="Listen port for the longpolling HTTP service", type="int", metavar="PORT")
group.add_option("--no-http", dest="http_enable", action="store_false", my_default=True,
help="Disable the HTTP and Longpolling services entirely")

# HTTP: configure werkzeug proxy mode
# https://werkzeug.palletsprojects.com/en/0.16.x/middleware/proxy_fix/
group.add_option("--proxy-mode", dest="proxy_mode", action="store_true", my_default=False,
help="Activate reverse proxy WSGI wrappers (headers rewriting) "
"Only enable this when running behind a trusted web proxy!")
group.add_option("--proxy-x-for", dest="proxy_x_for", type="int", my_default=1,
help="Number of values to trust for X-Forwarded-For.")
group.add_option("--proxy-x-proto", dest="proxy_x_proto", type="int", my_default=1,
help="Number of values to trust for X-Forwarded-Proto.")
group.add_option("--proxy-x-host", dest="proxy_x_host", type="int", my_default=1,
help="Number of values to trust for X-Forwarded-Host.")
group.add_option("--proxy-x-port", dest="proxy_x_port", type="int", my_default=0,
help="Number of values to trust for X-Forwarded-Port.")
group.add_option("--proxy-x-prefix", dest="proxy_x_prefix", type="int", my_default=0,
help="Number of values to trust for X-Forwarded-Prefix.")

# HTTP: hidden backwards-compatibility for "*xmlrpc*" options
hidden = optparse.SUPPRESS_HELP
group.add_option("--xmlrpc-interface", dest="http_interface", help=hidden)
Expand Down