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

Only check 3pids not in use when registering #5187

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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/5187.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix register endpoint returning a previously registered account.
Copy link
Member

Choose a reason for hiding this comment

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

Could you expand this a bit? It seems to say that the bug was that the endpoint incorrectly returned a previously registered account, but I don't think that is the case.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah I don't know why I thought that was a sensible wording.

40 changes: 22 additions & 18 deletions synapse/rest/client/v2_alpha/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,13 +391,6 @@ def on_POST(self, request):
# the user-facing checks will probably already have happened in
# /register/email/requestToken when we requested a 3pid, but that's not
# guaranteed.
#
# Also check that we're not trying to register a 3pid that's already
# been registered.
#
# This has probably happened in /register/email/requestToken as well,
# but if a user hits this endpoint twice then clicks on each link from
# the two activation emails, they would register the same 3pid twice.

if auth_result:
for login_type in [LoginType.EMAIL_IDENTITY, LoginType.MSISDN]:
Expand All @@ -413,17 +406,6 @@ def on_POST(self, request):
Codes.THREEPID_DENIED,
)

existingUid = yield self.store.get_user_id_by_threepid(
medium, address,
)

if existingUid is not None:
raise SynapseError(
400,
"%s is already in use" % medium,
Codes.THREEPID_IN_USE,
)

if registered_user_id is not None:
logger.info(
"Already registered user ID %r for this session",
Expand All @@ -446,6 +428,28 @@ def on_POST(self, request):
if auth_result:
threepid = auth_result.get(LoginType.EMAIL_IDENTITY)

# Also check that we're not trying to register a 3pid that's already
# been registered.
#
# This has probably happened in /register/email/requestToken as well,
# but if a user hits this endpoint twice then clicks on each link from
# the two activation emails, they would register the same 3pid twice.
for login_type in [LoginType.EMAIL_IDENTITY, LoginType.MSISDN]:
if login_type in auth_result:
medium = auth_result[login_type]['medium']
address = auth_result[login_type]['address']

existingUid = yield self.store.get_user_id_by_threepid(
medium, address,
)

if existingUid is not None:
raise SynapseError(
400,
"%s is already in use" % medium,
Codes.THREEPID_IN_USE,
)

(registered_user_id, _) = yield self.registration_handler.register(
localpart=desired_username,
password=new_password,
Expand Down