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

Commit b7da598

Browse files
committed
Always whitelist the login fallback for SSO (#7153)
That fallback sets the redirect URL to itself (so it can process the login token then return gracefully to the client). This would make it pointless to ask the user for confirmation, since the URL the confirmation page would be showing wouldn't be the client's.
1 parent 84f7eae commit b7da598

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed

changelog.d/7153.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Always whitelist the login fallback in the SSO configuration if `public_baseurl` is set.

docs/sample_config.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1444,6 +1444,10 @@ sso:
14441444
# phishing attacks from evil.site. To avoid this, include a slash after the
14451445
# hostname: "https://my.client/".
14461446
#
1447+
# If public_baseurl is set, then the login fallback page (used by clients
1448+
# that don't natively support the required login flows) is whitelisted in
1449+
# addition to any URLs in this list.
1450+
#
14471451
# By default, this list is empty.
14481452
#
14491453
#client_whitelist:

synapse/config/sso.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,17 @@ def read_config(self, config, **kwargs):
3939

4040
self.sso_client_whitelist = sso_config.get("client_whitelist") or []
4141

42+
# Attempt to also whitelist the server's login fallback, since that fallback sets
43+
# the redirect URL to itself (so it can process the login token then return
44+
# gracefully to the client). This would make it pointless to ask the user for
45+
# confirmation, since the URL the confirmation page would be showing wouldn't be
46+
# the client's.
47+
# public_baseurl is an optional setting, so we only add the fallback's URL to the
48+
# list if it's provided (because we can't figure out what that URL is otherwise).
49+
if self.public_baseurl:
50+
login_fallback_url = self.public_baseurl + "_matrix/static/client/login"
51+
self.sso_client_whitelist.append(login_fallback_url)
52+
4253
def generate_config_section(self, **kwargs):
4354
return """\
4455
# Additional settings to use with single-sign on systems such as SAML2 and CAS.
@@ -54,6 +65,10 @@ def generate_config_section(self, **kwargs):
5465
# phishing attacks from evil.site. To avoid this, include a slash after the
5566
# hostname: "https://my.client/".
5667
#
68+
# If public_baseurl is set, then the login fallback page (used by clients
69+
# that don't natively support the required login flows) is whitelisted in
70+
# addition to any URLs in this list.
71+
#
5772
# By default, this list is empty.
5873
#
5974
#client_whitelist:

tests/rest/client/v1/test_login.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,14 @@ def test_cas_redirect_confirm(self):
350350
def test_cas_redirect_whitelisted(self):
351351
"""Tests that the SSO login flow serves a redirect to a whitelisted url
352352
"""
353-
redirect_url = "https://legit-site.com/"
353+
self._test_redirect("https://legit-site.com/")
354+
355+
@override_config({"public_baseurl": "https://example.com"})
356+
def test_cas_redirect_login_fallback(self):
357+
self._test_redirect("https://example.com/_matrix/static/client/login")
358+
359+
def _test_redirect(self, redirect_url):
360+
"""Tests that the SSO login flow serves a redirect for the given redirect URL."""
354361
cas_ticket_url = (
355362
"/_matrix/client/r0/login/cas/ticket?redirectUrl=%s&ticket=ticket"
356363
% (urllib.parse.quote(redirect_url))

0 commit comments

Comments
 (0)