From 8b5aa10cacbd18d294fade28421ab49486f820cf Mon Sep 17 00:00:00 2001 From: Andrew Morgan Date: Tue, 19 Nov 2019 14:23:36 +0000 Subject: [PATCH 1/4] Remove assertion and provide a clear warning on startup for missing public_baseurl. --- synapse/config/emailconfig.py | 10 ++++++++++ synapse/handlers/identity.py | 2 -- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/synapse/config/emailconfig.py b/synapse/config/emailconfig.py index 43fad0bf8b27..930da0d79068 100644 --- a/synapse/config/emailconfig.py +++ b/synapse/config/emailconfig.py @@ -146,6 +146,8 @@ def read_config(self, config, **kwargs): if k not in email_config: missing.append("email." + k) + # public_baseurl is required to build password reset and validation links that + # will be emailed to users if config.get("public_baseurl") is None: missing.append("public_baseurl") @@ -238,6 +240,14 @@ def read_config(self, config, **kwargs): self.email_add_threepid_template_success_html_content = self.read_file( filepath, "email.add_threepid_template_success_html" ) + elif self.account_threepid_delegate_msisdn: + if not self.public_baseurl: + raise ConfigError( + "The configuration option `public_baseurl` is required if " + "`account_threepid_delegate.msisdn` is set, such that " + "clients know where to submit validation tokens to. Please " + "configure `public_baseurl`." + ) if self.email_enable_notifs: required = [ diff --git a/synapse/handlers/identity.py b/synapse/handlers/identity.py index 000fbf090f83..f936b29a750d 100644 --- a/synapse/handlers/identity.py +++ b/synapse/handlers/identity.py @@ -475,8 +475,6 @@ def requestMsisdnToken( except TimeoutError: raise SynapseError(500, "Timed out contacting identity server") - assert self.hs.config.public_baseurl - # we need to tell the client to send the token back to us, since it doesn't # otherwise know where to send it, so add submit_url response parameter # (see also MSC2078) From 3051adb7ed159a2ee6e5f2a893e03e20b9ba59a4 Mon Sep 17 00:00:00 2001 From: Andrew Morgan Date: Tue, 19 Nov 2019 15:01:09 +0000 Subject: [PATCH 2/4] Add changelog --- changelog.d/6379.misc | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/6379.misc diff --git a/changelog.d/6379.misc b/changelog.d/6379.misc new file mode 100644 index 000000000000..725c2e7d8744 --- /dev/null +++ b/changelog.d/6379.misc @@ -0,0 +1 @@ +Complain on startup instead of 500'ing during runtime when `public_baseurl` isn't set when necessary. \ No newline at end of file From ba8025dddd5fccdb06767cb97eb85cc138ac3371 Mon Sep 17 00:00:00 2001 From: Andrew Morgan Date: Tue, 19 Nov 2019 15:17:42 +0000 Subject: [PATCH 3/4] Add public_baseurl to 3pid test --- tests/rest/client/v2_alpha/test_register.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/rest/client/v2_alpha/test_register.py b/tests/rest/client/v2_alpha/test_register.py index dab87e5edff8..c0d0d2b44eb9 100644 --- a/tests/rest/client/v2_alpha/test_register.py +++ b/tests/rest/client/v2_alpha/test_register.py @@ -203,6 +203,7 @@ def test_advertised_flows(self): @unittest.override_config( { + "public_baseurl": "https://test_server", "enable_registration_captcha": True, "user_consent": { "version": "1", From f4df128a22ef15a2bc2b84ab712cb7770e7e98c1 Mon Sep 17 00:00:00 2001 From: Andrew Morgan Date: Mon, 25 Nov 2019 18:04:03 +0000 Subject: [PATCH 4/4] Address review comments --- synapse/config/emailconfig.py | 8 -------- synapse/config/registration.py | 7 +++++++ synapse/handlers/identity.py | 2 ++ 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/synapse/config/emailconfig.py b/synapse/config/emailconfig.py index 930da0d79068..ac1724045f04 100644 --- a/synapse/config/emailconfig.py +++ b/synapse/config/emailconfig.py @@ -240,14 +240,6 @@ def read_config(self, config, **kwargs): self.email_add_threepid_template_success_html_content = self.read_file( filepath, "email.add_threepid_template_success_html" ) - elif self.account_threepid_delegate_msisdn: - if not self.public_baseurl: - raise ConfigError( - "The configuration option `public_baseurl` is required if " - "`account_threepid_delegate.msisdn` is set, such that " - "clients know where to submit validation tokens to. Please " - "configure `public_baseurl`." - ) if self.email_enable_notifs: required = [ diff --git a/synapse/config/registration.py b/synapse/config/registration.py index 1f6dac69da00..ee9614c5f716 100644 --- a/synapse/config/registration.py +++ b/synapse/config/registration.py @@ -106,6 +106,13 @@ def read_config(self, config, **kwargs): account_threepid_delegates = config.get("account_threepid_delegates") or {} self.account_threepid_delegate_email = account_threepid_delegates.get("email") self.account_threepid_delegate_msisdn = account_threepid_delegates.get("msisdn") + if self.account_threepid_delegate_msisdn and not self.public_baseurl: + raise ConfigError( + "The configuration option `public_baseurl` is required if " + "`account_threepid_delegate.msisdn` is set, such that " + "clients know where to submit validation tokens to. Please " + "configure `public_baseurl`." + ) self.default_identity_server = config.get("default_identity_server") self.allow_guest_access = config.get("allow_guest_access", False) diff --git a/synapse/handlers/identity.py b/synapse/handlers/identity.py index f936b29a750d..000fbf090f83 100644 --- a/synapse/handlers/identity.py +++ b/synapse/handlers/identity.py @@ -475,6 +475,8 @@ def requestMsisdnToken( except TimeoutError: raise SynapseError(500, "Timed out contacting identity server") + assert self.hs.config.public_baseurl + # we need to tell the client to send the token back to us, since it doesn't # otherwise know where to send it, so add submit_url response parameter # (see also MSC2078)