GitHub Advisoryadvisory · Packagist

GHSA-97m3-52wr-xvv2 Dompdf's usage of vulnerable version of phenx/php-svg-lib leads to restriction bypass and potential RCE

CRITICAL Published 2024-02-22 Modified 2024-02-23 Official page ↗
Ecosystem
Packagist
Packages
phenx/php-svg-lib
Severity
Critical
CVSS vector
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:C/C:H/I:H/A:H
Weaknesses
CWE-502, CWE-73
Reviewed
2024-02-22

Affected packages

• Packagist phenx/php-svg-lib: < 0.5.2 → fixed in 0.5.2

Description

Summary A lack of sanitization/check in the font path returned by php-svg-lib, in the case of a inline CSS font defined, that will be used by Cpdf to open a font will be passed to a `file_exists` call, which is sufficient to trigger metadata unserializing on a PHAR file, through the phar:// URL handler on PHP fonts[$font]) && file_exists("$dir/$metrics_name")) { ``` Passing a font named `phar:///foo/bar/baz.phar/test` will set the value of $name to `test` and $dir to `phar:///foo/bar/baz.phar`, which once reconstructed will call file_exists on `phar:///foo/bar/baz.phar/test.ufm`. That allows to deserialize the `baz.phar` arbitrary file that contains a `test.ufm` file in the archive. PoC Consider the following, minimal PHP code : ``` loadHtml($_GET['payload']); $dompdf->setPaper('A4', 'landscape'); $options = $dompdf->getOptions(); $options->setAllowedProtocols([]); $dompdf->render(); $dompdf->stream(); ``` With payload being this html file : ``` ``` with the base64 image being : ``` My ``` A connection on ftp://blakl.is:21/ will occur, bypassing the allowed protocols. Impact An attacker might be able to exploit the vulnerability to call arbitrary URL with arbitrary protocols, if they can force dompdf to parse a SVG with an inline CSS property using a malicious font-family. In PHP versions before 8.0.0, it leads to arbitrary unserialize, that will leads at the very least to an arbitrary file deletion, and might leads to remote code execution, depending on classes that are available.

Related

Weakness · CWE (2)

  • CWE-502 Deserialization of Untrusted Data weakness
  • CWE-73 External Control of File Name or Path weakness

References