Skip to content
File upload Write-up Intermediate

CVE Decoded #5: CVE-2026–65640 (WordPress)

WordPress's Imagick image editor passed uploaded files to Ghostscript without checking their content, so a PostScript file containing embedded commands could be executed. An attacker with an Author-level account could upload such a file and run commands with the web server's privileges.

medium.com

Published on medium.com

Oscp

Saijalpreet Kaur, on medium.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 5 min read.

Context

This write-up decodes CVE-2026-65640, a vulnerability in WordPress Core affecting versions prior to 7.0.4. The affected feature is the media upload and image processing pipeline: when a user uploads an image, WordPress generates thumbnails, crops and resizes it through the WP_Image_Editor_Imagick class in wp-includes/class-wp-image-editor-imagick.php.

Two components sit behind that pipeline. Imagick (ImageMagick) is the image processing library that does the resizing work. Ghostscript is a separate tool that reads and renders document formats such as PostScript (.ps) and PDF. When Imagick meets a file it cannot handle directly, it passes the file to Ghostscript rather than refusing it, and Ghostscript processes whatever it receives, including commands embedded in the file.

The vulnerability type is unrestricted file upload leading to remote code execution (CWE-434). It was published on 12 August 2026 and rated High with a CVSS score of 8.8.

From the original on medium.com

Setup

The precondition is an account with the upload_files capability. The report describes this as an Author-level account, which could be a compromised author account, a guest contributor role, or a legitimate user who has gone rogue. No other tooling or configuration is described beyond a WordPress installation prior to 7.0.4.

Finding it

The issue turns on the trust relationship between Imagick and Ghostscript. Imagick does not rely on the file extension alone: it inspects the file contents, and when it sees PostScript magic bytes (%!PS) it decides the file is PostScript and delegates it to Ghostscript. PostScript is a full programming language, so a file that passes through this path can carry system commands.

WordPress checked the file extension against its allowed upload list and checked the MIME type, but never asked whether the file content was the kind that could contain executable code once handed to the image pipeline. PostScript files, EPS files and certain malformed PDFs can all contain executable code, and Imagick forwards all of them to Ghostscript.

Exploitation

Step 1: obtain an Author account

The attacker needs an account with upload_files permission. The report lists a compromised author account, a guest contributor role, or a legitimate user gone rogue as the ways to get one.

Step 2: craft a malicious PostScript file

Create a .ps file that looks innocent but embeds system commands through Ghostscript's %pipe% directive. The report's example payload is:

POSTSCRIPT
%!PS
% This LOOKS like a normal PostScript header...
% But hidden inside is a system command:
(%pipe%/bin/bash -c 'id > /tmp/pwned.txt') (w) file
% The attacker could also write a PHP web shell:
(%pipe%/bin/bash -c 'echo "<?php system($_GET[cmd]); ?>" > /var/www/html/shell.php') (w) file
showpage

The %!PS header identifies the file as PostScript. The %pipe% directive tells Ghostscript to open a pipe to the system shell and execute the command that follows. The first command writes the output of id to /tmp/pwned.txt; the report notes the attacker could also write a PHP web shell to the web root. The report notes this is not a bug in Ghostscript itself but a feature of the PostScript language; the bug is that WordPress let untrusted input reach Ghostscript at all.

Step 3: upload via the Media Library

The file is uploaded through WordPress's normal media upload interface, just like any other image.

Step 4: WordPress processes the file

WordPress tries to generate thumbnails and metadata. The WP_Image_Editor_Imagick class calls its load() method, which creates a new Imagick object and tells it to read the uploaded file. Imagick inspects the contents, recognises the PostScript magic bytes, and delegates to Ghostscript.

Step 5: Ghostscript executes the payload

The embedded commands run with the same privileges as the web server process. From there the attacker can write a web shell, exfiltrate data, or pivot deeper into the network.

Root cause

The vulnerable load() method performs no validation of the file contents before calling readImage():

