php-svg-lib possible DoS caused by infinite recursion when parsing SVG document
Description
php-svg-lib is an SVG file parsing / rendering library. Prior to version 0.5.1, when parsing the attributes passed to a use tag inside an svg document, an attacker can cause the system to go to an infinite recursion. Depending on the system configuration and attack pattern this could exhaust the memory available to the executing process and/or to the server itself. An attacker sending multiple request to a system to render the above payload can potentially cause resource exhaustion to the point that the system is unable to handle incoming request. Version 0.5.1 contains a patch for this issue.
Affected packages
Versions sourced from the GitHub Security Advisory.
| Package | Affected versions | Patched versions |
|---|---|---|
phenx/php-svg-libPackagist | < 0.5.1 | 0.5.1 |
Affected products
1- Range: < 0.5.1
Patches
188163cbe562dPrevent circular reference in use elements
1 file changed · +20 −0
src/Svg/Tag/UseTag.php+20 −0 modified@@ -14,12 +14,19 @@ class UseTag extends AbstractTag protected $y = 0; protected $width; protected $height; + protected $instances = 0; /** @var AbstractTag */ protected $reference; protected function before($attributes) { + $this->instances++; + if ($this->instances > 1) { + //TODO: log circular reference error state + return; + } + if (isset($attributes['x'])) { $this->x = $attributes['x']; } @@ -52,6 +59,9 @@ protected function before($attributes) } protected function after() { + if ($this->instances > 0) { + return; + } parent::after(); if ($this->reference) { @@ -63,6 +73,11 @@ protected function after() { public function handle($attributes) { + if ($this->instances > 1) { + //TODO: log circular reference error state + return; + } + parent::handle($attributes); if (!$this->reference) { @@ -87,6 +102,11 @@ public function handle($attributes) public function handleEnd() { + $this->instances--; + if ($this->instances > 0) { + return; + } + parent::handleEnd(); if (!$this->reference) {
Vulnerability mechanics
Generated on May 9, 2026. Inputs: CWE entries + fix-commit diffs from this CVE's patches. Citations validated against bundle.
References
4- github.com/advisories/GHSA-ff5x-7qg5-vwf2ghsaADVISORY
- nvd.nist.gov/vuln/detail/CVE-2023-50251ghsaADVISORY
- github.com/dompdf/php-svg-lib/commit/88163cbe562d9b391b3a352e54d9c89d02d77ee0ghsax_refsource_MISCWEB
- github.com/dompdf/php-svg-lib/security/advisories/GHSA-ff5x-7qg5-vwf2ghsax_refsource_CONFIRMWEB
News mentions
0No linked articles in our index yet.