Skip to content

Restrict ImageMagick policy to block ImageTragick-class coders - #1577

Merged
rosbo merged 2 commits into
mainfrom
imagemagick-restrictive-policy
Nov 16, 2026
Merged

rosbo merged 2 commits into
mainfrom
imagemagick-restrictive-policy

Conversation

@rosbo

@rosbo rosbo commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

patches/imagemagick-policy.xml replaced the distro policy with an empty <policymap>. That re-enabled every ImageMagick coder. Any notebook opening an untrusted dataset file with Wand was exposed to:

  • SSRF through URL/HTTP/HTTPS
  • local file disclosure through label:@/path and text:
  • MVG/MSL scripting
  • Ghostscript (9.55, still running PDF on its PostScript interpreter) through PS/EPS/PDF/XPS. Content sniffing means a .jpg with a %PDF/%!PS header also reaches Ghostscript.

The empty policy was added in 2020 so Wand could read PDFs.

Changes

  • New restrictive policy:
    • Denies network coders/delegates, the @* path pattern, EPHEMERAL, MVG, MSL, TEXT, SHOW, WIN, PLT, and all Ghostscript-backed coders (incl. PDF).
    • Common raster formats (PNG/JPEG/GIF/TIFF/WebP/...) still work.
    • Resource limits are much more generous than the Ubuntu defaults (128KP width/height, 4GP area, 32GiB disk) so large imagery still works while decompression bombs stay bounded.
  • Install poppler-utils. pdf2image was already installed but unusable without pdftoppm; it is now the supported way to rasterize PDFs.
  • test_pytesseract uses pdf2image instead of Wand to read the PDF.
  • New test_wand.py: checks that raster reads work and that PDF (filename and blob), PostScript, label:@, text:, MVG, MSL and URL reads raise PolicyError.

Behavior change: wand.image.Image(filename='x.pdf') now raises PolicyError. Use pdf2image.convert_from_path instead.

Testing: Ran tests/test_wand.py and tests/test_pytesseract.py in the current staging image with the new policy copied in and poppler-utils installed: 12 passed. With the old empty policy, the Wand suite crashes.

http://b/584415262

The empty policy.xml override re-enabled every ImageMagick coder, including
URL/HTTP(S), MVG, MSL, TEXT, the "@" indirect file read, and the
Ghostscript-backed PS/EPS/PDF/XPS coders. Notebooks opening untrusted dataset
files with Wand were exposed to SSRF, local file disclosure, and Ghostscript RCE.

Replace it with a restrictive policy that keeps common raster formats working
and uses generous resource limits. PDF rasterization moves to pdf2image, which
was already installed but broken because poppler-utils was missing.

http://b/584415262
@rosbo
rosbo requested a review from calderjo November 16, 2026 20:13
@rosbo
rosbo merged commit e1dbc17 into main Nov 16, 2026
9 checks passed
@rosbo
rosbo deleted the imagemagick-restrictive-policy branch November 16, 2026 20:36
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.

2 participants