diff --git a/docs/configuration/config_yaml.rst b/docs/configuration/config_yaml.rst index 7d4107174..e31219da1 100644 --- a/docs/configuration/config_yaml.rst +++ b/docs/configuration/config_yaml.rst @@ -934,7 +934,7 @@ Use the following settings to configure the server: # Settings if OctoPrint is running behind a reverse proxy (haproxy, nginx, apache, ...). # These are necessary in order to make OctoPrint generate correct external URLs so - # that AJAX requests and download URLs work. + # that AJAX requests and download URLs work, and so that client IPs are read correctly. reverseProxy: # The request header from which to determine the URL prefix under which OctoPrint @@ -968,6 +968,14 @@ Use the following settings to configure the server: # (X-Forwarded-Host by default, see above) with forwarded requests. hostFallback: + # List of trusted downstream servers for which to ignore the IP address when trying to determine + # the connecting client's IP address. If you have OctoPrint behind more than one reverse proxy + # you should add their IPs here so that they won't be interpreted as the client's IP. One reverse + # proxy will be handled correctly by default. + trustedDownstream: + - 192.168.1.254 + - 192.168.23.42 + # Settings for file uploads to OctoPrint, such as maximum allowed file size and # header suffixes to use for streaming uploads. OctoPrint does some nifty things internally in # order to allow streaming of large file uploads to the application rather than just storing diff --git a/src/octoprint/server/__init__.py b/src/octoprint/server/__init__.py index fd81781ad..4c30a6e4c 100644 --- a/src/octoprint/server/__init__.py +++ b/src/octoprint/server/__init__.py @@ -617,7 +617,15 @@ class Server(object): self._stop_intermediary_server() # initialize and bind the server - self._server = util.tornado.CustomHTTPServer(self._tornado_app, max_body_sizes=max_body_sizes, default_max_body_size=self._settings.getInt(["server", "maxSize"])) + trusted_downstream = self._settings.get(["server", "reverseProxy", "trustedDownstream"]) + if not isinstance(trusted_downstream, list): + self._logger.warn("server.reverseProxy.trustedDownstream is not a list, skipping") + trusted_downstreams = [] + self._server = util.tornado.CustomHTTPServer(self._tornado_app, + max_body_sizes=max_body_sizes, + default_max_body_size=self._settings.getInt(["server", "maxSize"]), + xheaders=True, + trusted_downstream=trusted_downstream) self._server.listen(self._port, address=self._host) ### From now on it's ok to launch subprocesses again diff --git a/src/octoprint/settings.py b/src/octoprint/settings.py index 928ef6fda..7a3f4be21 100644 --- a/src/octoprint/settings.py +++ b/src/octoprint/settings.py @@ -164,7 +164,8 @@ default_settings = { "schemeFallback": None, "hostFallback": None, "serverFallback": None, - "portFallback": None + "portFallback": None, + "trustedDownstream": [] }, "uploads": { "maxSize": 1 * 1024 * 1024 * 1024, # 1GB