External Control of System or Configuration Setting Affecting phenx/php-svg-lib package, versions <0.5.1


Severity

Recommended
0.0
high
0
10

CVSS assessment made by Snyk's Security Team. Learn more

Threat Intelligence

Exploit Maturity
Proof of concept
EPSS
0.15% (52nd percentile)

Do your applications use this vulnerable package?

In a few clicks we can analyze your entire application and see what components are vulnerable in your application, and suggest you quick fixes.

Test your applications
  • Snyk IDSNYK-PHP-PHENXPHPSVGLIB-6125684
  • published14 Dec 2023
  • disclosed12 Dec 2023
  • creditcod3beat

Introduced: 12 Dec 2023

CVE-2023-50252  (opens in a new tab)
CWE-15  (opens in a new tab)

How to fix?

Upgrade phenx/php-svg-lib to version 0.5.1 or higher.

Overview

phenx/php-svg-lib is a library to read, parse and export to PDF SVG files.

Affected versions of this package are vulnerable to External Control of System or Configuration Setting due to improper sanitization of the href attribute from the <use> tag when it is merged with an <image> tag. An attacker can cause an unsafe file read that may lead to PHAR Deserialization vulnerability in PHP versions prior to 8 by manipulating the href attribute.

Workaround

Systems utilizing php-svg-lib can implement input validation using logic similar to the following:

$parser = xml_parser_create("utf-8");
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, false);
xml_set_element_handler(
    $parser,
    function ($parser, $name, $attributes) {
        if (strtolower($name) === "image" || strtolower($name) === "use") {
            $attributes = array_change_key_case($attributes, CASE_LOWER);
            $urls = [];
            $urls[] = $attributes["xlink:href"] ?? "";
            $urls[] = $attributes["href"] ?? "";
            foreach ($urls as $url) {
                if (!empty($url)) {
                    // perform validation here
                }
            }
        }

    // include other tag/attribute validation
},
false

);

if (($fp = fopen($url, "r")) !== false) { while ($line = fread($fp, 8192)) { xml_parse($parser, $line, false); } fclose($fp); xml_parse($parser, "", true); } xml_parser_free($parser);

PoC


<svg width="200" height="200"
  xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
  <image id="phar:///poc.phar" xlink:href="file:///existing/safe/image.png" />
  <use href="phar:///poc.phar" width="500" height="500"/>
</svg>

References

CVSS Scores

version 3.1