diff --git a/changelog.d/18125.bugfix b/changelog.d/18125.bugfix new file mode 100644 index 00000000000..0e6aa704fff --- /dev/null +++ b/changelog.d/18125.bugfix @@ -0,0 +1 @@ +Fix a bug when updating a user 3pid with invalid returns 500 server error change to 400 with a message. \ No newline at end of file diff --git a/synapse/handlers/auth.py b/synapse/handlers/auth.py index 1f4264ad7e7..e96922c08d1 100644 --- a/synapse/handlers/auth.py +++ b/synapse/handlers/auth.py @@ -1579,7 +1579,10 @@ async def add_threepid( # for the presence of an email address during password reset was # case sensitive). if medium == "email": - address = canonicalise_email(address) + try: + address = canonicalise_email(address) + except ValueError as e: + raise SynapseError(400, str(e)) await self.store.user_add_threepid( user_id, medium, address, validated_at, self.hs.get_clock().time_msec() @@ -1610,7 +1613,10 @@ async def delete_local_threepid( """ # 'Canonicalise' email addresses as per above if medium == "email": - address = canonicalise_email(address) + try: + address = canonicalise_email(address) + except ValueError as e: + raise SynapseError(400, str(e)) await self.store.user_delete_threepid(user_id, medium, address)