Skip to content

Commit

Permalink
Check if the localpart is reserved for guests earlier in the registra…
Browse files Browse the repository at this point in the history
…tion flow (matrix-org#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.
  • Loading branch information
babolivier authored and phil-flex committed Jun 16, 2020
1 parent 1d4abbf commit 3c8d814
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
1 change: 1 addition & 0 deletions changelog.d/7625.misc
Original file line number Diff line number Diff line change
@@ -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`.
18 changes: 9 additions & 9 deletions synapse/handlers/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,15 @@ def check_username(self, localpart, guest_access_token=None, assigned_user_id=No
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,
Expand Down Expand Up @@ -170,15 +179,6 @@ def register_user(

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

Expand Down

0 comments on commit 3c8d814

Please sign in to comment.