Skip to content

Commit 816054b

Browse files
authored
Fix internal server error when updating 3pid address with invalid email (#18125)
When updating 3pid for a user email from admin api and sending invalid email the server throws 500 internal server error. changed to 400 Bad request and returned the error message Signed-off-by: qashlan <ahmedelqashlan@gmail.com> Signed-off-by: Ahmed Qashlan <ahmedelqashlan@gmail.com>
1 parent aaffc35 commit 816054b

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

changelog.d/18125.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix a bug when updating a user 3pid with invalid returns 500 server error change to 400 with a message.

synapse/handlers/auth.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1579,7 +1579,10 @@ async def add_threepid(
15791579
# for the presence of an email address during password reset was
15801580
# case sensitive).
15811581
if medium == "email":
1582-
address = canonicalise_email(address)
1582+
try:
1583+
address = canonicalise_email(address)
1584+
except ValueError as e:
1585+
raise SynapseError(400, str(e))
15831586

15841587
await self.store.user_add_threepid(
15851588
user_id, medium, address, validated_at, self.hs.get_clock().time_msec()
@@ -1610,7 +1613,10 @@ async def delete_local_threepid(
16101613
"""
16111614
# 'Canonicalise' email addresses as per above
16121615
if medium == "email":
1613-
address = canonicalise_email(address)
1616+
try:
1617+
address = canonicalise_email(address)
1618+
except ValueError as e:
1619+
raise SynapseError(400, str(e))
16141620

16151621
await self.store.user_delete_threepid(user_id, medium, address)
16161622

0 commit comments

Comments
 (0)