php-svg-lib lacks path validation on font through SVG inline styles
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.
| Package | Affected versions | Patched versions |
|---|---|---|
phenx/php-svg-libPackagist | < 0.5.2 | 0.5.2 |
Affected products
1- Range: < 0.5.2
Patches
2732faa9fb430Remove invalid condition around image href validation
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);
8ffcc41bbde3Update resource validation logic
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- github.com/advisories/GHSA-f3qr-qr4x-j273ghsaADVISORY
- nvd.nist.gov/vuln/detail/CVE-2024-25117ghsaADVISORY
- github.com/dompdf/php-svg-lib/commit/732faa9fb4309221e2bd9b2fda5de44f947133aaghsax_refsource_MISCWEB
- github.com/dompdf/php-svg-lib/commit/8ffcc41bbde39f09f94b9760768086f12bbdce42ghsax_refsource_MISCWEB
- github.com/dompdf/php-svg-lib/security/advisories/GHSA-f3qr-qr4x-j273ghsax_refsource_CONFIRMWEB
News mentions
0No linked articles in our index yet.