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

Commit b0db928

Browse files
authored
Extend web_client_location to handle absolute URLs (#7006)
Log warning when filesystem path is used. Signed-off-by: Martin Milata <martin@martinmilata.cz>
1 parent 334bfdb commit b0db928

4 files changed

Lines changed: 30 additions & 9 deletions

File tree

changelog.d/7006.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Extend the `web_client_location` option to accept an absolute URL to use as a redirect. Adds a warning when running the web client on the same hostname as homeserver. Contributed by Martin Milata.

docs/sample_config.yaml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,15 @@ server_name: "SERVERNAME"
3333
#
3434
pid_file: DATADIR/homeserver.pid
3535

36-
# The path to the web client which will be served at /_matrix/client/
37-
# if 'webclient' is configured under the 'listeners' configuration.
36+
# The absolute URL to the web client which /_matrix/client will redirect
37+
# to if 'webclient' is configured under the 'listeners' configuration.
3838
#
39-
#web_client_location: "/path/to/web/root"
39+
# This option can be also set to the filesystem path to the web client
40+
# which will be served at /_matrix/client/ if 'webclient' is configured
41+
# under the 'listeners' configuration, however this is a security risk:
42+
# https://github.com/matrix-org/synapse#security-note
43+
#
44+
#web_client_location: https://riot.example.com/
4045

4146
# The public-facing base URL that clients use to access this HS
4247
# (not including _matrix/...). This is the same URL a user would

synapse/app/homeserver.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,16 +241,26 @@ def _configure_named_resource(self, name, compress=False):
241241
resources[SERVER_KEY_V2_PREFIX] = KeyApiV2Resource(self)
242242

243243
if name == "webclient":
244-
webclient_path = self.get_config().web_client_location
244+
webclient_loc = self.get_config().web_client_location
245245

246-
if webclient_path is None:
246+
if webclient_loc is None:
247247
logger.warning(
248248
"Not enabling webclient resource, as web_client_location is unset."
249249
)
250+
elif webclient_loc.startswith("http://") or webclient_loc.startswith(
251+
"https://"
252+
):
253+
resources[WEB_CLIENT_PREFIX] = RootRedirect(webclient_loc)
250254
else:
255+
logger.warning(
256+
"Running webclient on the same domain is not recommended: "
257+
"https://github.com/matrix-org/synapse#security-note - "
258+
"after you move webclient to different host you can set "
259+
"web_client_location to its full URL to enable redirection."
260+
)
251261
# GZip is disabled here due to
252262
# https://twistedmatrix.com/trac/ticket/7678
253-
resources[WEB_CLIENT_PREFIX] = File(webclient_path)
263+
resources[WEB_CLIENT_PREFIX] = File(webclient_loc)
254264

255265
if name == "metrics" and self.get_config().enable_metrics:
256266
resources[METRICS_PREFIX] = MetricsResource(RegistryProxy)

synapse/config/server.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -604,10 +604,15 @@ def generate_config_section(
604604
#
605605
pid_file: %(pid_file)s
606606
607-
# The path to the web client which will be served at /_matrix/client/
608-
# if 'webclient' is configured under the 'listeners' configuration.
607+
# The absolute URL to the web client which /_matrix/client will redirect
608+
# to if 'webclient' is configured under the 'listeners' configuration.
609609
#
610-
#web_client_location: "/path/to/web/root"
610+
# This option can be also set to the filesystem path to the web client
611+
# which will be served at /_matrix/client/ if 'webclient' is configured
612+
# under the 'listeners' configuration, however this is a security risk:
613+
# https://github.com/matrix-org/synapse#security-note
614+
#
615+
#web_client_location: https://riot.example.com/
611616
612617
# The public-facing base URL that clients use to access this HS
613618
# (not including _matrix/...). This is the same URL a user would

0 commit comments

Comments
 (0)