Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Check if the localpart is reserved for guests earlier in the registration flow #7625

Merged
merged 3 commits into from
Jun 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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."
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be nice to send errcode M_INVALID_USERNAME, for the moment, the client receives M_UNKNOWN:

{"errcode":"M_UNKNOWN","error":"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