6 of 8 SVG Sanitizers Got Broken. Your “Safe” Image Upload Might Be Running JavaScript
Six of eight popular SVG sanitizers could be bypassed, allowing an attacker to upload a malicious SVG that executes JavaScript when viewed. This stored cross-site scripting could lead to account takeover.
Gareth Heyes at PortSwigger published a post called “Scalable Vector Grief” on 27 October 2026. He took eight popular SVG sanitizers, threw some very creative payloads at them, and got past six.
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 failed to account for obscure SVG and XML features such as namespace switching, animation elements, XSLT stylesheets, and browser-specific behaviours like Safari importing non-SVG files via <use>.
Impact
An attacker could execute arbitrary JavaScript in the context of the vulnerable site, potentially leading to account takeover.
What the attacker needed
Ability to upload SVG files; Victim views the uploaded file
The fix
Use a robust sanitizer like DOMPurify or darylldoyle/svg-sanitizer with an allow-list, serve uploads from a separate domain, and apply a strict Content-Security-Policy.
How it was found
- Upload an SVG file containing a malicious payload, such as a namespace-confused element or an XSLT stylesheet.
- The sanitizer processes the file but fails to strip the dangerous content.
- The sanitized file is stored and served to other users.
- A victim opens the uploaded SVG URL, and the browser executes the embedded JavaScript.
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.
An SVG file is a text-based image format that can contain scripts, similar to a web page. If a website lets you upload an SVG without properly cleaning it, an attacker can hide JavaScript inside the image. When someone views that image, the code runs in their browser as if it came from the website itself, letting the attacker steal data or take over accounts.
What is XSS?
Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.