PortSwigger researcher bypasses six of eight popular SVG sanitizers
Gareth Heyes found bypasses in six SVG sanitizer libraries, including namespace confusion, XSLT stylesheets and Safari GIF import tricks.
Reported by PortSwigger Research
First reported Summary updated
- Public PoC
- Yes
- Exploited
- Not known
- Severity
- Not rated
What happened
A researcher tested eight widely used SVG sanitizer libraries and found ways around six of them.1
One bypass switches an element's XML namespace to XHTML so the browser renders it as HTML inside the SVG, allowing a JavaScript URL.1
Another technique gets JavaScript execution from a self-contained XSLT stylesheet loaded through a data URL, without a separate file.1
In Firefox, a Link response header carrying a data URL stylesheet can execute script even when the response body is harmless XML.1
Safari can import image files as SVG, so a GIF containing a payload can be pulled in with an element and bypass three of the libraries.1
Who is affected
- mattkrick/sanitise-svg1
- Borewit/svg-sanitizer1
- bgalek/safe-svg1
- alnorris/SVG-Sanitizer1
- cloudflare/svg-hush1
- jams2/py-svg-hush1
Is there a public exploit?
Yes, public The post includes working payloads and a Hackvertor link for the XSLT header technique.1
Exploited in the wild?
Not known None of the sources reports attacks using it so far.
What to do
- The researcher notes that DOMPurify and darylldoyle/svg-sanitizer resisted every technique in the post.1
For bug hunters
The underlying bug class is cross-site scripting reached through SVG sanitizer bypasses. Sanitizers that parse XML and then re-serialize, or that match element names case-sensitively, are common weak points. Look at any program that accepts SVG uploads and renders them, especially where sanitizer output is served from the application origin. Test namespace switching, foreignObject casing, animate on links, and XSLT or stylesheet loading paths.
What to test
- Upload SVG with an element switched to the XHTML namespace and a JavaScript URL
- Try foreignObject in different letter cases to defeat querySelectorAll matching
- Animate a link href into a JavaScript URL and trigger it after a delay
- Check whether response headers or data URL stylesheets can load XSLT in Firefox
Written by bugbounty.wiki with AI from its source. Every statement above comes with a quote we checked against the source it cites (the numbers link to it); anything we could not check was left out. It can still be wrong, so read the coverage before relying on a detail.
Coverage
The article this story is based on. Each headline opens the outlet's own article.
-
1
PortSwigger Research
Scalable Vector Grief“SVG is an image format that can contain scripts, event handlers, links, animations and even embedded HTML, so applications that accept SVG uploads usually run…”