Описание
Dompdf: Local file read due to improper file path validation in SVG images encoded as data-URI
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
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
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
Inside the base64 payload is an SVG containing the <image> element that points to the target file:
Listing 4. Pointing to the target file
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
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-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
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
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)
Listing 10. An example attack on the vulnerable code
Figure 1. The image was read successfully
Credits
Nikita Sveshnikov (Positive Technologies)
Пакеты
dompdf/dompdf
< 3.1.6
3.1.6
Связанные уязвимости
Dompdf is an HTML to PDF converter for PHP. In versions 3.15 and prior, aAn attacker who controls the HTML input can bypass this restriction by embedding a target file path inside an SVG image delivered through a data: URI, because dompdf processes the SVG twice and the second pass does not enforce the same protections as the first. When rendering, dompdf hands the SVG to the separate php-svg-lib library with external references forced on, and that library has no knowledge of the chroot directory, blocks only the phar:// scheme, and ultimately reads the referenced file with no path or protocol validation. This lets an external, unauthenticated attacker read arbitrary image files from the server's file system in the default configuration. This issue has been fixed in version 3.16.
Dompdf is an HTML to PDF converter for PHP. In versions 3.15 and prior, aAn attacker who controls the HTML input can bypass this restriction by embedding a target file path inside an SVG image delivered through a data: URI, because dompdf processes the SVG twice and the second pass does not enforce the same protections as the first. When rendering, dompdf hands the SVG to the separate php-svg-lib library with external references forced on, and that library has no knowledge of the chroot directory, blocks only the phar:// scheme, and ultimately reads the referenced file with no path or protocol validation. This lets an external, unauthenticated attacker read arbitrary image files from the server's file system in the default configuration. This issue has been fixed in version 3.16.
Dompdf is an HTML to PDF converter for PHP. In versions 3.15 and prior ...
Уязвимость PHP-библиотеки генерации PDF-документов из HTML-разметки и CSS-стилей Dompdf, позволяющая нарушителю раскрыть защищаемую информацию