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.
pull/7630/head
Brendan Abolivier 2020-06-03 16:55:02 +02:00 committed by GitHub
parent 11dc2b4698
commit c9507be989
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 9 deletions

1
changelog.d/7625.misc Normal file
View File

@ -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`.

View File

@ -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()