Skip to content
XSS Write-up Advanced

DOMPurify XSS via selectedcontent re-clone

DOMPurify 3.4.4 allowed the selectedcontent element by default, so a browser could re-clone an XSS payload from an option element after DOMPurify had already sanitised that part of the tree. An attacker could therefore get script to run in applications that sanitise attacker-controlled HTML and insert the result into the page.

github.com

Published on github.com

DOMPurify 3.4.4 allows selectedcontent by default, allowing a chain in which browsers "re-clone" an XSS payload after sanitization, effectively bypassing DOMPurify.

The author, on github.com

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

DOMPurify sanitised a browser-generated clone of the selected option but did not re-sanitise it after the browser refreshed that clone from the original option, which it had already walked past.

Impact

A default-configuration DOMPurify sanitizer bypass resulting in XSS, affecting apps that sanitise attacker-controlled HTML with the string-input path and insert the result into the page; reproduced in Chromium and WebKit but not Safari or Firefox.

What the attacker needed

DOMPurify 3.4.4 with default config; string-input sanitize path; output inserted via innerHTML; Chromium or WebKit browser

The fix

The issue was fixed in DOMPurify 3.4.5.

How it was found

  1. Build HTML containing a select with a button and selectedcontent element plus a selected option holding an image with an error handler.
  2. Pass the HTML to DOMPurify's sanitize function and log the returned string.
  3. Insert the returned string into the page via innerHTML.
  4. Observe that the handler fires before the browser strips it from the displayed clone.

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 untrusted HTML so dangerous parts like event handlers are removed before the page displays it. Here the browser itself quietly rebuilt a cleaned element from another part of the page after cleaning had finished, bringing the dangerous handler back. Because the library did not check that rebuilt copy again, the malicious code could run.

What is XSS?

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

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.