Skip to content
RCE Write-up Advanced

CVE202241343 RCE via Phar Deserialisation (Dompdf)

Dompdf v2.0.0's font registration function lacked return statements after protocol validation, allowing the phar:// wrapper to reach file_get_contents. An attacker could upload a polyglot TrueType-Phar file via data:// and then trigger deserialisation via phar://, leading to remote code execution if a gadget chain exists.

TantoSecurity Follow

Published on tantosec.com

Dompdf is a popular PHP library used for rendering PDF files from HTML. Tanto Security disclosed a vulnerability in Dompdf affecting version 2.0.0 and below.

Tanto Security team (@TantoSecurity), on tantosec.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.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the registerFont() function in Dompdf v2.0.0 omitted return statements after protocol validation, so disallowed protocols such as phar:// were still passed to file_get_contents().

Impact

An attacker could achieve remote code execution, but only if the application runs on PHP <= 7.x and a known deserialisation gadget exists in one of its libraries.

What the attacker needed

Dompdf v2.0.0 or below; PHP <= 7.x; A deserialisation gadget in a library; Ability to send HTML to Dompdf

The fix

The vulnerability was fixed in Dompdf v2.0.1 by adding the missing return statements after protocol validation.

How it was found

  1. Generate a polyglot TrueType-Phar file containing a deserialisation gadget payload.
  2. Send a first request using the data:// protocol to write the polyglot file to the fonts cache directory.
  3. Send a second request using the phar:// protocol pointing to the uploaded file to trigger deserialisation.
  4. The deserialisation gadget writes a PHP webshell to the public web directory.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

Dompdf is a PHP library that turns HTML into PDFs. A missing 'return' in its code let attackers use a special file path (phar://) to make the server load a malicious file. If the application also has a known code gadget, this can let the attacker run their own commands on the server.

What is RCE?

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.

Similar reports

View all

Same bug class and techniques, clearest first.

Remote code execution

The lesson behind this report.

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.