The readImage() call happens with zero validation of what is inside the file. If the file is PostScript with embedded shell commands, Imagick passes it straight to Ghostscript for execution. The extension check and the MIME type check did not stop this because neither of them asks whether the content is safe for the image pipeline to interpret.

Impact

Successful exploitation gives code execution with the web server's privileges, which the report describes as a shell on the server, with the ability to write a web shell, exfiltrate data or pivot further into the network.

The CVSS score of 8.8 is High rather than Critical because, unlike the path traversal in CVE-2026-87902 covered earlier in the series, this vulnerability requires authentication. An attacker cannot hit a site from the internet and get a shell without first holding an Author-level account. The report argues the exposure is still broad: author accounts are common on multi-author blogs, news sites and e-commerce platforms with contributor roles; credential stuffing, phishing or leaked password dumps can supply one; and once upload access exists the exploit is a single file upload with no complex chain and no race condition.

Fix

WordPress 7.0.4, changeset 63218, added content inspection before the file reaches Imagick:

The patch reads the first 256 bytes and checks for the %!PS signature, either at the start of the buffer or anywhere inside it. If the signature is present, the upload is rejected with image_load_error before Imagick or Ghostscript ever sees the file. As the report puts it: before the patch WordPress asked "can I open this file?"; after the patch it asks "should I open this file?".

The report also lists operational measures:

  1. Update WordPress Core to 7.0.4.
  2. Audit Author accounts and consider restricting upload_files to Editors and Admins only.
  3. Check PHP extensions with php -m | grep imagick and, if Imagick is installed, check whether Ghostscript is present (gs — version). Remove Ghostscript if it is not needed.
  4. If patching is not immediately possible, set disable_functions in php.ini to disable proc_open, popen and exec, limiting Ghostscript's ability to spawn shells.
  5. Review upload logs and check wp-content/uploads/ for unexpected .ps, .eps or .pdf files uploaded around August 2026.

Variants to test

  1. Other PostScript-like formats. Upload .eps and malformed PDF files containing embedded commands through the media library.
  2. Signature placement. The patch checks for %!PS at the start of the first 256 bytes and anywhere within them. A positive result is a file that is processed by Ghostscript despite the content check.
  3. Ghostscript availability. On installations where Imagick is present, check whether Ghostscript is installed.
  4. Capability boundaries. A positive result is a lower-privileged account that can still upload a file which reaches the image pipeline.
  5. Server-level hardening. A positive result is that the payload no longer executes even on an unpatched WordPress, confirming the server-level control as a compensating measure.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 16 min read.

What happened, in plain words

WordPress is the software that runs a huge share of the world's blogs and websites. One of its everyday features is the media library: you click a button, pick a photo from your computer, and the site stores it and makes smaller copies of it (thumbnails) so pages load quickly. That resizing work is not done by WordPress itself. WordPress hands the picture to a helper program on the server, and that helper sometimes hands the file on to a second helper.

CVE-2026-65640 is a bug in that chain of helpers. A person with an Author account could upload a file that seemed like an image but was really a disguised script. WordPress passed it along without checking what was inside, and the second helper ran it. The result was that the person could run commands on the server with the web server's privileges.

The bug affects WordPress Core before version 7.0.4. It was published on 12 August 2026 and rated High with a CVSS score of 8.8. The vulnerability type is unrestricted file upload leading to remote code execution, catalogued as CWE-434.

From the original on medium.com

A few words before we start, because this story uses them constantly:

  • Server: the computer somewhere in a data centre that holds your website's files and runs its code. Your browser asks it for pages; it answers.
  • Upload: sending a file from your computer to the server, the opposite of downloading.
  • Code execution: making the server run instructions of your choosing, rather than the ones the site's owner wrote. It is the difference between being allowed to leave a note in someone's letterbox and being allowed to stand in their kitchen and use their cooker.
  • CVE: a public catalogue number for a known security flaw, so that everyone in the world can refer to the same bug unambiguously.
  • CVSS: a 0 to 10 score for how serious a flaw is. Higher is worse. 8.8 sits in the "High" band, below "Critical".

