Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

subdomains: Fix realm=None case for is_static_or_current_realm_url.

Anders Kaseorgeb9957aa35a2
diff --git a/zerver/lib/subdomains.py b/zerver/lib/subdomains.py
index 6cab4a5d0fe..852c9b4fbcb 100644
--- a/zerver/lib/subdomains.py
+++ b/zerver/lib/subdomains.py
@@ -1,5 +1,6 @@
import re
import urllib
+from typing import Optional
from django.conf import settings
from django.http import HttpRequest
@@ -55,7 +56,7 @@ def is_root_domain_available() -> bool:
return not Realm.objects.filter(string_id=Realm.SUBDOMAIN_FOR_ROOT_DOMAIN).exists()
-def is_static_or_current_realm_url(url: str, realm: Realm) -> bool:
+def is_static_or_current_realm_url(url: str, realm: Optional[Realm]) -> bool:
split_url = urllib.parse.urlsplit(url)
split_static_url = urllib.parse.urlsplit(settings.STATIC_URL)
@@ -67,7 +68,11 @@ def is_static_or_current_realm_url(url: str, realm: Realm) -> bool:
# HTTPS access to this Zulip organization's domain; our existing
# HTTPS protects this request, and there's no privacy benefit to
# using camo in front of the Zulip server itself.
- if split_url.netloc == realm.host and f"{split_url.scheme}://" == settings.EXTERNAL_URI_SCHEME:
+ if (
+ realm is not None
+ and split_url.netloc == realm.host
+ and f"{split_url.scheme}://" == settings.EXTERNAL_URI_SCHEME
+ ):
return True
# Relative URLs will be processed by the browser the same way as the above.