Skip to content

Refuse an SVG source that references an external resource - #100

Merged
beetlebugorg merged 1 commit into
mainfrom
fix/svg-external-reference
Aug 28, 2026
Merged

beetlebugorg merged 1 commit into
mainfrom
fix/svg-external-reference

Conversation

@beetlebugorg

Copy link
Copy Markdown
Owner

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> href or xlink: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.xml disables PS, 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, including TestSvgExternalReferenceIsRefused, the test_svgguard.c unit cases, and TestSvgSource, which still renders. make -C test sanitize is 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.

- 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
beetlebugorg force-pushed the fix/svg-external-reference branch from c254cf0 to d60570c Compare August 28, 2026 18:06
@beetlebugorg
beetlebugorg merged commit e84b852 into main Aug 28, 2026
6 checks passed
@beetlebugorg
beetlebugorg deleted the fix/svg-external-reference branch August 28, 2026 18:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant