From 8a3c21bd8292aaee9a01110d333bba93c53a4250 Mon Sep 17 00:00:00 2001 From: Maximilian Bosch Date: Thu, 14 Sep 2023 17:31:25 +0200 Subject: [PATCH] nixos/matrix-synapse: fix type of `settings.url_preview_url_blacklist` Actually, it's supposed to be `listOf (attrsOf str)` because each list-item can match against multiple properties from `urlsplit`[1]. In fact, `listOf str` breaks URL previews at runtime: Sep 14 15:03:47 soost synapse[1100355]: synapse.http.server: [GET-116] Failed handle request via 'PreviewUrlResource': Traceback (most recent call last): [...] File "/nix/store/xk5yksbw09p6qwk0maq2cb2in3z6f4gn-matrix-synapse-1.91.2/lib/python3.10/site-packages/synapse/media/url_previewer.py", line 398, in _is_url_blocked for attrib, pattern in entry.items(): AttributeError: 'str' object has no attribute 'items' To make sure that people aren't confused when upgrading their configs, I decided to work with `types.coercedTo` to "pretend" accepting the old type signature, but then throwing an error explaining what to do (and rejecting the broken configuration). [1] https://docs.python.org/3/library/urllib.parse.html#urllib.parse.urlsplit --- nixos/modules/services/matrix/synapse.nix | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/nixos/modules/services/matrix/synapse.nix b/nixos/modules/services/matrix/synapse.nix index ef69a8adebb0..71f64d2fc4f8 100644 --- a/nixos/modules/services/matrix/synapse.nix +++ b/nixos/modules/services/matrix/synapse.nix @@ -630,8 +630,27 @@ in { }; url_preview_url_blacklist = mkOption { - type = types.listOf types.str; + # FIXME revert to just `listOf (attrsOf str)` after some time(tm). + type = types.listOf ( + types.coercedTo + types.str + (const (throw '' + Setting `config.services.matrix-synapse.settings.url_preview_url_blacklist` + to a list of strings has never worked. Due to a bug, this was the type accepted + by the module, but in practice it broke on runtime and as a result, no URL + preview worked anywhere if this was set. + + See https://matrix-org.github.io/synapse/latest/usage/configuration/config_documentation.html#url_preview_url_blacklist + on how to configure it properly. + '')) + (types.attrsOf types.str)); default = []; + example = literalExpression '' + [ + { scheme = "http"; } # no http previews + { netloc = "www.acme.com"; path = "/foo"; } # block http(s)://www.acme.com/foo + ] + ''; description = lib.mdDoc '' Optional list of URL matches that the URL preview spider is denied from accessing.