VYPR
Moderate severityNVD Advisory· Published Feb 21, 2024· Updated Aug 28, 2024

php-svg-lib lacks path validation on font through SVG inline styles

CVE-2024-25117

Description

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.

Affected packages

Versions sourced from the GitHub Security Advisory.

PackageAffected versionsPatched versions
phenx/php-svg-libPackagist
< 0.5.20.5.2

Affected products

1

Patches

2
732faa9fb430

Remove invalid condition around image href validation

https://github.com/dompdf/php-svg-libBrian SweeneyFeb 7, 2024via ghsa
1 file changed · +6 8
  • src/Svg/Tag/Image.php+6 8 modified
    @@ -58,14 +58,12 @@ public function start($attributes)
     
             $this->document->getSurface()->transform(1, 0, 0, -1, 0, $height);
     
    -        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;
    -            }
    +        $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;
             }
     
             $this->document->getSurface()->drawImage($this->href, $this->x, $this->y, $this->width, $this->height);
    
8ffcc41bbde3

Update resource validation logic

https://github.com/dompdf/php-svg-libBrian SweeneyJan 31, 2024via ghsa
4 files changed · +27 14
  • src/Svg/Document.php+1 1 modified
    @@ -202,7 +202,7 @@ protected function before($attributes)
         {
             $surface = $this->getSurface();
     
    -        $style = new DefaultStyle();
    +        $style = new DefaultStyle($this);
             $style->inherit($this);
             $style->fromAttributes($attributes);
     
    
  • src/Svg/Style.php+17 10 modified
    @@ -18,6 +18,7 @@ class Style
         const TYPE_ANGLE = 4;
         const TYPE_NUMBER = 5;
     
    +    private $_document;
         private $_parentStyle;
     
         public $color;
    @@ -43,6 +44,12 @@ class Style
         public $fontStyle = 'normal';
         public $textAnchor = 'start';
     
    +    public function __construct($document = null) {
    +        if ($document !== null) {
    +            $this->_document = $document;
    +        }
    +    }
    +
         protected function getStyleMap()
         {
             return array(
    @@ -139,16 +146,6 @@ public function fromStyleSheets(AbstractTag $tag, $attributes) {
                             break;
                         }
                     }
    -
    -                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"]);
    -                }
                 }
             }
     
    @@ -185,6 +182,16 @@ protected function fillStyles($styles)
                             $value = $styles[$from];
                     }
     
    +                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;
    +                    }
    +                }
    +
                     if ($value !== null) {
                         $this->$to = $value;
                     }
    
  • src/Svg/Tag/AbstractTag.php+1 1 modified
    @@ -119,7 +119,7 @@ public function getStyle()
          * @return Style
          */
         protected function makeStyle($attributes) {
    -        $style = new Style();
    +        $style = new Style($this->document);
             $style->inherit($this);
             $style->fromStyleSheets($this, $attributes);
             $style->fromAttributes($attributes);
    
  • src/Svg/Tag/Image.php+8 2 modified
    @@ -58,8 +58,14 @@ public function start($attributes)
     
             $this->document->getSurface()->transform(1, 0, 0, -1, 0, $height);
     
    -        if (\strtolower(\substr($this->href, 0, 7)) === "phar://" || ($this->document->allowExternalReferences === false && \strtolower(\substr($this->href, 0, 5) !== "data:"))) {
    -            return;
    +        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;
    +            }
             }
     
             $this->document->getSurface()->drawImage($this->href, $this->x, $this->y, $this->width, $this->height);
    

Vulnerability mechanics

Generated on May 9, 2026. Inputs: CWE entries + fix-commit diffs from this CVE's patches. Citations validated against bundle.

References

5

News mentions

0

No linked articles in our index yet.