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

Commit 1c6b875

Browse files
Only assert valid next_link params when provided (#8417)
Broken in #8275 and has yet to be put in a release. Fixes #8418. `next_link` is an optional parameter. However, we were checking whether the `next_link` param was valid, even if it wasn't provided. In that case, `next_link` was `None`, which would clearly not be a valid URL. This would prevent password reset and other operations if `next_link` was not provided, and the `next_link_domain_whitelist` config option was set.
1 parent 866c84d commit 1c6b875

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

changelog.d/8417.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add a config option to specify a whitelist of domains that a user can be redirected to after validating their email or phone number.

synapse/rest/client/v2_alpha/account.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,9 @@ async def on_POST(self, request):
103103
Codes.THREEPID_DENIED,
104104
)
105105

106-
# Raise if the provided next_link value isn't valid
107-
assert_valid_next_link(self.hs, next_link)
106+
if next_link:
107+
# Raise if the provided next_link value isn't valid
108+
assert_valid_next_link(self.hs, next_link)
108109

109110
# The email will be sent to the stored address.
110111
# This avoids a potential account hijack by requesting a password reset to
@@ -379,8 +380,9 @@ async def on_POST(self, request):
379380
Codes.THREEPID_DENIED,
380381
)
381382

382-
# Raise if the provided next_link value isn't valid
383-
assert_valid_next_link(self.hs, next_link)
383+
if next_link:
384+
# Raise if the provided next_link value isn't valid
385+
assert_valid_next_link(self.hs, next_link)
384386

385387
existing_user_id = await self.store.get_user_id_by_threepid("email", email)
386388

@@ -453,8 +455,9 @@ async def on_POST(self, request):
453455
Codes.THREEPID_DENIED,
454456
)
455457

456-
# Raise if the provided next_link value isn't valid
457-
assert_valid_next_link(self.hs, next_link)
458+
if next_link:
459+
# Raise if the provided next_link value isn't valid
460+
assert_valid_next_link(self.hs, next_link)
458461

459462
existing_user_id = await self.store.get_user_id_by_threepid("msisdn", msisdn)
460463

tests/rest/client/v2_alpha/test_account.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,12 @@ def test_next_link_file_uri(self):
732732
@override_config({"next_link_domain_whitelist": ["example.com", "example.org"]})
733733
def test_next_link_domain_whitelist(self):
734734
"""Tests next_link parameters must fit the whitelist if provided"""
735+
736+
# Ensure not providing a next_link parameter still works
737+
self._request_token(
738+
"something@example.com", "some_secret", next_link=None, expect_code=200,
739+
)
740+
735741
self._request_token(
736742
"something@example.com",
737743
"some_secret",

0 commit comments

Comments
 (0)