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

Commit e40d88c

Browse files
authored
Backout changes for automatically calculating the public baseurl. (#9313)
This breaks some people's configurations (if their Client-Server API is not accessed via port 443).
1 parent afa18f1 commit e40d88c

File tree

16 files changed

+97
-41
lines changed

16 files changed

+97
-41
lines changed

changelog.d/9313.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Do not automatically calculate `public_baseurl` since it can be wrong in some situations.

docs/sample_config.yaml

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,6 @@ pid_file: DATADIR/homeserver.pid
7474
# Otherwise, it should be the URL to reach Synapse's client HTTP listener (see
7575
# 'listeners' below).
7676
#
77-
# If this is left unset, it defaults to 'https://<server_name>/'. (Note that
78-
# that will not work unless you configure Synapse or a reverse-proxy to listen
79-
# on port 443.)
80-
#
8177
#public_baseurl: https://example.com/
8278

8379
# Set the soft limit on the number of file descriptors synapse can use
@@ -1169,9 +1165,8 @@ account_validity:
11691165
# send an email to the account's email address with a renewal link. By
11701166
# default, no such emails are sent.
11711167
#
1172-
# If you enable this setting, you will also need to fill out the 'email'
1173-
# configuration section. You should also check that 'public_baseurl' is set
1174-
# correctly.
1168+
# If you enable this setting, you will also need to fill out the 'email' and
1169+
# 'public_baseurl' configuration sections.
11751170
#
11761171
#renew_at: 1w
11771172

@@ -1262,7 +1257,8 @@ account_validity:
12621257
# The identity server which we suggest that clients should use when users log
12631258
# in on this server.
12641259
#
1265-
# (By default, no suggestion is made, so it is left up to the client.)
1260+
# (By default, no suggestion is made, so it is left up to the client.
1261+
# This setting is ignored unless public_baseurl is also set.)
12661262
#
12671263
#default_identity_server: https://matrix.org
12681264

@@ -1287,6 +1283,8 @@ account_validity:
12871283
# by the Matrix Identity Service API specification:
12881284
# https://matrix.org/docs/spec/identity_service/latest
12891285
#
1286+
# If a delegate is specified, the config option public_baseurl must also be filled out.
1287+
#
12901288
account_threepid_delegates:
12911289
#email: https://example.com # Delegate email sending to example.com
12921290
#msisdn: http://localhost:8090 # Delegate SMS sending to this local process
@@ -1938,9 +1936,9 @@ sso:
19381936
# phishing attacks from evil.site. To avoid this, include a slash after the
19391937
# hostname: "https://my.client/".
19401938
#
1941-
# The login fallback page (used by clients that don't natively support the
1942-
# required login flows) is automatically whitelisted in addition to any URLs
1943-
# in this list.
1939+
# If public_baseurl is set, then the login fallback page (used by clients
1940+
# that don't natively support the required login flows) is whitelisted in
1941+
# addition to any URLs in this list.
19441942
#
19451943
# By default, this list is empty.
19461944
#

synapse/api/urls.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ def __init__(self, hs_config):
4242
"""
4343
if hs_config.form_secret is None:
4444
raise ConfigError("form_secret not set in config")
45+
if hs_config.public_baseurl is None:
46+
raise ConfigError("public_baseurl not set in config")
4547

4648
self._hmac_secret = hs_config.form_secret.encode("utf-8")
4749
self._public_baseurl = hs_config.public_baseurl

synapse/config/cas.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16-
from ._base import Config
16+
from ._base import Config, ConfigError
1717

1818

1919
class CasConfig(Config):
@@ -30,13 +30,15 @@ def read_config(self, config, **kwargs):
3030

3131
if self.cas_enabled:
3232
self.cas_server_url = cas_config["server_url"]
33-
public_base_url = cas_config.get("service_url") or self.public_baseurl
34-
if public_base_url[-1] != "/":
35-
public_base_url += "/"
33+
34+
# The public baseurl is required because it is used by the redirect
35+
# template.
36+
public_baseurl = self.public_baseurl
37+
if not public_baseurl:
38+
raise ConfigError("cas_config requires a public_baseurl to be set")
39+
3640
# TODO Update this to a _synapse URL.
37-
self.cas_service_url = (
38-
public_base_url + "_matrix/client/r0/login/cas/ticket"
39-
)
41+
self.cas_service_url = public_baseurl + "_matrix/client/r0/login/cas/ticket"
4042
self.cas_displayname_attribute = cas_config.get("displayname_attribute")
4143
self.cas_required_attributes = cas_config.get("required_attributes") or {}
4244
else:

synapse/config/emailconfig.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,11 @@ def read_config(self, config, **kwargs):
166166
if not self.email_notif_from:
167167
missing.append("email.notif_from")
168168

169+
# public_baseurl is required to build password reset and validation links that
170+
# will be emailed to users
171+
if config.get("public_baseurl") is None:
172+
missing.append("public_baseurl")
173+
169174
if missing:
170175
raise ConfigError(
171176
MISSING_PASSWORD_RESET_CONFIG_ERROR % (", ".join(missing),)
@@ -264,6 +269,9 @@ def read_config(self, config, **kwargs):
264269
if not self.email_notif_from:
265270
missing.append("email.notif_from")
266271

272+
if config.get("public_baseurl") is None:
273+
missing.append("public_baseurl")
274+
267275
if missing:
268276
raise ConfigError(
269277
"email.enable_notifs is True but required keys are missing: %s"

synapse/config/oidc_config.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@ def read_config(self, config, **kwargs):
5353
"Multiple OIDC providers have the idp_id %r." % idp_id
5454
)
5555

56-
self.oidc_callback_url = self.public_baseurl + "_synapse/client/oidc/callback"
56+
public_baseurl = self.public_baseurl
57+
if public_baseurl is None:
58+
raise ConfigError("oidc_config requires a public_baseurl to be set")
59+
self.oidc_callback_url = public_baseurl + "_synapse/client/oidc/callback"
5760

5861
@property
5962
def oidc_enabled(self) -> bool:

synapse/config/registration.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ def __init__(self, config, synapse_config):
4949

5050
self.startup_job_max_delta = self.period * 10.0 / 100.0
5151

52+
if self.renew_by_email_enabled:
53+
if "public_baseurl" not in synapse_config:
54+
raise ConfigError("Can't send renewal emails without 'public_baseurl'")
55+
5256
template_dir = config.get("template_dir")
5357

5458
if not template_dir:
@@ -105,6 +109,13 @@ def read_config(self, config, **kwargs):
105109
account_threepid_delegates = config.get("account_threepid_delegates") or {}
106110
self.account_threepid_delegate_email = account_threepid_delegates.get("email")
107111
self.account_threepid_delegate_msisdn = account_threepid_delegates.get("msisdn")
112+
if self.account_threepid_delegate_msisdn and not self.public_baseurl:
113+
raise ConfigError(
114+
"The configuration option `public_baseurl` is required if "
115+
"`account_threepid_delegate.msisdn` is set, such that "
116+
"clients know where to submit validation tokens to. Please "
117+
"configure `public_baseurl`."
118+
)
108119

109120
self.default_identity_server = config.get("default_identity_server")
110121
self.allow_guest_access = config.get("allow_guest_access", False)
@@ -227,9 +238,8 @@ def generate_config_section(self, generate_secrets=False, **kwargs):
227238
# send an email to the account's email address with a renewal link. By
228239
# default, no such emails are sent.
229240
#
230-
# If you enable this setting, you will also need to fill out the 'email'
231-
# configuration section. You should also check that 'public_baseurl' is set
232-
# correctly.
241+
# If you enable this setting, you will also need to fill out the 'email' and
242+
# 'public_baseurl' configuration sections.
233243
#
234244
#renew_at: 1w
235245
@@ -320,7 +330,8 @@ def generate_config_section(self, generate_secrets=False, **kwargs):
320330
# The identity server which we suggest that clients should use when users log
321331
# in on this server.
322332
#
323-
# (By default, no suggestion is made, so it is left up to the client.)
333+
# (By default, no suggestion is made, so it is left up to the client.
334+
# This setting is ignored unless public_baseurl is also set.)
324335
#
325336
#default_identity_server: https://matrix.org
326337
@@ -345,6 +356,8 @@ def generate_config_section(self, generate_secrets=False, **kwargs):
345356
# by the Matrix Identity Service API specification:
346357
# https://matrix.org/docs/spec/identity_service/latest
347358
#
359+
# If a delegate is specified, the config option public_baseurl must also be filled out.
360+
#
348361
account_threepid_delegates:
349362
#email: https://example.com # Delegate email sending to example.com
350363
#msisdn: http://localhost:8090 # Delegate SMS sending to this local process

synapse/config/saml2_config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,8 @@ def _default_saml_config_dict(
189189
import saml2
190190

191191
public_baseurl = self.public_baseurl
192+
if public_baseurl is None:
193+
raise ConfigError("saml2_config requires a public_baseurl to be set")
192194

193195
if self.saml2_grandfathered_mxid_source_attribute:
194196
optional_attributes.add(self.saml2_grandfathered_mxid_source_attribute)

synapse/config/server.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,7 @@ def read_config(self, config, **kwargs):
161161
self.print_pidfile = config.get("print_pidfile")
162162
self.user_agent_suffix = config.get("user_agent_suffix")
163163
self.use_frozen_dicts = config.get("use_frozen_dicts", False)
164-
self.public_baseurl = config.get("public_baseurl") or "https://%s/" % (
165-
self.server_name,
166-
)
167-
if self.public_baseurl[-1] != "/":
168-
self.public_baseurl += "/"
164+
self.public_baseurl = config.get("public_baseurl")
169165

170166
# Whether to enable user presence.
171167
self.use_presence = config.get("use_presence", True)
@@ -321,6 +317,9 @@ def read_config(self, config, **kwargs):
321317
# Always blacklist 0.0.0.0, ::
322318
self.federation_ip_range_blacklist.update(["0.0.0.0", "::"])
323319

320+
if self.public_baseurl is not None:
321+
if self.public_baseurl[-1] != "/":
322+
self.public_baseurl += "/"
324323
self.start_pushers = config.get("start_pushers", True)
325324

326325
# (undocumented) option for torturing the worker-mode replication a bit,
@@ -748,10 +747,6 @@ def generate_config_section(
748747
# Otherwise, it should be the URL to reach Synapse's client HTTP listener (see
749748
# 'listeners' below).
750749
#
751-
# If this is left unset, it defaults to 'https://<server_name>/'. (Note that
752-
# that will not work unless you configure Synapse or a reverse-proxy to listen
753-
# on port 443.)
754-
#
755750
#public_baseurl: https://example.com/
756751
757752
# Set the soft limit on the number of file descriptors synapse can use

synapse/config/sso.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,11 @@ def read_config(self, config, **kwargs):
6464
# gracefully to the client). This would make it pointless to ask the user for
6565
# confirmation, since the URL the confirmation page would be showing wouldn't be
6666
# the client's.
67-
login_fallback_url = self.public_baseurl + "_matrix/static/client/login"
68-
self.sso_client_whitelist.append(login_fallback_url)
67+
# public_baseurl is an optional setting, so we only add the fallback's URL to the
68+
# list if it's provided (because we can't figure out what that URL is otherwise).
69+
if self.public_baseurl:
70+
login_fallback_url = self.public_baseurl + "_matrix/static/client/login"
71+
self.sso_client_whitelist.append(login_fallback_url)
6972

7073
def generate_config_section(self, **kwargs):
7174
return """\
@@ -83,9 +86,9 @@ def generate_config_section(self, **kwargs):
8386
# phishing attacks from evil.site. To avoid this, include a slash after the
8487
# hostname: "https://my.client/".
8588
#
86-
# The login fallback page (used by clients that don't natively support the
87-
# required login flows) is automatically whitelisted in addition to any URLs
88-
# in this list.
89+
# If public_baseurl is set, then the login fallback page (used by clients
90+
# that don't natively support the required login flows) is whitelisted in
91+
# addition to any URLs in this list.
8992
#
9093
# By default, this list is empty.
9194
#

0 commit comments

Comments
 (0)