Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
nginx: Also error on serving over HTTP without proxy headers.
Alex Vandiverdadc072cb5ce
diff --git a/puppet/zulip/templates/nginx/trusted-proto.template.erb b/puppet/zulip/templates/nginx/trusted-proto.template.erbindex 87b27d7f38f..f0f80af0e64 100644--- a/puppet/zulip/templates/nginx/trusted-proto.template.erb+++ b/puppet/zulip/templates/nginx/trusted-proto.template.erb@@ -3,9 +3,10 @@map $remote_addr $trusted_x_forwarded_proto {default $scheme;}-map $http_x_forwarded_for $x_proxy_misconfiguration {+map "$scheme:$http_x_forwarded_for" $x_proxy_misconfiguration {+ "~^https?:." "No proxies configured in Zulip, but reverse proxy headers were detected from $remote_addr; Zulip must be configured with the IP addresses of reverse proxies to trust. See https://zulip.readthedocs.io/en/latest/production/reverse-proxies.html";+ "~^http:$" "Request came in over HTTP, with no proxy headers; if HTTPS is disabled in Zulip, it must be behind a proxy which does TLS termination. See https://zulip.readthedocs.io/en/latest/production/reverse-proxies.html";default "";- "~." "No proxies configured in Zulip, but proxy headers detected from proxy at $remote_addr; see https://zulip.readthedocs.io/en/latest/production/reverse-proxies.html";}<% else %># Check if the request's original `REMOTE_ADDR` header was from adiff --git a/zerver/middleware.py b/zerver/middleware.pyindex 204cec65012..7d35b3922dc 100644--- a/zerver/middleware.py+++ b/zerver/middleware.py@@ -653,12 +653,13 @@ class DetectProxyMisconfiguration(MiddlewareMixin):) -> None:proxy_state_header = request.headers.get("X-Proxy-Misconfiguration", "")# Our nginx configuration sets this header if:- # - there is an X-Forwarded-For set but no proxies configured in Zulip- # - proxies are configured but the request did not come from them- # - proxies are configured and the request came through them,- # but there was no X-Forwarded-Proto header+ # 1. the request came in over HTTP with no proxy headers set+ # 2. there is an X-Forwarded-For set but no proxies configured in Zulip+ # 3. proxies are configured but the request did not come from them+ # 4. proxies are configured and the request came through them,+ # but there was no X-Forwarded-Proto header#- # Note that the first two may be false-positives. We only+ # Note that (2) and (3) may be false-positives. We only# display the error if the request also came in over HTTP (and# a trusted proxy didn't say they get it over HTTPS), which# should be impossible because Zulip only supports external