Upload2Shell: how to check your apps for Ghostscript exposure
Key takeaways
- Any app that crops, converts or previews uploaded images may hand a file to Ghostscript, even if the file is named .png or .jpg
- Upload2Shell (CVE-2026-125396) is a use-after-free in Ghostscript's Type 1 font loader that bypasses the -dSAFER sandbox
- The decoder matters: PHP GD, OpenCV, prebuilt Sharp, Jimp, Java ImageIO and Go's standard decoders did not start Ghostscript in the tests
After reading this, an IT team should be able to work out which of its applications can pass an uploaded file to Ghostscript, and cut that exposure while some related bugs are still being fixed.
The trigger is research from Paulos Yibelo at pwn.ai, published on 21 November 2026 and covered by The Hacker News. The team reached Ghostscript through most of the applications it tested, exploited a memory corruption bug in its font loader, and bypassed the -dSAFER sandbox to get remote command execution. The headline bug is Upload2Shell, now CVE-2026-125396. Some related bugs, reported to Artifex, are still being fixed.
Difficulty: moderate. Time: roughly half a day for a small estate, longer if you run many services.
What you need before starting
- An inventory of every service that accepts uploads: image galleries, CMS plugins, document previewers, AI image tools, ticketing systems.
- Access to source or build manifests for those services, so you can see which image libraries they use.
- A staging copy of at least one upload workflow for safe testing. Do not test with hostile files on production.
- Shell access to the servers, to check whether
gsis installed and whether ImageMagick or Ghostscript is linked as a library. - No licence cost: the checks use tools already on your systems.
Step-by-step process
Step 1: Understand why the file extension tells you nothing
Ghostscript renders PDF and PostScript. PostScript is a Turing-complete programming language, so rendering a document means executing a program. The -dSAFER sandbox restricts that program's file access and command execution, but it relies on checks inside the interpreter rather than a kernel-enforced system-call filter. A memory-safety bug in the interpreter can let the program corrupt the engine running it.
In the researchers' WordPress-shaped preview proof, a file named .pdf actually contained PostScript. ImageMagick handed it to Ghostscript under -dSAFER. Names do not decide the route; the decoder inspecting the bytes does.
Step 2: Find direct and indirect Ghostscript calls
Search your code for explicit gs invocations, but do not stop there. The researchers note that looking only for explicit Ghostscript calls misses two indirect routes: an upload handler calling a library such as Imagick (the PHP binding to ImageMagick), which delegates to Ghostscript, and Ghostscript linked into an image-processing build as a library, where it runs inside your existing process.
Check each server for an installed gs binary and for ImageMagick builds that list Ghostscript delegates.
Step 3: Audit the image calls your code makes after accepting a file
In controlled runs on Ubuntu 24.04 with Ghostscript installed, one test matrix traced 145 benign calls across 29 image APIs; a second covered additional wrappers including Imagick and imageio. EPS content reached Ghostscript through ordinary calls even when the file was named .png.
The detail that matters for audits: Image.open() alone only identified the file. Loading pixels, cropping or converting started the renderer. So the dangerous step is the one after upload, not the upload itself. The source audit also found image decoding calls in InvokeAI uploads, AUTOMATIC1111 img2img and ComfyUI previews.
Step 4: Separate exposed decoders from safe ones
In the tests, PHP GD, OpenCV, prebuilt Sharp, Jimp, Java ImageIO and Go's standard image decoders did not start Ghostscript for these inputs. Copying or storing a file did not render it either. The versions tested describe those libraries, not every product that uses them, so confirm against your own build.
Step 5: Reduce the exposure
The source gives no patch version, so treat these as mitigations to confirm with your vendors:
- Where a safe decoder meets the need, switch the preview or crop path to it.
Common mistakes to avoid
- Trusting the extension or MIME type. The exploit proofs used PostScript behind .pdf and .png names.
- Grepping only for
gs. Library-linked Ghostscript and delegate chains through Imagick never show up that way. - Testing the upload and stopping. Storing a file did not trigger rendering; the later preview or conversion is the step to inspect.
- Assuming -dSAFER is a hard boundary. It is an in-interpreter check, and this bug defeats it.
- Treating the exploit as needing a font on the server. The proof wrote its own Type 1 font to the authorised scratch output path, and a variant used Ghostscript's process-local %ram% device.
Tips that make a difference
- Map the full chain per feature: upload endpoint, library, delegate, interpreter. One CMS plugin can hide three hops.
- AI image tooling deserves its own pass. The audited tools take user uploads into decoding calls in the same way a CMS does.
- Log which process renders files, and what child processes it spawns, so a rendering service starting a shell stands out.
UK and compliance angle
For UK organisations, an exploited upload feature that exposes personal data is a security question under the law.
Related reading on the site: the Nginx2Root patch guide shows a similar check-and-patch workflow, and the UK cyber compliance guide for IT teams covers the obligations above.
The weak point is the conversion library behind a feature as routine as cropping or previewing, not the upload form. Teams in both the UK and US running image pipelines, CMS previews or AI image tools should inventory their decoders now.
Next steps
Track fixes for CVE-2026-125396 and the related bugs Artifex is still addressing.
Summary
You now know how an upload reaches Ghostscript, which decoders did and did not trigger it in testing, and how to audit, isolate and harden your own rendering paths while fixes land.
Frequently asked questions
What is Upload2Shell?
Upload2Shell, CVE-2026-125396, is a use-after-free in Ghostscript's Type 1 font loader. It gives a write-what-where primitive that lets a crafted document alter the state enforcing -dSAFER and run commands as the rendering process.
Does renaming a file to .png make it safe?
No. In the researchers' tests a PostScript sample named .png still reached Ghostscript when loaded or converted, because the decoder inspected the bytes rather than trusting the name.
Which image libraries did not start Ghostscript?
In the tests, PHP GD, OpenCV, prebuilt Sharp, Jimp, Java ImageIO and Go's standard image decoders did not start Ghostscript for these inputs. Copying or storing a file did not render it either.