summary refs log tree commit diff
diff options
context:
space:
mode:
authorBrendan Abolivier <babolivier@matrix.org>2020-06-03 16:55:02 +0200
committerGitHub <noreply@github.com>2020-06-03 16:55:02 +0200
commitc9507be9895878367184afc513dac85fd7ff29e9 (patch)
tree8b82e816dec694c63a2b38005d06e5a67538898a
parentFix exceptions when fetching events from a down host. (#7622) (diff)
downloadsynapse-c9507be9895878367184afc513dac85fd7ff29e9.tar.xz
Check if the localpart is reserved for guests earlier in the registration flow (#7625)
This is so the user is warned about the username not being valid as soon as possible, rather than only once they've finished UIA.
-rw-r--r--changelog.d/7625.misc1
-rw-r--r--synapse/handlers/register.py18
2 files changed, 10 insertions, 9 deletions
diff --git a/changelog.d/7625.misc b/changelog.d/7625.misc
new file mode 100644
index 0000000000..4c61d8d99f
--- /dev/null
+++ b/changelog.d/7625.misc
@@ -0,0 +1 @@
+Check if the localpart of a Matrix ID is reserved for guest users earlier in the registration flow, as well as when responding to requests to `/register/available`.
diff --git a/synapse/handlers/register.py b/synapse/handlers/register.py
index a6178e74a1..55a03e53ea 100644
--- a/synapse/handlers/register.py
+++ b/synapse/handlers/register.py
@@ -128,6 +128,15 @@ class RegistrationHandler(BaseHandler):
                     errcode=Codes.FORBIDDEN,
                 )
 
+        if guest_access_token is None:
+            try:
+                int(localpart)
+                raise SynapseError(
+                    400, "Numeric user IDs are reserved for guest users."
+                )
+            except ValueError:
+                pass
+
     @defer.inlineCallbacks
     def register_user(
         self,
@@ -170,15 +179,6 @@ class RegistrationHandler(BaseHandler):
 
             was_guest = guest_access_token is not None
 
-            if not was_guest:
-                try:
-                    int(localpart)
-                    raise SynapseError(
-                        400, "Numeric user IDs are reserved for guest users."
-                    )
-                except ValueError:
-                    pass
-
             user = UserID(localpart, self.hs.hostname)
             user_id = user.to_string()