This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix inconsistent handling of upper and lower cases of email addresses. (
- Loading branch information
Showing
8 changed files
with
279 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Fix inconsistent handling of upper and lower case in email addresses when used as identifiers for login, etc. Contributed by @dklimpel. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,7 +30,7 @@ | |
from synapse.push.mailer import Mailer, load_jinja2_templates | ||
from synapse.util.msisdn import phone_number_to_msisdn | ||
from synapse.util.stringutils import assert_valid_client_secret, random_string | ||
from synapse.util.threepids import check_3pid_allowed | ||
from synapse.util.threepids import canonicalise_email, check_3pid_allowed | ||
|
||
from ._base import client_patterns, interactive_auth_handler | ||
|
||
|
@@ -83,7 +83,15 @@ async def on_POST(self, request): | |
client_secret = body["client_secret"] | ||
assert_valid_client_secret(client_secret) | ||
|
||
email = body["email"] | ||
# Canonicalise the email address. The addresses are all stored canonicalised | ||
# in the database. This allows the user to reset his password without having to | ||
# know the exact spelling (eg. upper and lower case) of address in the database. | ||
# Stored in the database "[email protected]" | ||
# User requests with "[email protected]" would raise a Not Found error | ||
try: | ||
email = canonicalise_email(body["email"]) | ||
except ValueError as e: | ||
raise SynapseError(400, str(e)) | ||
send_attempt = body["send_attempt"] | ||
next_link = body.get("next_link") # Optional param | ||
|
||
|
@@ -94,6 +102,10 @@ async def on_POST(self, request): | |
Codes.THREEPID_DENIED, | ||
) | ||
|
||
# The email will be sent to the stored address. | ||
# This avoids a potential account hijack by requesting a password reset to | ||
# an email address which is controlled by the attacker but which, after | ||
# canonicalisation, matches the one in our database. | ||
existing_user_id = await self.hs.get_datastore().get_user_id_by_threepid( | ||
"email", email | ||
) | ||
|
@@ -274,10 +286,13 @@ async def on_POST(self, request): | |
if "medium" not in threepid or "address" not in threepid: | ||
raise SynapseError(500, "Malformed threepid") | ||
if threepid["medium"] == "email": | ||
# For emails, transform the address to lowercase. | ||
# We store all email addreses as lowercase in the DB. | ||
# For emails, canonicalise the address. | ||
# We store all email addresses canonicalised in the DB. | ||
# (See add_threepid in synapse/handlers/auth.py) | ||
threepid["address"] = threepid["address"].lower() | ||
try: | ||
threepid["address"] = canonicalise_email(threepid["address"]) | ||
except ValueError as e: | ||
raise SynapseError(400, str(e)) | ||
# if using email, we must know about the email they're authing with! | ||
threepid_user_id = await self.datastore.get_user_id_by_threepid( | ||
threepid["medium"], threepid["address"] | ||
|
@@ -392,7 +407,16 @@ async def on_POST(self, request): | |
client_secret = body["client_secret"] | ||
assert_valid_client_secret(client_secret) | ||
|
||
email = body["email"] | ||
# Canonicalise the email address. The addresses are all stored canonicalised | ||
# in the database. | ||
# This ensures that the validation email is sent to the canonicalised address | ||
# as it will later be entered into the database. | ||
# Otherwise the email will be sent to "[email protected]" and stored as | ||
# "[email protected]" in database. | ||
try: | ||
email = canonicalise_email(body["email"]) | ||
except ValueError as e: | ||
raise SynapseError(400, str(e)) | ||
send_attempt = body["send_attempt"] | ||
next_link = body.get("next_link") # Optional param | ||
|
||
|
@@ -403,9 +427,7 @@ async def on_POST(self, request): | |
Codes.THREEPID_DENIED, | ||
) | ||
|
||
existing_user_id = await self.store.get_user_id_by_threepid( | ||
"email", body["email"] | ||
) | ||
existing_user_id = await self.store.get_user_id_by_threepid("email", email) | ||
|
||
if existing_user_id is not None: | ||
if self.config.request_token_inhibit_3pid_errors: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.