CVE-2024-25117 (published 2024-02-21T17:15Z)

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.


Weakness information:
cwe_id: NVD-CWE-noinfo
cwe_name: Insufficient Information
description: There is insufficient information about the issue to classify it; details are unkown or unspecified.
extended_description: Insufficient Information

Fix information:
repo_url: https://github.com/dompdf/php-svg-lib
commit_details: repo_url: https://github.com/dompdf/php-svg-lib
author: Brian Sweeney
author_date: 2024-02-07 07:49:40-05:00
msg: Remove invalid condition around image href validation
repository: repo_url: https://github.com/dompdf/php-svg-lib
repo_name: dompdf/php-svg-lib
description: SVG file parsing / rendering library
repo_language: PHP
owner: dompdf
file_changes: filename: Image.php
change_type: ModificationType.MODIFY
diff: @@ -58,14 +58,12 @@ class Image extends AbstractTag
 
         $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);

programming_language: PHP
repo_url: https://github.com/dompdf/php-svg-lib
commit_details: repo_url: https://github.com/dompdf/php-svg-lib
author: Brian Sweeney
author_date: 2024-01-31 09:55:55-05:00
msg: 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.
repository: repo_url: https://github.com/dompdf/php-svg-lib
repo_name: dompdf/php-svg-lib
description: SVG file parsing / rendering library
repo_language: PHP
owner: dompdf
file_changes: filename: Document.php
change_type: ModificationType.MODIFY
diff: @@ -202,7 +202,7 @@ class Document extends AbstractTag
     {
         $surface = $this->getSurface();
 
-        $style = new DefaultStyle();
+        $style = new DefaultStyle($this);
         $style->inherit($this);
         $style->fromAttributes($attributes);
 

programming_language: PHP
filename: Style.php
change_type: ModificationType.MODIFY
diff: @@ -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 @@ class Style
                         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 @@ class Style
                         $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;
                 }

programming_language: PHP
filename: AbstractTag.php
change_type: ModificationType.MODIFY
diff: @@ -119,7 +119,7 @@ abstract class AbstractTag
      * @return Style
      */
     protected function makeStyle($attributes) {
-        $style = new Style();
+        $style = new Style($this->document);
         $style->inherit($this);
         $style->fromStyleSheets($this, $attributes);
         $style->fromAttributes($attributes);

programming_language: PHP
filename: Image.php
change_type: ModificationType.MODIFY
diff: @@ -58,8 +58,14 @@ class Image extends AbstractTag
 
         $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);

programming_language: PHP