Python's Pillow Library Has a Flaw That Could Let Hackers Run Code

·
Listen to this article~3 min
Python's Pillow Library Has a Flaw That Could Let Hackers Run Code

Pillow, Python's most popular image library, has a critical flaw that lets attackers run code on your server via a crafted EPS image. Here's what you need to know and how to protect yourself.

You know how we all rely on Pillow for image processing in Python? It's the go-to library for everything from resizing photos to generating thumbnails. But here's the thing: a critical flaw has been discovered that could let an attacker run malicious code on your server. And it all starts with a seemingly innocent EPS file. The vulnerability, tracked as CVE-2026-112900, is in the way Pillow handles EPS (Encapsulated PostScript) images. When you open an EPS file, Pillow doesn't process it directly. Instead, it passes the file's name to Ghostscript, a separate program that converts the image into pixels. The problem? Pillow doesn't check the filename first. So if an attacker crafts a filename that includes shell commands, those commands get executed on your server. Yikes. ### How the Exploit Works Let's break it down. Ghostscript is powerful—it can interpret PostScript code. But when Pillow hands over a filename without sanitizing it, it's like giving someone the keys to your house and hoping they don't snoop around. An attacker could create a file with a name like `image.eps; rm -rf /` (though in practice, it's more subtle). When Pillow passes that name to Ghostscript, the shell interprets the semicolon as a command separator and runs the malicious command. This is a classic command injection vulnerability. ### Who's at Risk? If you're using Pillow to process user-uploaded images, you're potentially at risk. This is especially concerning for web applications that allow users to upload EPS files. Even if you don't explicitly support EPS, Pillow might still attempt to open them if the file extension is present. So it's worth checking your code. ### What You Can Do First, update Pillow to the latest version. The maintainers have likely patched this by now (check the release notes). If you can't update immediately, consider disabling EPS support or validating filenames before passing them to Pillow. Also, avoid running your application with elevated privileges—that way, even if an attacker exploits this, the damage is limited. > Security is not a one-time fix; it's a continuous process of staying informed and proactive. ### The Bigger Picture This isn't just about Pillow. It's a reminder that even the most trusted libraries can have hidden dangers. Always sanitize inputs, especially when they interact with external programs. And keep your dependencies up to date—it's the simplest way to protect yourself. So, take a moment to check your Python projects. A quick update could save you from a nasty surprise.