93664[BUGFIX] Sanitize and size SVG through a single SvgDocument entrypoint
Commit message
Review
-
Code review CR -1
- Garvin Hicking -1
-
Verified V +1
- Garvin Hicking +1
- core-ci +1 CI
Issues 1
Files 13
- typo3/sysext/backend/Classes/ViewHelpers/LoginLogoViewHelper.php+9 −30
- typo3/sysext/core/Classes/Imaging/Exception/InvalidSvgException.phpnew+25 −0
- typo3/sysext/core/Classes/Imaging/IconProvider/AbstractSvgIconProvider.php+5 −7
- typo3/sysext/core/Classes/Imaging/Svg/SvgDocument.phpnew+294 −0
- typo3/sysext/core/Classes/Imaging/SvgManipulation.phpdeleted+0 −196
- typo3/sysext/core/Classes/Resource/Processing/SvgImageProcessor.php+12 −7
- typo3/sysext/core/Classes/Resource/Security/SvgSanitizer.php+12 −1
- typo3/sysext/core/Classes/Type/File/ImageInfo.php+6 −22
- typo3/sysext/core/Tests/Functional/Imaging/IconProvider/SvgIconProviderTest.php+2 −2
- typo3/sysext/core/Tests/Functional/Imaging/IconProvider/SvgSpriteIconProviderTest.php+2 −2
- typo3/sysext/core/Tests/Functional/Resource/Security/SvgSanitizerTest.php+39 −0
- typo3/sysext/core/Tests/Unit/Imaging/Svg/SvgDocumentTest.phpnew+346 −0
- typo3/sysext/frontend/Classes/ContentObject/ScalableVectorGraphicsContentObject.php+13 −11
Review log 2534
Show 59 earlier messages
-
Benjamin Kott uploaded patch set 1 04/14/26, 11:00
-
Benjamin Kott updated the commit message in patch set 2 04/14/26, 11:04
-
core-ci voted on patch set 2 V -1 04/14/26, 11:28 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/100147
-
core-ci voted on patch set 1 V -1 04/14/26, 11:37 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/100146
-
Benjamin Kott uploaded patch set 3
V -104/14/26, 13:10 -
core-ci voted on patch set 3 V -1 04/14/26, 13:32 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/100161
-
Christian Kuhn voted on patch set 3 CR -2 04/14/26, 13:45
-
Benjamin Kott uploaded patch set 4
V -104/14/26, 13:57Copied Votes: * Code-Review-2 (copy condition: "changekind:NO_CHANGE OR **is:MIN**") -
core-ci voted on patch set 4 V -1 04/14/26, 14:12 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/100168
-
Benjamin Kott uploaded patch set 5
V -104/14/26, 14:14Copied Votes: * Code-Review-2 (copy condition: "changekind:NO_CHANGE OR **is:MIN**") -
core-ci voted on patch set 5 V +1 04/14/26, 14:23 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/100169
-
Christian Kuhn commented on patch set 5 CR -2 04/14/26, 17:17
-2 for now since we need to communicate and coordinate these internally first: https://review.typo3.org/c/Packages/TYPO3.CMS/+/93666 https://review.typo3.org/c/Packages/TYPO3.CMS/+/93664 https://review.typo3.org/c/Packages/TYPO3.CMS/+/93628 -
Benjamin Kott rebased onto patch set 6
V +104/15/26, 09:02Copied Votes: * Code-Review-2 (copy condition: "changekind:NO_CHANGE OR **is:MIN**") -
core-ci voted on patch set 6 V +1 04/15/26, 09:40 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/100237
-
Benjamin Kott rebased onto patch set 7
V +104/16/26, 12:58Copied Votes: * Code-Review-2 (copy condition: "changekind:NO_CHANGE OR **is:MIN**") -
core-ci voted on patch set 7 V +1 04/16/26, 13:10 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/100318
-
Benjamin Kott rebased onto patch set 8
V +104/20/26, 06:44Copied Votes: * Code-Review-2 (copy condition: "changekind:NO_CHANGE OR **is:MIN**") -
core-ci voted on patch set 8 V +1 04/20/26, 07:22 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/100508
-
Benjamin Kott uploaded patch set 9
V +104/20/26, 19:58Copied Votes: * Code-Review-2 (copy condition: "changekind:NO_CHANGE OR **is:MIN**") -
core-ci voted on patch set 9 V +1 04/20/26, 20:06 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/100601
-
Christian Kuhn commented on patch set 9 CR -2 04/21/26, 01:05
similar fundamental state issues as with the other patches: SvgDocument blends value object characteristics, with transformation that return this, with output-context related things. that's 3 different things. suggestion as first shot: * create SvgDocument to wrap safetly-loaded DOMDocument, with static fromString, static fromFile, (probably protected/private) __construct(private readonly \DOMDocument), document(), rootElement(), toXmlString(). * create stateless SvgOperations service getDimensions(SvgDocument): ImageDimension, cropScale(), sanitize(), toInlineMarkup(document + additional attributes). -
Benjamin Kott commented on patch set 9 04/21/26, 03:53
Reply
heya, i see where you are coming from but i really tried to avoid the suggestion you are giving here to ensure everything is in full circle. that means for me that the lifetime of an svg-document is self-contained. i consider this more like a working document, something you modify after load until you dump it again. we had similar approaches before that lead to scattered usages across the core, it was unclear when and if something happened. the goal here was to complete the chain and more or less enforce the correct behavior (as much as possible), from loading, over processing to dumping again. happy to discuss this further and check how we can align it here. also see https://review.typo3.org/c/Packages/TYPO3.CMS/+/93628/47/typo3/sysext/core/Classes/Imaging/Processor/SvgProcessor.php still rough but i really did not want to chain utility functions here. -
Benni Mack commented on patch set 9 04/21/26, 07:36
let's re-evaluate this change after the v14 LTS release, and see if we can add these bugfixes in v14 still. -
Benjamin Kott commented on patch set 9 04/21/26, 07:43
Reply Unresolved
we already agreed to that on friday during the merger alignment call, so fine with me -
Christian Kuhn commented on patch set 9 04/21/26, 16:29
Reply
SvgDocument: A few points that bite you when you blend entity and service characteristics in a single class: * DI is poisoned the moment a dependent service is needed. Concrete example already in this patch: sanitized() calls new SvgSanitizer(). The day we want a facade with an interface in front of the sanitizer so it can be swapped, you can't inject it - state is nailed into the constructor. Either we hack around it (container lookup) or we tear the class apart. We've been there. It took me two majors to untangle just one case for COR, and we're still suffering from others. Polluted constructors on service-shaped classes are where most of the refactoring pain in core lives. Other case: EventDispatcherInterface injection - the class is completely sealed. If ever anyone needs to change anything, you will see the forge issue requesting an event. Probably tomorrow. * Chaining that mixes mutation and return-new on one stateful class is the problem. setRootAttribute() mutates and returns $this. sanitized() returns a new instance. cropScale() returns a new instance. toInlineMarkup() returns a string. Three different contracts on one class. Consumers that chain through this are tied to exactly this shape, and any refactor breaks them. Immutable fluent value objects (PSR-7 withX) are fine, this mix is not. * Totally encapsulated final entity, zero seam. No chance to change anything. The solution has issues we don't see yet - it will. Devs and extensions will want a faster transformer, a parallelizing service, a different sanitizer. Create a casual entity class we can hand around, and a single, non-static stateless service for the transformations. When anyone wants something cleverer, we add an interface and inject it. Done. Maybe even consider shipping the interface from day one, or when we de-@internal it. -
Benjamin Kott commented on patch set 9 04/23/26, 08:06
Reply
Thanks for the detailed thoughts! I think the perception might be a bit off though, because SvgDocument isn't really a service. It's more of a document wrapper, similar in spirit to \DOMDocument itself. Some of its methods mutate the tree, some return a new document, and some serialize to a string. That mix isn't inconsistent, it's just what a document API naturally looks like. PSR-7's strict immutability exists because HTTP messages travel through middleware and get shared around, but an SVG wrapper that's built and used in one spot doesn't have that pressure. On the DI side, the sanitizer has no dependencies and no alternative implementation today, so putting an interface in front of it wouldn't actually buy us anything right now. If that ever changes, it's a tiny refactor. And since the class is @internal, we keep full freedom to adjust it later when a real need shows up, without locking ourselves into abstractions we're only guessing at today. -
Benni Mack commented on patch set 9 04/23/26, 09:53
Reply
I created an alternative now in order to move forward. This change https://review.typo3.org/c/Packages/TYPO3.CMS/+/93823 1) uses a Factory, allowing to inject SvgSanitizer separately / later-on as it isn't in the document created there, so it won't need a refactor later-on. 2) The SvgDocument still is a "working document", and now acts as a wrapper / converter, but you can explicitly set things you need. We expose the underlying document if we need it, leaving out the API. 3) It doesn't use a fluent API anymore - completely shifting away from the discussion of mutability, avoiding any problems with inheritance at a later point. Using the fluent API in e.g. DocHeader Buttons is a mess from a technical point of view - e.g. we cannot define that it returns the same = modified object. 4) The factory now covers the actual dependencies via DI, so we have this one place to change later-on inside the factory. Is that a way we can agree with? If so, I think we can also put the paradigms into a "core dev best practices". The change of me now shows where we still need to use GeneralUtility::makeInstance and where we have bad code smell ("ImageInfo"). -
Benjamin Kott commented on patch set 9 05/05/26, 09:10
Reply
How do we proceed here now? -
Christian Kuhn commented on patch set 9 05/05/26, 12:13
Reply Unresolved
i prefer bennis solution since it resolves my concerns. -
Garvin Hicking commented on patch set 9 05/29/26, 09:00
I tested https://review.typo3.org/c/Packages/TYPO3.CMS/+/93823 and would prefer that solution. -
Oliver Hader wrote 06/26/26, 09:48
Removed Code-Review-2 by Christian Kuhn -
Oliver Hader commented on patch set 9 06/26/26, 09:49
Unblocking this patch to proceed in a constructive way, without blocking this initiative by the `-2` that has been given. -
Garvin Hicking commented on patch set 9 CR -1 V +1 06/26/26, 10:03
This patch works and I think we need to move forward with addressing this. Subjectively I would prefer to move forward with the architecturally different (but functionally basically the same) implementation of https://review.typo3.org/c/Packages/TYPO3.CMS/+/93823 (where I've voted some time ago) This is however broader topic why I'm for that and want to die on the hill of stateless services, a value object containing state, and service methods that can operate on these value objects (not needing immutable value objects). I explicitly want to mention that I'm okay with merging this approach if this carries the majority, and accept that a different architectural decision can override my subjective approach. No hard feelings :-) -
Benjamin Kott abandoned the change 07/21/26, 07:46