CVE-2024-25117 (PHP, published 2024-02-21T17:15Z)
Description: value: php-svg-lib is a scalable vector graphics (SVG) file parsing/rendering library. Prior to version 0.5.2, php-svg-lib fails to validate that font-family doesn't contain a PHAR url, which might leads to RCE on PHP < 8.0, and doesn't validate if external references are allowed. This might leads to bypass of restrictions or RCE on projects that are using it, if they do not strictly revalidate the fontName that is passed by php-svg-lib. The `Style::fromAttributes(`), or the `Style::parseCssStyle()` should check the content of the `font-family` and prevents it to use a PHAR url, to avoid passing an invalid and dangerous `fontName` value to other libraries. The same check as done in the `Style::fromStyleSheets` might be reused. Libraries using this library as a dependency might be vulnerable to some bypass of restrictions, or even remote code execution, if they do not double check the value of the `fontName` that is passed by php-svg-lib. Version 0.5.2 contains a fix for this issue.
Severity: nan (CVSS v3 base score: )
Weakness: NVD-CWE-noinfo \u2014 Insufficient Information
There is insufficient information about the issue to classify it; details are unkown or unspecified.
Repository: https://github.com/dompdf/php-svg-lib
Files changed:
src/Svg/Document.php
src/Svg/Style.php
src/Svg/Tag/AbstractTag.php
src/Svg/Tag/Image.php
Commit message: Update resource validation logic

The previous logic did not validate the font-family when set by attribute. To accommodate style validation across all sources the Style class now accepts the Document during construction so that it has access to the allowExternalReferences property regardless of style source.


Vulnerable code:
        $style = new DefaultStyle();

                if (
                    \array_key_exists("font-family", $styles)
                    && (
                        \strtolower(\substr($this->href, 0, 7)) === "phar://"
                        || ($this->document->allowExternalReferences === false && \strtolower(\substr($this->href, 0, 5)) !== "data:")
                    )
                ) {
                    unset($style["font-family"]);
                }
        $style = new Style();
        if (\strtolower(\substr($this->href, 0, 7)) === "phar://" || ($this->document->allowExternalReferences === false && \strtolower(\substr($this->href, 0, 5) !== "data:"))) {
            return;

Fixed code:
        $style = new DefaultStyle($this);
    private $_document;
    public function __construct($document = null) {
        if ($document !== null) {
            $this->_document = $document;
        }
    }

                if ($from === "font-family") {
                    $scheme = \strtolower(parse_url($value, PHP_URL_SCHEME) ?: "");
                    if (
                        $scheme === "phar" || \strtolower(\substr($value, 0, 7)) === "phar://"
                        || ($this->_document !== null && $this->_document->allowExternalReferences === false && $scheme !== "data")
                    ) {
                        continue;
                    }
                }

        $style = new Style($this->document);
        if ($from === "font-family") {
            $scheme = \strtolower(parse_url($this->href, PHP_URL_SCHEME) ?: "");
            if (
                $scheme === "phar" || \strtolower(\substr($this->href, 0, 7)) === "phar://"
                || ($this->document->allowExternalReferences === false && $scheme !== "data")
            ) {
                return;
            }