From 2f106d4fc31bbd02005f16b11e18208187791e87 Mon Sep 17 00:00:00 2001 From: Zander Work Date: Sat, 29 Feb 2020 20:37:57 -0800 Subject: [PATCH] Fix #1249 (#1250) * Fix behavior for `REVERSE_PROXY` setting when set to a boolean instead of a string --- CTFd/__init__.py | 2 +- tests/test_config.py | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/CTFd/__init__.py b/CTFd/__init__.py index ed0a0880..55a543f3 100644 --- a/CTFd/__init__.py +++ b/CTFd/__init__.py @@ -177,7 +177,7 @@ def create_app(config="CTFd.config.Config"): reverse_proxy = app.config.get("REVERSE_PROXY") if reverse_proxy: - if "," in reverse_proxy: + if type(reverse_proxy) is str and "," in reverse_proxy: proxyfix_args = [int(i) for i in reverse_proxy.split(",")] app.wsgi_app = ProxyFix(app.wsgi_app, None, *proxyfix_args) else: diff --git a/tests/test_config.py b/tests/test_config.py index e2384669..34add48b 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -32,6 +32,18 @@ def test_reverse_proxy_config(): assert app.wsgi_app.x_prefix == 1 destroy_ctfd(app) + class ReverseProxyConfig(TestingConfig): + REVERSE_PROXY = True + + app = create_ctfd(config=ReverseProxyConfig) + with app.app_context(): + assert app.wsgi_app.x_for == 1 + assert app.wsgi_app.x_proto == 1 + assert app.wsgi_app.x_host == 1 + assert app.wsgi_app.x_port == 1 + assert app.wsgi_app.x_prefix == 1 + destroy_ctfd(app) + def test_server_sent_events_config(): """Test that SERVER_SENT_EVENTS configuration behaves properly"""