The two helpers: Imagick and Ghostscript

Before the bug makes sense, you need to meet the two programs doing the quiet work.

Imagick (short for ImageMagick) is an image processing library. A library, in programming, is a bundle of ready-made code that other programs call on instead of writing everything themselves. When you upload a photo and WordPress automatically makes a thumbnail, crops it and resizes it, Imagick is the thing doing the heavy lifting. Think of it as a photo editing robot that lives on the server and takes orders from WordPress.

Ghostscript is an older, more specialised tool. Its job is to read and render document formats such as PostScript (.ps) and PDF. Think of it as a document translator: you hand it a complex print-ready file and it turns it into something a computer can display.

Here is the part that matters. Imagick and Ghostscript trust each other far too much. When Imagick meets a file it cannot handle directly, say a PostScript file, it does not say "sorry, I only do images". It quietly passes the file to Ghostscript and says: you do it. Ghostscript, being the obedient tool it is, opens and processes whatever it receives, including any hidden commands buried inside the file.

That handover is the heart of the story. Two programs, each doing its own job correctly, combine into a path that lets a stranger's file reach a program that can run instructions.

What went wrong

The vulnerable code lives in WordPress's image editor class, in the file wp-includes/class-wp-image-editor-imagick.php. A class, in programming, is a named bundle of code and data that does one job; this one handles all the behind-the-scenes image processing when someone uploads media.

Here is what happened when an Author-level user uploaded a file, step by step:

  1. WordPress checks the file extension. Is it jpg, png, gif, .ps, .eps? WordPress keeps an allowed list of uploadable file types and compares the name against it. The extension is the bit after the dot in a filename, and it is only a label: renaming holiday.jpg to holiday.txt does not change what is inside.
  2. WordPress hands the file to Imagick. The WP_Image_Editor_Imagick class calls its load() method, which creates a new Imagick object and tells it to read the uploaded file. A method is simply a named action a class can perform; load() means "read this file in".
  3. Imagick looks at the file contents. This is the critical moment. Imagick does not just trust the extension; it peeks inside the file to work out what format it really is. When it sees the PostScript magic bytes %!PS, it concludes: this is PostScript, I need Ghostscript for this. Magic bytes are a short fixed sequence at the start of a file that identifies its real format, a bit like the first few bars of a song telling you what tune it is.
  4. Ghostscript processes the file. Ghostscript opens the PostScript file and starts interpreting it. PostScript is not just a static document format: it is a full programming language. An attacker can embed system commands directly inside a .ps file.
  5. Code execution. Ghostscript runs the embedded commands with the same privileges as the web server process. The attacker now has a shell on the server. A shell is a way to type commands and have the machine carry them out; having one on someone else's server means you can do what the server's own software can do.

The core flaw

WordPress never checked whether the file content was actually safe to hand to Ghostscript.

It checked the file extension. It checked the file MIME type. A MIME type is the formal label for a file's kind, such as image/jpeg or application/pdf, and it is usually taken from the extension or from what the browser claims, so it is a label too, not proof of content.

But WordPress never asked the critical question: is this the kind of file that could contain executable code if processed by our image pipeline?

PostScript files can contain executable code. EPS files can contain executable code. Certain malformed PDFs can contain executable code. And Imagick will happily forward all of them to Ghostscript without a second thought.

A useful comparison: a nightclub bouncer who checks your name against a guest list is doing extension checking. A bouncer who checks whether you are carrying something dangerous is doing content checking. WordPress had the first and not the second.

The vulnerable code

This is the load() method as it stood in WordPress before 7.0.4:

