Bypassing Firefox's HTML Sanitizer API
Firefox's HTML Sanitizer API incorrectly allowed SVG 'use' elements to import content from absolute same-origin URLs, even when the imported SVG was served with Content-Disposition: attachment. An attacker could upload a malicious SVG and then use the sanitizer to execute arbitrary JavaScript in the context of the target site.
Published on portswigger.net
The HTML Sanitizer is a great new API that allows web developers to filter untrusted HTML natively in the browser rather than use a JavaScript library such as DOM Purify. Microsoft created a similar API called toStaticHTML in 2008 for Internet Explorer but it was riddled with holes and wasn't widely adopted or…
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
The sanitizer's allowlist for SVG 'use' elements permitted absolute same-origin URLs, overlooking that such imports can execute JavaScript even when the imported resource is served as an attachment.
Impact
An attacker could execute arbitrary JavaScript in the context of the target site, potentially leading to account compromise or data theft, if the site allowed SVG uploads and used the vulnerable sanitizer.
What the attacker needed
Target uses HTML Sanitizer API; target allows SVG uploads; uploaded SVG served with Content-Disposition: attachment; attacker can supply HTML to sanitizer
The fix
The issue was fixed by Mozilla, as indicated in the timeline.
How it was found
- Upload an SVG file to the target site that is served with Content-Disposition: attachment.
- Craft HTML containing an SVG 'use' element that references the uploaded SVG via an absolute same-origin URL.
- Pass the crafted HTML through the HTML Sanitizer API.
- The sanitizer fails to remove the 'use' element, and the browser executes the JavaScript from the imported 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.
A sanitizer is a tool that cleans untrusted HTML to remove dangerous parts. Firefox's new sanitizer was supposed to block SVG 'use' elements that load other files, but it missed a case where the file is loaded from the same website using a full web address. This let an attacker run their own code on the site if they could upload an SVG file.
What is XSS?
Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.