Unverified Commit 8a3c21bd authored by Maximilian Bosch's avatar Maximilian Bosch
Browse files

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': <XForwardedForRequest at 0x7f691bd5f730 method='GET' uri='/_matrix/media/r0/preview_url?url=<redacted>' clientproto='HTTP/1.1' site='8448'>
                                            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
parent 225886d8
Loading
Loading
Loading
Loading
+20 −1
Original line number Diff line number Diff line
@@ -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.