Scalable Vector Grief
The author tested eight popular SVG sanitizers and bypassed six of them, achieving JavaScript execution through various techniques such as namespace confusion, animation attributes, XSLT stylesheets, and Safari's image import behaviour. An attacker could upload a malicious SVG that bypasses sanitization and executes JavaScript in the context of the victim's browser.
portswigger.net
Published on portswigger.net
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 them through a sanitizer first. To see how well those sanitizers hold up, I tested the most popular SVG libraries according to ChatGPT:
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the sanitizers fail to account for browser-specific parsing quirks, such as namespace switching, case sensitivity, animation attributes, XSLT processing instructions, and Safari's image import behaviour.
Impact
An attacker could execute arbitrary JavaScript in the context of the victim's browser, potentially leading to data theft or other malicious actions, though some techniques are browser-specific and one relies on a deprecated feature.
What the attacker needed
Victim views the SVG; attacker can upload SVG; sanitizer is vulnerable
The fix
The author notes that DOMPurify and darylldoyle/svg-sanitizer were not bypassed, implying that using those libraries or updating sanitizers to handle these edge cases would mitigate the issue.
How it was found
- Upload an SVG file containing a malicious payload that bypasses the sanitizer.
- The sanitizer processes the SVG but fails to remove the payload.
- The victim views the sanitized SVG in a browser.
- The browser executes the JavaScript embedded in the SVG.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
SVG files are images that can contain scripts, so websites often clean them with a sanitizer before showing them. This research found that many sanitizers miss clever tricks, letting an attacker hide JavaScript in an SVG. When a victim views the image, the script runs and can steal data or perform actions as the victim.
What is XSS?
Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.