summary refs log tree commit diff
path: root/synapse/server.py
diff options
context:
space:
mode:
authorSean Quah <8349537+squahtx@users.noreply.github.com>2022-09-08 15:54:36 +0100
committerGitHub <noreply@github.com>2022-09-08 15:54:36 +0100
commit8ef0c8ff14fcf613c5df1cfc30b38236de1695a7 (patch)
tree228041c6b7c3f40091af55fcd786bfdb971006cd /synapse/server.py
parentFix cache metrics not being updated when not using the legacy exposition modu... (diff)
downloadsynapse-8ef0c8ff14fcf613c5df1cfc30b38236de1695a7.tar.xz
Fix error in `is_mine_id` when encountering a malformed ID (#13746)
Previously, `is_mine_id` would raise an exception when passed an ID with
no colons. Return `False` instead.

Fixes #13040.

Signed-off-by: Sean Quah <seanq@matrix.org>
Diffstat (limited to 'synapse/server.py')
-rw-r--r--synapse/server.py12
1 files changed, 11 insertions, 1 deletions
diff --git a/synapse/server.py b/synapse/server.py
index 5a99c0b344..df3a1cb405 100644
--- a/synapse/server.py
+++ b/synapse/server.py
@@ -341,7 +341,17 @@ class HomeServer(metaclass=abc.ABCMeta):
         return domain_specific_string.domain == self.hostname
 
     def is_mine_id(self, string: str) -> bool:
-        return string.split(":", 1)[1] == self.hostname
+        """Determines whether a user ID or room alias originates from this homeserver.
+
+        Returns:
+            `True` if the hostname part of the user ID or room alias matches this
+            homeserver.
+            `False` otherwise, or if the user ID or room alias is malformed.
+        """
+        localpart_hostname = string.split(":", 1)
+        if len(localpart_hostname) < 2:
+            return False
+        return localpart_hostname[1] == self.hostname
 
     @cache_in_self
     def get_clock(self) -> Clock: