{"id":"GHSA-m9xh-6747-9r6f","summary":"svg-sanitizer: Mixed-case xlink:HrEf skips the `\u003cuse\u003e` nesting-DoS check in Resolver::processReferences","details":"## Summary\n\n`Resolver::processReferences()` collects `\u003cuse\u003e` elements with the XPath predicate `use[@href or @xlink:href]`, which is case sensitive. A `\u003cuse\u003e` element written as `xlink:HrEf` is therefore never added to the reference graph, so the nesting-DoS nullification never marks it for removal. `Sanitizer::cleanHrefAttributes()` then runs later in the same pass and rewrites `xlink:HrEf` back to the canonical `xlink:href`. The sanitizer hands back a fully live nesting bomb that it would have stripped completely had the input used canonical casing.\n\nThis is the mirror image of CVE-2025-55166: that fix made href *value* checking case insensitive, but the `\u003cuse\u003e` reference graph still selects nodes case sensitively.\n\n## Where it is\n\n`src/ElementReference/Resolver.php:97-118`, the case-sensitive node selection:\n\n```php\n$useNodeName = $this-\u003exPath-\u003ecreateNodeName('use');\nforeach ($this-\u003esubjects as $subject) {\n    $useElements = $this-\u003exPath-\u003equery(\n        $useNodeName . '[@href or @xlink:href]',\n        $subject-\u003egetElement()\n    );\n```\n\n`src/Sanitizer.php:479-504`, the normalization that happens afterwards and makes the attribute live again:\n\n```php\n// in case the attribute name is `HrEf`/`xlink:HrEf`, adjust it to `href`/`xlink:href`\nif (!in_array($attribute-\u003enodeName, $this-\u003eallowedAttrs, true)\n    && in_array(strtolower($attribute-\u003enodeName), $this-\u003eallowedAttrs, true)\n) {\n    $element-\u003eremoveAttribute($attribute-\u003enodeName);\n    $element-\u003esetAttribute(strtolower($attribute-\u003enodeName), $attribute-\u003evalue);\n}\n```\n\nOrdering is the whole bug. `Sanitizer::sanitize()` builds the resolver graph first and normalizes attribute casing second, so the graph is built against names the sanitizer is about to change.\n\n## Impact\n\nAnyone who can submit an SVG to an application that sanitizes it with this library and then serves it. No privileges beyond being able to upload or paste an SVG. The output is the project's own `tests/data/useDosTest.svg` nesting structure, intact, with canonical `xlink:href` attributes, which is exactly the input the `useNestingLimit` machinery exists to defuse.\n\n## Proof of concept\n\nAgainst a clean clone of tag `0.22.0`. The only change to the input is rewriting `xlink:href` to `xlink:HrEf` in the project's own DoS fixture.\n\n```php\n\u003c?php\nspl_autoload_register(function ($class) {\n    $p = 'enshrined\\\\svgSanitize\\\\';\n    if (strpos($class, $p) !== 0) return;\n    $rel = str_replace('\\\\', '/', substr($class, strlen($p)));\n    $f = __DIR__ . '/svgsan/src/' . $rel . '.php';\n    if (file_exists($f)) require $f;\n});\n$orig = file_get_contents(__DIR__ . '/svgsan/tests/data/useDosTest.svg');\n$mut  = str_replace('xlink:href', 'xlink:HrEf', $orig);\n\nfunction run($label, $input) {\n    $s = new \\enshrined\\svgSanitize\\Sanitizer();\n    $s-\u003eremoveRemoteReferences(true);\n    $out = $s-\u003esanitize($input);\n    echo \"[$label]\\n\";\n    echo \"  output \u003cuse  count : \", substr_count($out, '\u003cuse '), \"\\n\";\n    echo \"  output xlink:href  : \", (strpos($out,'xlink:href')!==false?'YES':'NO'), \"\\n\";\n    echo \"  output xlink:HrEf  : \", (strpos($out,'xlink:HrEf')!==false?'YES':'NO'), \"\\n\";\n}\nrun('canonical xlink:href (control)', $orig);\nrun('mixed-case xlink:HrEf (attack)', $mut);\n```\n\nObserved on PHP 8.5.9:\n\n```text\norig use count: 201\nmutated input has xlink:HrEf: YES\n\n[canonical xlink:href (control)]\n  output \u003cuse  count : 0\n  output xlink:href  : NO\n  output xlink:HrEf  : NO\n[mixed-case xlink:HrEf (attack)]\n  output \u003cuse  count : 201\n  output xlink:href  : YES\n  output xlink:HrEf  : NO\n```\n\n201 to 0 on canonical input, 201 to 201 on mixed-case input, and the output attribute name comes back canonical either way. To be precise about what I measured: I measured the nullification being skipped and the attribute being re-canonicalized. I did not measure renderer memory or CPU on the resulting file, so the downstream cost is whatever you already assign to `useDosTest.svg`.\n\n## Suggested fix\n\nStop matching attribute names case sensitively when the reference graph is built. Either select every descendant `use` and resolve the href in PHP with a case-insensitive local-name lookup (an extension of `Helper::getElementHref()` at `Helper.php:10-19` is the smallest change), or move the `cleanHrefAttributes()` canonicalization so it runs before `$this-\u003eelementReferenceResolver-\u003ecollect()` rather than after, so the resolver only ever sees `href` and `xlink:href`. The second option also removes the general class of bug where the graph and the cleaner disagree about a node's identity.","aliases":["CVE-2026-107381"],"modified":"2026-10-08T20:00:06.562026594Z","published":"2026-10-08T19:41:10Z","database_specific":{"nvd_published_at":null,"cwe_ids":["CWE-178","CWE-400"],"severity":"MODERATE","github_reviewed":true,"github_reviewed_at":"2026-10-08T19:41:10Z"},"references":[{"type":"WEB","url":"https://github.com/darylldoyle/svg-sanitizer/security/advisories/GHSA-m9xh-6747-9r6f"},{"type":"WEB","url":"https://github.com/darylldoyle/svg-sanitizer/commit/2dff6628314de8519155b7feb218bbe132785757"},{"type":"PACKAGE","url":"https://github.com/darylldoyle/svg-sanitizer"},{"type":"WEB","url":"https://github.com/darylldoyle/svg-sanitizer/releases/tag/1.0.0"}],"affected":[{"package":{"name":"enshrined/svg-sanitize","ecosystem":"Packagist","purl":"pkg:composer/enshrined/svg-sanitize"},"ranges":[{"type":"ECOSYSTEM","events":[{"introduced":"0"},{"fixed":"1.0.0"}]}],"versions":["0.1.0","0.1.1","0.1.2","0.1.3","0.1.4","0.1.5","0.1.6","0.10.0","0.11.0","0.12.0","0.13.0","0.13.1","0.13.2","0.13.3","0.14.0","0.14.1","0.15.0","0.15.1","0.15.2","0.15.3","0.15.4","0.16.0","0.17.0","0.18.0","0.19.0","0.2.0","0.2.1","0.20.0","0.21.0","0.22.0","0.3.0","0.4.0","0.4.1","0.5.0","0.5.1","0.5.2","0.5.3","0.5.3.1","0.6.0","0.7.0","0.7.1","0.7.2","0.8.0","0.8.1","0.8.2","0.9.0","0.9.1","0.9.2"],"database_specific":{"last_known_affected_version_range":"\u003c= 0.22.0","source":"https://github.com/github/advisory-database/blob/main/advisories/github-reviewed/2026/10/GHSA-m9xh-6747-9r6f/GHSA-m9xh-6747-9r6f.json"}}],"schema_version":"1.9.0","severity":[{"type":"CVSS_V3","score":"CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:N/I:N/A:H"}]}