Line by line, in plain words:

  • public function load() { starts the method called load. public means other parts of WordPress are allowed to call it.
  • if ( $this->image instanceof Imagick ) { return true; } asks: has an Imagick object already been created for this file? If yes, there is nothing to do, so report success and stop. This avoids loading the same file twice.
  • if ( ! is_file( $this->file ) ) { asks: does the file actually exist on disk? The ! means "not".
  • return new WP_Error( 'error_loading_image', __( 'File does not exist?' ) ); is the answer when it does not: build an error object with the code error_loading_image and the message "File does not exist?". WP_Error is WordPress's standard way of carrying an error back to whoever called the function.
  • try { begins a block where something might fail, so the failure can be caught rather than crashing the page.
  • $this->image = new Imagick(); creates a fresh Imagick object and stores it on the class, ready to use.
  • $this->image->readImage( $this->file ); is the important line: tell Imagick to read the uploaded file. This is where Imagick inspects the contents and, for PostScript, hands the file to Ghostscript.
  • $this->mime_type = $this->get_mime_type( $this->image->getImageFormat() ); asks Imagick what format it decided the file is, converts that to a MIME type, and remembers it.
  • return true; reports success.
  • } catch ( Exception $e ) { catches any error thrown inside the try block.
  • return new WP_Error( 'image_load_error', $e->getMessage() ); turns that error into a WordPress error object with the code image_load_error and the original message.

See the problem? The readImage() call happens with zero validation of what is actually inside the file. If it is a PostScript file with embedded shell commands, Imagick shrugs and passes it straight to Ghostscript for execution. The extension check and the MIME type check did not stop this, because neither of them asks whether the content is safe for the image pipeline to interpret.

What a malicious PostScript file looks like

This is the example payload from the report:

Line by line:

  • %!PS is the magic-byte header. It tells any reader, including Imagick, "this is a PostScript file". It is what makes the file look ordinary.
  • % This LOOKS like a normal PostScript header... is a comment. In PostScript, a line starting with % is ignored by the interpreter, so this is decoration for human eyes.
  • % But hidden inside is a system command: is another comment, explaining what follows.
  • (%pipe%/bin/bash -c 'id > /tmp/pwned.txt') (w) file is the first real instruction. %pipe% is a Ghostscript directive that tells it to open a pipe to the system shell. A pipe is a channel between two programs: one writes, the other reads. Here the channel leads to /bin/bash, the standard command shell on Linux. The -c flag tells bash to run the command that follows as text. That command is id, which prints who the server thinks it is running as, and > /tmp/pwned.txt sends that output into a file in the temporary directory. The (w) file part opens the pipe for writing. In short: prove you can run commands by writing the result somewhere you can see it.
  • % The attacker could also write a PHP web shell: is a comment introducing the second instruction.
  • (%pipe%/bin/bash -c 'echo "<?php system($_GET[cmd]); ?>" > /var/www/html/shell.php') (w) file does something more ambitious. It opens the same kind of pipe to bash, and asks bash to write a small PHP file into the web root, the folder the web server serves pages from. PHP is the programming language WordPress is written in. The written file contains <?php system($_GET[cmd]); ?>, which means: take the value of the cmd parameter from the URL and run it as a system command. That is a web shell: a page on the site that turns any visitor's URL into a command on the server.
  • showpage is a normal PostScript instruction that renders the page. It makes the file behave like a real document, so nothing looks unusual.

When Ghostscript processes this, the %pipe% directive tells it to open a pipe to the system shell and execute the command. It is not a bug in Ghostscript as such: this is a feature of the PostScript language. The bug is that WordPress let untrusted user input reach Ghostscript in the first place.

The attack, step by step

  1. Get an Author account. The attacker needs an account with the upload_files permission. The report lists three routes: a compromised author account, a guest contributor role, or a legitimate user who has gone rogue.
  2. Craft a malicious PostScript file. Create a .ps file that looks innocent but contains embedded system commands via Ghostscript's %pipe% directive, as in the payload above.
  3. Upload via the Media Library. Upload the file through WordPress's normal media upload interface, just like uploading any other image. Upload the file through WordPress's normal media upload interface, just like uploading any other image.
  4. WordPress processes the file. WordPress tries to generate thumbnails and metadata. It passes the file to Imagick, which delegates to Ghostscript.
  5. Ghostscript executes the payload. The embedded commands run with the web server's privileges. The attacker can write a web shell, exfiltrate data, or pivot deeper into the network. Exfiltrate means copying data out of a system without permission; pivot means using the first compromised machine as a stepping stone to reach others.

Was it bad?

At CVSS 8.8 this is rated High, not quite Critical, and there is a good reason for that distinction.

Unlike CVE-2026-87902, the path traversal covered earlier in the series, this one requires authentication. Authentication means proving who you are with a username and password. An attacker cannot simply hit your site from the internet and pop a shell; they need an Author-level account first.

But:

  • Author accounts are everywhere. Multi-author blogs, news sites, e-commerce platforms with contributor roles: any site with more than one writer is potentially exposed.
  • Compromised credentials are cheap. Credential stuffing (trying username and password pairs leaked from other breaches), phishing, or buying leaked passwords from dark web dumps can get an attacker an Author account.
  • The payload is trivial. Once you have upload access, the actual exploit is a single file upload. No complex exploit chain, no race condition. Just upload and wait. A race condition is a bug that only appears when two things happen at almost the same moment; this one needs no such timing.

The fix

The WordPress security team's fix was clean and surgical. They added content inspection before the file ever touches Imagick. This is the patched load() method from WordPress 7.0.4, changeset 63218:

Line by line, focusing on what changed:

  • The opening checks are the same as before: if an Imagick object already exists, stop; if the file is missing, return the "File does not exist?" error.
  • $file_contents = file_get_contents( $this->file, false, null, 0, 256 ); is new. It reads the file from disk into a variable, but only the first 256 bytes. The arguments mean: read this file, do not use the include path, no stream context, start at offset 0, read 256 bytes. Reading a small slice is enough to spot a header and cheap enough not to slow uploads down.
  • if ( $this->is_postscript_like( $file_contents ) ) { is new. It asks a helper method whether those bytes look like PostScript.
  • return new WP_Error( 'image_load_error', __( 'File type not supported for image processing.' ) ); is the rejection. If the answer is yes, the upload is refused with the message "File type not supported for image processing." and the file never reaches Imagick or Ghostscript.
  • $this->image->readImage( $this->file ); and the lines after it are unchanged: only files that passed the content check get read.
  • private function is_postscript_like( $header_bytes ) { starts the new helper. private means only this class can call it.
  • if ( false === $header_bytes ) { return false; } handles the case where reading the file failed. If there are no bytes, there is nothing suspicious to find, so it says no.
  • if ( str_starts_with( $header_bytes, '%!PS' ) ) { return true; } checks whether the bytes begin with the PostScript signature. If so, it is PostScript.
  • if ( str_contains( $header_bytes, '%!PS' ) ) { return true; } checks whether the signature appears anywhere inside those bytes, in case something sits in front of it.
  • return false; is the answer when neither check matched: not PostScript as far as we can tell.

The key difference: before the patch, WordPress asked "can I open this file?" After the patch, WordPress asks "should I open this file?"

By reading just the first 256 bytes and checking for PostScript signatures (%!PS), WordPress now blocks dangerous files before they ever reach Imagick or Ghostscript. The file never gets processed. The bomb never detonates.

Other things to check

The report also lists operational measures.

  1. Update WordPress Core to version 7.0.4.

  2. Audit Author accounts. Do all your Authors need upload permissions? Consider restricting the upload_files capability to Editors and Admins only.

  3. Check your PHP extensions. Run php -m | grep imagick on your server. php -m lists the modules PHP has loaded, and grep imagick filters that list down to lines containing "imagick". If Imagick is installed, check whether Ghostscript is also present (gs — version). If you do not need Ghostscript, remove it.

  4. Set disable_functions in php.ini. If you cannot patch immediately, consider disabling proc_open, popen and exec in PHP to limit Ghostscript's ability to spawn shells. php.ini is PHP's configuration file, and disable_functions is the setting that switches named functions off entirely.

  5. Review upload logs. Check your wp-content/uploads/ directory for unexpected .ps, .eps or .pdf files uploaded around August 2026.

  6. Other PostScript-like formats. Upload .eps and malformed PDF files containing embedded commands through the media library.

  7. Signature placement. The patch checks for %!PS at the start of the first 256 bytes and anywhere within them. A positive result is a file that is processed by Ghostscript despite the content check.

  8. Ghostscript availability. On installations where Imagick is present, check whether Ghostscript is installed.

  9. Capability boundaries. A positive result is a lower-privileged account that can still upload a file which reaches the image pipeline.

  10. Server-level hardening. A positive result is that the payload no longer executes even on an unpatched WordPress, confirming the server-level control as a compensating measure.

Takeaway

This CVE is a reminder that internal trust between software components can be just as dangerous as external trust. Treating file uploads as passive data fails when file formats like PostScript function as hidden programming languages. Basic validation layers are no match for deep interpreter flaws, especially when modern apps still inherit decades-old legacy tools like Ghostscript that were never built to handle untrusted input.

Glossary

  • Authentication: proving who you are, usually with a username and password.
  • Author (WordPress role): a user role that can write and publish its own posts and, in the default setup, upload files.
  • Capability: a specific permission in WordPress, such as upload_files, that decides what an account may do.
  • Class: a named bundle of code and data in a program that performs one job.
  • Code execution: making a computer run instructions of your choosing.
  • Coder (ImageMagick): the module inside ImageMagick that reads or writes one particular file format.
  • Credential stuffing: trying username and password pairs stolen from one breach against other sites, on the bet that people reuse them.
  • CVE: a public catalogue number for a known security vulnerability.
  • CVSS: a 0 to 10 score describing the severity of a vulnerability.
  • CWE-434: the catalogue entry for unrestricted upload of a file with a dangerous type.
  • EPS: Encapsulated PostScript, a PostScript-based file format often used for print graphics.
  • Exfiltrate: copy data out of a system without permission.
  • Extension: the part of a filename after the dot, such as .jpg; a label, not proof of content.
  • Ghostscript: a program that reads and renders PostScript and PDF documents.
  • Imagick / ImageMagick: an image processing library used to resize, crop and convert images.
  • Library: a bundle of ready-made code that other programs call on.
  • Magic bytes: a short fixed sequence at the start of a file that identifies its real format.
  • Method: a named action that a class can perform.
  • MIME type: the formal label for a file's kind, such as image/jpeg.
  • Path traversal: a vulnerability that lets an attacker reach files outside the intended folder.
  • Permission: see capability; a rule about what an account is allowed to do.
  • PHP: the programming language WordPress is written in.
  • php.ini: PHP's configuration file.
  • Pipe: a channel between two programs, where one writes and the other reads.
  • Pivot: using one compromised machine as a stepping stone to reach others.
  • PostScript: a page description language that is also a full programming language, so files can carry executable instructions.
  • Privileges: the level of access a running program or user has on a system.
  • Race condition: a bug that appears only when two operations happen at almost the same moment.
  • Remote code execution (RCE): running your own code on someone else's machine over a network.
  • Server: the computer that holds a website's files and runs its code.
  • Shell: a way to type commands and have a machine carry them out.
  • Unrestricted file upload: a flaw where a system accepts a file type it should have refused.
  • Upload: sending a file from your computer to a server.
  • Web root: the folder a web server serves pages from.
  • Web shell: a file placed on a server that turns web requests into system commands.
  • WP_Error: WordPress's standard object for carrying an error back to the caller.

Similar reports

View all

Same bug class and techniques, clearest first.

Unrestricted file upload

The lesson behind this report.

An upload feature accepts a file that the server or other users' browsers then treat as code or as something trusted.