Skip to content
XSS Write-up Advanced

Playing with DOMPurify custom elements handling

DOMPurify 3.0.8 with overly permissive CUSTOM_ELEMENT_HANDLING and a custom FORBID_CONTENTS list allowed namespace confusion, enabling an attacker to inject an XSS payload that bypassed the sanitizer.

kevin_mizu Follow

Published on mizu.re

In this article, I will describe a DOMPurify 3.0.8 bypass (fix) I recently discovered when the CUSTOMELEMENTHANDLING and FORBIDCONTENTS configuration options are used together. This issue is not a major concern as it doesn't involve a full DOMPurify bypass using the default configuration.

Mizu (@kevin_mizu), on mizu.re

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 combination of an overly permissive custom element tag name check and a custom FORBID_CONTENTS list that overwrote the default, allowing namespace confusion between the sanitizer and the browser.

What the attacker needed

Application uses DOMPurify 3.0.8; CUSTOM_ELEMENT_HANDLING tagNameCheck is overly permissive; FORBID_CONTENTS is customised and overwrites defaults

The fix

The issue was fixed in DOMPurify by updating the custom element handling to properly filter SVG and MathML elements.

How it was found

  1. Configure DOMPurify with CUSTOM_ELEMENT_HANDLING tagNameCheck set to /.*/ and FORBID_CONTENTS set to an empty string.
  2. Pass a crafted HTML string containing an SVG, annotation-xml, foreignobject, style, and an image with an onerror handler to DOMPurify.sanitize.
  3. Insert the sanitized output into the DOM via innerHTML.
  4. The browser parses the output differently, causing the onerror handler to execute.

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 tool that cleans HTML to remove dangerous code. This report shows that if a developer configures it too loosely, an attacker can sneak in a script that runs when the page loads, because the browser and the cleaner disagree about how to interpret the HTML.

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 kevin_mizu

View all

4 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.