Skip to content
XSS Write-up Advanced

DOM Purify - untrusted Node bypass

DOMPurify's node iterator did not include processing instructions, so an XML processing instruction inside an SVG could survive sanitisation and be reinterpreted by the HTML parser as markup containing an event handler. An attacker could use this to run script on a page that sanitised untrusted nodes, even where a CSP blocked direct exploitation of the uploaded file.

Vsevolod Kokorin Follow

Published on blog.slonser.info

In this article, I aim to elucidate a deficiency in the implementation of DOMPurify that I recently uncovered. While it may not pertain to the most common use cases of this library, I found it to be a compelling discovery worthy of exploration.

Vsevolod Kokorin (slonser_), on blog.slonser.info

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 sanitiser's node iterator filter omitted processing instruction nodes, and the HTML parser's different comment-closing rules let the leftover instruction be reinterpreted as markup.

Impact

Script execution was possible on the embedding page despite the uploaded file's own CSP.

What the attacker needed

Application sanitises a DOM node, not a string; attacker can upload an SVG file; victim loads the page that sanitises it

How it was found

  1. Create an SVG file containing an XML processing instruction that includes an image tag with an event handler.
  2. Upload the file and pass its link to the function that builds an iframe and sanitises the resulting node.
  3. The processing instruction survives sanitisation and the browser parses it as a comment ending at the first closing angle bracket, exposing the image tag.
  4. The event handler fires, showing an alert.

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.

DOMPurify is a library that cleans HTML so dangerous parts are removed before a page shows it. It walks through the page structure looking only at certain kinds of items, and it was skipping one kind called a processing instruction, which is a special instruction used in XML documents. When that item was later read as normal HTML, the browser treated part of it as a real tag with an event handler, so script ran.

What is XSS?

Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.

More by Vsevolod Kokorin

View all

2 more disclosed reports, best first.

More from DOMPurify

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Cross-site scripting (XSS)

The lesson behind this report.

Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.