Skip to content
RCE Write-up Advanced

Dompdf RCE via Phar Deserialisation

Dompdf v2.0.0 failed to return after validating protocols in registerFont(), allowing the use of phar:// and data:// wrappers. An attacker could write a polyglot TrueType-Phar file to disk and then trigger deserialisation via phar://, leading to remote code execution if a PHP deserialisation gadget is present.

Marcio Almeida 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.

Marcio Almeida, 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:// and data:// were still passed to Helpers::getFileContent().

Impact

An attacker could achieve remote code execution, but only if the application runs on PHP <= 7.x and has a library with a known deserialisation gadget.

What the attacker needed

Dompdf v2.0.0 or below; PHP <= 7.x; A library with a deserialisation gadget; Ability to send requests to the app

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. Send a request using the data:// protocol to write a polyglot TrueType-Phar file to disk.
  2. Send a second request using the phar:// protocol pointing to the uploaded file to trigger deserialisation.
  3. On successful deserialisation, a webshell is written 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' statement meant that a security check could be bypassed, letting an attacker use special URL schemes to write a malicious file and then trigger code execution. This only works if the application uses an old PHP version and has another library with a known code-execution gadget.

What is RCE?

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

More by Marcio Almeida

View all

2 more disclosed reports, best first.

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.