Review main Merged

96896[BUGFIX] Sanitize inline SVG nodes through public API

Oli Bartsch CR +2 V +2 Normal +27 −30 updated 10/20/26, 20:15

Commit message

SvgSanitizer::sanitizeNode() subclassed the enshrined sanitizer with
a sanitizeDocument(\DOMDocument) method of its own, which repeated
the cleaning steps of the library's sanitize() on an existing
document. enshrined/svg-sanitize 1.1.0 introduces a protected
sanitizeDocument($dirty) with a different signature, so declaring
the anonymous class now fails with a fatal error. Any inline SVG
passed through the default HTML sanitizer breaks as soon as 1.1.0
is installed.

The repeated steps were also out of date: 1.1.0 changed the order of
the cleaning steps and added checks the subclass did not run.

The node is now serialized, cleaned with the public sanitize()
method and imported back into the document. No library internals
are used anymore, and later improvements in the library apply
automatically. Whitespace-only text nodes are dropped, as the library
already does when it parses markup itself.

The minimum version of enshrined/svg-sanitize is raised to 1.1.1,
a security release that fixes a regression of 1.1.0, where
sanitize() throws on input that ends inside an unclosed tag:
 - GHSA-f7cw-vfxq-7ph2

Requiring 1.1.1 also ensures the security fixes of 1.1.0:
 - GHSA-2v7c-jx29-jprp
 - GHSA-cgcm-4g72-hfgw
 - GHSA-hrwm-vcc9-hcm4
 - GHSA-94x8-pw3c-6qcq
 - GHSA-vjg7-f2wj-gqqh
 - GHSA-3vh3-jf65-656w
 - GHSA-q546-85r6-f39q

Executed commands:

  composer req enshrined/svg-sanitize:^1.1.1
  composer req -d typo3/sysext/core --no-update \
    enshrined/svg-sanitize:^1.1.1

Review

  • Code review CR +2 Done
    • Benjamin Franzke +2
  • Verified V +2 Done
    • Benjamin Franzke +2
    • core-ci +1 CI

Issues 1

Files 5

Review log 2026

Show 1 earlier messages
  1. Oli Bartsch uploaded patch set 1 10/20/26, 07:06

  1. core-ci voted on patch set 1 V +1 10/20/26, 07:15 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/111747

  2. Benjamin Franzke commented on patch set 1 10/20/26, 07:21

    Thanks for tackling this! FYI: `sanitizeDocument()` actually wasn't a copy, but didn't exist before. We added it to allow sanitizing existing documents in order to combine it with `typo3/html-sanitizer` without having to * write the SVG (that is embedded in HTML) to a string * parse it again as a svg-sanitzier document again * write it back to string * parse it again in order to reimport to the HTML document. Now, why I'm saying that: Can we actually rename our overwrite to something else that is less likely to be used by the upstream lib as well. e.g. `typo3SanitizeExistingDocument(…)`, instead of writing to string? I understand that this has the possibility that upstream goes to final at some point. We should have upstream our own addition (but olly and me missed it :\), but maybe we can try that this time.
  3. Oli Bartsch updated the commit message in patch set 2 V +1 10/20/26, 08:05

  4. Oli Bartsch commented on patch set 2 10/20/26, 08:09

    Reply

    Thanks. Right. A rename would fix the fatal, but not the actual problem. 1.1.0 changed the pipeline itself. It now cleans first, then removes duplicate ids, and only then resolves and removes unsafe <use> elements (to measure the graph on what the browser renders). It also added a root-namespace check and fails closed. Our overridden method would keep the 1.0 order and skip those steps, so inline SVG would be sanitized weaker than uploaded files. Matching 1.1.0 would need version-dependent calls into protected internals (removeDuplicateIds()/removeUnsafeUseElements() don't exist in 1.0), and 13.4/14.3 must support both. So I'd keep the public sanitize() for the fix and backports (the cost is one serialize plus one parse per inline SVG).
  5. core-ci voted on patch set 2 V +1 10/20/26, 08:16 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/111755

  6. Benjamin Franzke commented on patch set 2 CR +1 10/20/26, 09:05

    Reply

    Ack, I see, thanks.

    DefaultSanitizerBuilderTest.php:177

    nitpick: this could demonstrate the fact that the SVG can come nested in other HTML elements. Like a wrapping `<div>` or alike.
  7. Oli Bartsch uploaded patch set 3 CR +1 V +1 10/20/26, 09:15

  8. Oli Bartsch commented on patch set 3 10/20/26, 09:17

    DefaultSanitizerBuilderTest.php:177 Reply

    Yep, good idea.
  9. core-ci voted on patch set 3 V +1 10/20/26, 09:25 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/111774

  10. Benjamin Franzke voted on patch set 3 CR +1 V +1 10/20/26, 18:50

  11. Benjamin Franzke commented on patch set 3 10/20/26, 18:53

    Scheduled a nightly test on this change which should now be green: https://git.typo3.org/typo3/CI/cms/-/pipelines/111917 Let's see…
  12. Torben Hansen commented on patch set 3 10/20/26, 18:56

    Heads-up: enshrined/svg-sanitize 1.0.0 and 1.1.0 are vulnerable, 1.1.1 is the only fixed version. Once the advisory is in the DB, Composer will block these versions on update/require. We should bump the lock (and check the constraint allows 1.1.1) in all affected branches before that happens, to avoid issues like we had previously and had to release 13.4.36 and 14.3.7 to fix the issue.
  13. core-ci commented on patch set 3 10/20/26, 19:05 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/111917

  14. Benjamin Franzke commented on patch set 3 10/20/26, 19:07

    Reply

    sounds right, albeit for this case composer users would be allowed to upgrade, since we allow ^1.0, but it definitely makes sense to update the locked version for classic mode users.
  15. Oli Bartsch commented on patch set 3 10/20/26, 19:08

    Reply

    Sure, but they will get a fatal then.
  16. Oli Bartsch commented on patch set 3 10/20/26, 19:21

    Reply

    Nightly passed. Should we merge or wait for other reviews?
  17. Benjamin Franzke commented on patch set 3 10/20/26, 19:38

    Reply

    Well, I would have said "let's merge", but I think we should raise/pin to 1.1.1 as outlined by torben. Can you do that (sorry for the iterations)?

    Reply

    yes, you are right. so we need to pin/raise anyway.

    Reply

    Meanwhile I also try to upstream our sanitizeDocument addon in order to be able to remove the stringify/parse roundtrip later on: https://github.com/darylldoyle/svg-sanitizer/pull/130
  18. Benjamin Franzke commented on patch set 3 10/20/26, 19:48

    Reply

    nvm, i'll just do it
  19. Benjamin Franzke uploaded patch set 4 CR +1 V +1 10/20/26, 19:49

  20. Benjamin Franzke updated the commit message in patch set 5 10/20/26, 19:51

  21. Benjamin Franzke commented on patch set 5 10/20/26, 19:52

    Reply

    Done, will update cherry-picks as well.
  22. core-ci voted on patch set 4 V +1 10/20/26, 20:03 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/111932

  23. core-ci voted on patch set 5 V +1 10/20/26, 20:03 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/111933

  24. Benjamin Franzke voted on patch set 5 CR +2 V +2 10/20/26, 20:13

  25. Benjamin Franzke merged patch set 6 10/20/26, 20:15