Repository navigation
Refuse an SVG source that references an external resource - #100
Merged
Merged
Conversation
- Parse a fetched SVG and refuse an external <image> reference, on the source and on the watermark overlay. - Refuse an SVG that does not parse, rather than hand it to the renderer. - Ship an ImageMagick policy that disables the coders the service does not use, including PS, PDF, EPS, and MSL.
beetlebugorg
force-pushed
the
fix/svg-external-reference
branch
from
August 28, 2026 18:06
c254cf0 to
d60570c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
The module reads a fetched SVG as XML and refuses one that references an external resource before ImageMagick sees it. It checks the source image and the watermark overlay. A self-contained SVG still renders. An SVG that names a file, a URL, or a relative path in an
<image>href is refused, and so is one that does not parse. The image also ships an ImageMagick policy that disables the coders the service does not use.Why
ImageMagick's internal SVG renderer reads a local file named by an
<image>hreforxlink:href, and returns it inside the rendered raster. A caller who supplies an SVG source can read image files the worker can reach. A policy cannot separate that read from the module's own file reads or the renderer's temp file, so the module inspects the SVG instead. The check parses with the APR XML parser, so an entity-encoded value decodes before it is read, and it fails closed on a parse error.Testing found the read reaches a file only through an
<image>href; feImage, use, external entities, and CSS url() did not. The check refuses any external href, which covers those as well.The shipped
policy.xmldisablesPS,PS2,PS3,EPS,PDF,XPS,MSL,SCRIPT, and the network and text render coders. Each can read a file, write a file, or run a command. The image coders and the SVG renderer stay enabled.Verify
Run
make -C test test. All 263 cases pass, includingTestSvgExternalReferenceIsRefused, thetest_svgguard.cunit cases, andTestSvgSource, which still renders.make -C test sanitizeis clean. The suite runs under the shipped policy, so the raster golden files prove it does not disable a coder the service needs.Breaking
An SVG source or overlay that references an external resource is refused and answered with the error image. A self-contained SVG is unchanged. A deployment that renders SVG with an external reference must inline it as a
data:URI.