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

Commit 9562f0c

Browse files
authored
Ensure emails are canonicalized before fetching associated user. (#11547)
This should fix pushers with an email in non-canonical form is used as the pushkey.
1 parent 3b88722 commit 9562f0c

File tree

5 files changed

+11
-4
lines changed

5 files changed

+11
-4
lines changed

changelog.d/11547.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix a bug introduced in Synapse 1.17.0 where a pusher created for an email with capital letters would fail to be created.

synapse/push/pusherpool.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
from synapse.replication.http.push import ReplicationRemovePusherRestServlet
2828
from synapse.types import JsonDict, RoomStreamToken
2929
from synapse.util.async_helpers import concurrently_execute
30+
from synapse.util.threepids import canonicalise_email
3031

3132
if TYPE_CHECKING:
3233
from synapse.server import HomeServer
@@ -113,7 +114,9 @@ async def add_pusher(
113114
"""
114115

115116
if kind == "email":
116-
email_owner = await self.store.get_user_id_by_threepid("email", pushkey)
117+
email_owner = await self.store.get_user_id_by_threepid(
118+
"email", canonicalise_email(pushkey)
119+
)
117120
if email_owner != user_id:
118121
raise SynapseError(400, "Email not found", Codes.THREEPID_NOT_FOUND)
119122

synapse/storage/databases/main/monthly_active_users.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from synapse.storage._base import SQLBaseStore
1919
from synapse.storage.database import DatabasePool, make_in_list_sql_clause
2020
from synapse.util.caches.descriptors import cached
21+
from synapse.util.threepids import canonicalise_email
2122

2223
if TYPE_CHECKING:
2324
from synapse.server import HomeServer
@@ -103,7 +104,7 @@ async def get_registered_reserved_users(self) -> List[str]:
103104
: self.hs.config.server.max_mau_value
104105
]:
105106
user_id = await self.hs.get_datastore().get_user_id_by_threepid(
106-
tp["medium"], tp["address"]
107+
tp["medium"], canonicalise_email(tp["address"])
107108
)
108109
if user_id:
109110
users.append(user_id)

synapse/storage/databases/main/registration.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -856,7 +856,8 @@ async def get_user_id_by_threepid(self, medium: str, address: str) -> Optional[s
856856
857857
Args:
858858
medium: threepid medium e.g. email
859-
address: threepid address e.g. [email protected]
859+
address: threepid address e.g. [email protected]. This must already be
860+
in canonical form.
860861
861862
Returns:
862863
The user ID or None if no user id/threepid mapping exists

tests/rest/admin/test_user.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1550,7 +1550,8 @@ def test_create_user_email_notif_for_new_users(self):
15501550
# Create user
15511551
body = {
15521552
"password": "abc123",
1553-
"threepids": [{"medium": "email", "address": "[email protected]"}],
1553+
# Note that the given email is not in canonical form.
1554+
"threepids": [{"medium": "email", "address": "[email protected]"}],
15541555
}
15551556

15561557
channel = self.make_request(

0 commit comments

Comments
 (0)