Repository: CTFd/CTFd

Issue:
Fails to start when reverse proxy is configured with boolean
<!--
If this is a bug report please fill out the template below.

If this is a feature request please describe the behavior that you'd like to see.
-->

**Environment**:

  - CTFd Version/Commit: 22c1323
  - Operating System: Ubuntu 18.04
  - Web Browser and Version: n/a

**What happened?**

Running with docker-compose, fails to start due to bad type checking on the reverse proxy config var

**What did you expect to happen?**

Should have properly started

**How to reproduce your issue**

Set `REVERSE_PROXY` in CTFd/config.py to `True`

**Any associated stack traces or error logs**

```
ctfd_1   | Traceback (most recent call last):
ctfd_1   |   File "manage.py", line 9, in <module>
ctfd_1   |     app = create_app()
ctfd_1   |   File "/opt/CTFd/CTFd/__init__.py", line 180, in create_app
ctfd_1   |     if "," in reverse_proxy:
ctfd_1   | TypeError: argument of type 'bool' is not iterable
ctfd_1   | Traceback (most recent call last):
ctfd_1   |   File "manage.py", line 9, in <module>
ctfd_1   |     app = create_app()
ctfd_1   |   File "/opt/CTFd/CTFd/__init__.py", line 180, in create_app
ctfd_1   |     if "," in reverse_proxy:
ctfd_1   | TypeError: argument of type 'bool' is not iterable
ctfd_ctfd_1 exited with code 1
```

I have a patch for this ready to go and will make a pull request.

Fails to start when reverse proxy is configured with boolean
<!--
If this is a bug report please fill out the template below.

If this is a feature request please describe the behavior that you'd like to see.
-->

**Environment**:

  - CTFd Version/Commit: 22c1323
  - Operating System: Ubuntu 18.04
  - Web Browser and Version: n/a

**What happened?**

Running with docker-compose, fails to start due to bad type checking on the reverse proxy config var

**What did you expect to happen?**

Should have properly started

**How to reproduce your issue**

Set `REVERSE_PROXY` in CTFd/config.py to `True`

**Any associated stack traces or error logs**

```
ctfd_1   | Traceback (most recent call last):
ctfd_1   |   File "manage.py", line 9, in <module>
ctfd_1   |     app = create_app()
ctfd_1   |   File "/opt/CTFd/CTFd/__init__.py", line 180, in create_app
ctfd_1   |     if "," in reverse_proxy:
ctfd_1   | TypeError: argument of type 'bool' is not iterable
ctfd_1   | Traceback (most recent call last):
ctfd_1   |   File "manage.py", line 9, in <module>
ctfd_1   |     app = create_app()
ctfd_1   |   File "/opt/CTFd/CTFd/__init__.py", line 180, in create_app
ctfd_1   |     if "," in reverse_proxy:
ctfd_1   | TypeError: argument of type 'bool' is not iterable
ctfd_ctfd_1 exited with code 1
```

I have a patch for this ready to go and will make a pull request.



Discussion:

Resolving patch:
diff --git a/CTFd/__init__.py b/CTFd/__init__.py
--- 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:


Test patch:
diff --git a/tests/test_config.py b/tests/test_config.py
--- a/tests/test_config.py
+++ b/tests/test_config.py
@@ -32,6 +32,18 @@ class ReverseProxyConfig(TestingConfig):
         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"""