Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
middleware: Redirect non-canonical realm domain names.
Alex Vandiver24c3e25f8625
diff --git a/zerver/middleware.py b/zerver/middleware.pyindex 4990a98d932..813e166a807 100644--- a/zerver/middleware.py+++ b/zerver/middleware.py@@ -4,7 +4,7 @@ import tempfileimport timeimport tracebackfrom typing import Any, AnyStr, Callable, Dict, Iterable, List, MutableMapping, Optional, Tuple-from urllib.parse import urlencode+from urllib.parse import urlencode, urljoinfrom django.conf import settingsfrom django.conf.urls.i18n import is_language_prefix_patterns_used@@ -579,6 +579,14 @@ class HostDomainMiddleware(MiddlewareMixin):return render(request, "zerver/invalid_realm.html", status=404)+ # Check that we're not using the non-canonical form of a REALM_HOSTS subdomain+ if subdomain in settings.REALM_HOSTS:+ host = request.get_host().lower()+ formal_host = request_notes.realm.host+ if host != formal_host and not host.startswith(formal_host + ":"):+ return HttpResponseRedirect(+ urljoin(request_notes.realm.uri, request.get_full_path())+ )return None