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.
pull/11558/head
Patrick Cloke 2021-12-10 07:17:28 -05:00 committed by GitHub
parent 3b8872299a
commit 9562f0c2f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 11 additions and 4 deletions

1
changelog.d/11547.bugfix Normal file
View File

@ -0,0 +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.

View File

@ -27,6 +27,7 @@ from synapse.push.pusher import PusherFactory
from synapse.replication.http.push import ReplicationRemovePusherRestServlet
from synapse.types import JsonDict, RoomStreamToken
from synapse.util.async_helpers import concurrently_execute
from synapse.util.threepids import canonicalise_email
if TYPE_CHECKING:
from synapse.server import HomeServer
@ -113,7 +114,9 @@ class PusherPool:
"""
if kind == "email":
email_owner = await self.store.get_user_id_by_threepid("email", pushkey)
email_owner = await self.store.get_user_id_by_threepid(
"email", canonicalise_email(pushkey)
)
if email_owner != user_id:
raise SynapseError(400, "Email not found", Codes.THREEPID_NOT_FOUND)

View File

@ -18,6 +18,7 @@ from synapse.metrics.background_process_metrics import wrap_as_background_proces
from synapse.storage._base import SQLBaseStore
from synapse.storage.database import DatabasePool, make_in_list_sql_clause
from synapse.util.caches.descriptors import cached
from synapse.util.threepids import canonicalise_email
if TYPE_CHECKING:
from synapse.server import HomeServer
@ -103,7 +104,7 @@ class MonthlyActiveUsersWorkerStore(SQLBaseStore):
: self.hs.config.server.max_mau_value
]:
user_id = await self.hs.get_datastore().get_user_id_by_threepid(
tp["medium"], tp["address"]
tp["medium"], canonicalise_email(tp["address"])
)
if user_id:
users.append(user_id)

View File

@ -856,7 +856,8 @@ class RegistrationWorkerStore(CacheInvalidationWorkerStore):
Args:
medium: threepid medium e.g. email
address: threepid address e.g. me@example.com
address: threepid address e.g. me@example.com. This must already be
in canonical form.
Returns:
The user ID or None if no user id/threepid mapping exists

View File

@ -1550,7 +1550,8 @@ class UserRestTestCase(unittest.HomeserverTestCase):
# Create user
body = {
"password": "abc123",
"threepids": [{"medium": "email", "address": "bob@bob.bob"}],
# Note that the given email is not in canonical form.
"threepids": [{"medium": "email", "address": "Bob@bob.bob"}],
}
channel = self.make_request(