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

[IMP] AWS load balancers do not provide X-Forwarded-Host. #29

Open
wants to merge 1 commit into
base: 16.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
14 changes: 8 additions & 6 deletions odoo/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,7 @@
from werkzeug.urls import URL, url_parse, url_encode, url_quote
from werkzeug.exceptions import (HTTPException, BadRequest, Forbidden,
NotFound, InternalServerError)
try:
from werkzeug.middleware.proxy_fix import ProxyFix as ProxyFix_
ProxyFix = functools.partial(ProxyFix_, x_for=1, x_proto=1, x_host=1)
except ImportError:
from werkzeug.contrib.fixers import ProxyFix
from werkzeug.middleware.proxy_fix import ProxyFix as ProxyFix_

try:
from werkzeug.utils import send_file as _send_file
Expand All @@ -172,6 +168,12 @@
from .tools._vendor import sessions
from .tools._vendor.useragents import UserAgent

ProxyFix = functools.partial(ProxyFix_,
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'])

_logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -1918,7 +1920,7 @@ def __call__(self, environ, start_response):
current_thread.query_time = 0
current_thread.perf_t0 = time.time()

if odoo.tools.config['proxy_mode'] and environ.get("HTTP_X_FORWARDED_HOST"):
if odoo.tools.config['proxy_mode']:
# The ProxyFix middleware has a side effect of updating the
# environ, see https://github.com/pallets/werkzeug/pull/2184
def fake_app(environ, start_response):
Expand Down
15 changes: 15 additions & 0 deletions odoo/tools/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,28 @@ def __init__(self, fname=None):
help="Listen port for the gevent worker", 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.")

group.add_option("--x-sendfile", dest="x_sendfile", action="store_true", my_default=False,
help="Activate X-Sendfile (apache) and X-Accel-Redirect (nginx) "
"HTTP response header to delegate the delivery of large "
"files (assets/attachments) to the web server.")

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