CyberPeople

Ghostscript: How a Routine File Upload Becomes Remote Code Execution on Your Server

Ghostscript Flaw Turns Uploaded Files into RCE (CVE-2026-125396)

CVE-2026-125396 lets a crafted file escape Ghostscript's -dSAFER sandbox and run commands on the server. How the flaw works and how to defend.

Security firm pwn.ai showed this week how ordinary features — uploading an avatar, previewing an email attachment, printing a document — can turn into full command execution on a server. The culprit is Ghostscript, the open-source PostScript and PDF interpreter that quietly works under the hood on many Linux servers. The flaw, tracked as CVE-2026-125396 and dubbed Upload2Shell, lets a crafted file disable the -dSAFER sandbox and run arbitrary code. Here we break down how the bug works, why it is reachable without logging in, and how to defend your services.

What Ghostscript is and why it is almost everywhere

Ghostscript is a PostScript and PDF interpreter developed by Artifex. Its job is simple on the surface: convert a document from one format to another — render a PDF preview, generate an image thumbnail, print a file, or convert PostScript into a plain picture.

The catch is that almost nobody calls Ghostscript directly. It sits far deeper: behind print queues, image conversion, thumbnail generation, and document preview. When your application "just shows a preview" of an uploaded file, libraries such as ImageMagick, Pillow, libvips, or a Qt plugin may hand that file's content to Ghostscript behind the scenes — without the application even knowing it uses Ghostscript.

That is the root of the problem. Ghostscript is one of those "invisible" components whose vulnerability means vulnerability in dozens of unrelated products at once, no matter what language they are written in.

The flaw: a bug in font loading

Technically, CVE-2026-125396 is a use-after-free in the part of Ghostscript that loads fonts. To see why that matters, note one quirk of Ghostscript: part of its internal logic, including font handling, is itself written in PostScript.

One internal helper — the .putgstringcopy procedure in gs_fonts.ps — has to write into protected font dictionaries, and it uses the privileged internal operator .forceput to bypass normal write restrictions. The problem is that this procedure did not check the types of its operands. A crafted Type 1 font could make an earlier step of the helper fail, after which the document's own error handler continued into the privileged write with values of the document's choosing.

From there the attacker used that write to keep a reference to memory Ghostscript later frees — a classic use-after-free. With it, researchers could read and write the interpreter's native memory, switch off the path checks imposed by -dSAFER, and run a command.

How the attack works: disabling the sandbox

PostScript is a full programming language, not just a "picture" format, so rendering a PostScript file means executing its code. That is why -dSAFER exists: it is supposed to stop a document from reading or writing arbitrary files and launching other commands. Almost everything that hands untrusted documents to Ghostscript relies on it.

The Upload2Shell attack effectively turns that protection off. A crafted document breaks the font-loading routine, substitutes values through its own error handler, and ultimately disables the path checks in the interpreter's memory. The command then runs as the account that renders the document — usually a low-privilege service account such as lp for a print queue or the web server user for an upload handler.

One key detail: no Ghostscript setting removes this bug. -dSAFER is precisely the protection being bypassed. The only real fix is upgrading to a version where the helper validates operand types.

Uploaded files as an attack vector

Where it works in practice: uploads, printing, email

Although the CVE is classified as a "local" flaw, pwn.ai's tests showed Ghostscript can be reached from the network through ordinary features. The researchers confirmed command execution in roughly ten common applications — and some paths required no authentication at all:

  • An anonymous print job to a shared Debian 13 CUPS queue that accepts jobs without authentication;
  • An email attachment that Roundcube webmail processed the moment the recipient opened the message;
  • Public upload forms in the WordPress plugins Forminator and Essential Addons for Elementor.

WordPress Core itself needed more — an account able to upload files, which the Author role and above have by default. Notably, WordPress closed its own upload path back on August 12, 2026 in version 7.0.4 under a separate identifier, CVE-2026-65640.

Patch distribution is also tellingly uneven. Updates touched Debian, AlmaLinux 8/9/10, Amazon Linux, and SUSE, as well as container images that freeze an older Ghostscript version together with the application. So even after the fix shipped, part of the infrastructure remains vulnerable.

Server infrastructure processing files

Why the file extension doesn't help

One of the most dangerous traits of this attack is the "trusted" file extension. A user uploads an image named photo.png, scan.jpg, or a document report.pdf, while inside it actually holds PostScript or EPS content. A library like ImageMagick or Pillow, trying to make a thumbnail or crop the picture, hands the content to Ghostscript — which executes it regardless of the harmless-looking extension.

The practical lesson for developers: checking the file type by extension is useless here. You need to inspect the actual content, and do it before the file reaches conversion or preview generation, not after.

Who found it and how it was fixed

The flaw was discovered by Paulos Yibelo of pwn.ai — by his account, not without help from artificial intelligence. It is a telling example of how AI tools increasingly take part in finding real vulnerabilities in old, "invisible" code.

There is a notable historical context: a related flaw was found in the same font-handling file back in 2018 by Google researcher Tavis Ormandy through fuzzing. This is not a one-off accident but a recurring class of problems in this part of the code.

Artifex fixed the vulnerability in Ghostscript 10.08.0 on September 8, 2026, and is moving the vulnerable internal step into safer code. The developer who closed the bug, Ken Sharp, called it "an ancient piece of code well known to be a vulnerability, but difficult to eradicate" in the bug report. The CVE was requested on November 6 and published on November 9 — more than two months after the fix. It is scored 8.5 out of 10 under CVSS 4.0 (NVD, in turn, lists 7.8 on the older scale). As of publication, there have been no reports of the flaw being used in real attacks.

Defending servers against RCE

How to protect yourself

Even though the bug is already fixed, patch distribution is the weakest link. Here is a practical plan for teams running servers that process files:

  • Upgrade Ghostscript to 10.08.0 or newer — the only complete fix. Check not only the system package but also Ghostscript copies inside containers and applications that bundle their own build.
  • Don't expose print queues to untrusted networks. Shared CUPS queues that accept jobs without authentication are a direct attack path. Close them or require authorization.
  • Disable unneeded coders in ImageMagick. If you don't need PostScript, EPS, or PDF conversion, disable those coders in policy.xml so ImageMagick won't hand such files to Ghostscript.
  • Check the real file type before conversion, not after, and turn off preview generation for document types you don't use.
  • Follow distribution updates. AlmaLinux, Debian, Amazon Linux, and SUSE have shipped or prepared patches — update systems once the fix reaches the stable repository.

For teams working with web applications, this story is another reminder: the attack surface often hides not in your code but in the libraries that "just make a preview." To systematize knowledge about such vulnerability classes, see our cyberpeople.tech education resources.

Conclusion

CVE-2026-125396 is a vivid example of how an "old, invisible" infrastructure component can become a code-execution point. Ghostscript doesn't write your applications, but it processes their files; nobody "plugs it in" consciously, yet libraries do it on their own the moment a preview or print job appears.

The main lesson is simple: an uploaded file is always potential code, especially when an interpreter sits behind its processing. And what protects you is not extension checking but timely updates of those "invisible" components the team often doesn't even know exist.

Stay ahead of threats

Weekly cybersecurity intelligence in your inbox. No spam.

CyberPeople contributor