Skip to content
XSS Advisory Advanced CVE-2026-8539

Script injection in SanitizerAPI (CVE-2026-8539)

The Sanitizer API's setHTML() method fails open when given an invalid SanitizerConfig: instead of leaving the element empty, it inserts the parsed but unsanitized HTML into the live DOM. Event handler attributes then execute, so an attacker-supplied string can run script in the page.

Jungwoo Lee Follow

Originally disclosed on Chrome VRP

  • Fix shipped in 48 days

Report description

setHTML() fails open on invalid SanitizerConfig, inserting unsanitized HTML with active scripts into the live DOM


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://chromium.googlesource.com/chromium/src


The problem

Please describe the technical details of the vulnerability

Summary

Element.setHTML() fails open on invalid SanitizerConfig, inserting unsanitized HTML with active scripts into the live DOM.

When Sanitizer::Create throws a TypeError due to an invalid config (e.g., both elements and removeElements specified), the parsed but unsanitized DocumentFragment is inserted into the DOM. Event handler attributes such as ontoggle and onerror execute JavaScript immediately after insertion.

Chrome Version

  • Tested on Chrome 146.0.7680.164 (Official Build, 64-bit), Linux x86_64
  • Affected on All Chrome versions with the Sanitizer API enabled

Root Cause

SanitizeSafeInternal does not clear fragment on Sanitizer creation failure

File: third_party/blink/renderer/core/sanitizer/sanitizer_api.cc

When SanitizerFromSafeOptions fails, the function returns without clearing the fragment at lines 107–109:

C++
if (exception_state.HadException()) {
    return;  // BUG: does NOT clear root_element
}

The earlier error path in the same function at lines 90–92 correctly clears it:

C++
if (exception_state.HadException()) {
    root_element->setTextContent("");  // CORRECT: clears unsanitized content
    return;
}

The unsanitized fragment is unconditionally inserted into the live DOM. The TypeError propagates to JS, but the DOM is already modified and event handlers have already fired.

Reproduction

Sanitizer::setFrom() returns false when the config is invalid per spec:

  • Both elements and removeElements present (sanitizer.cc:1170)
  • Both attributes and removeAttributes present (sanitizer.cc:1175)
  • elements and replaceWithChildrenElements overlap (sanitizer.cc:1184)
  • Duplicate entries in any list (sanitizer.cc:1058)

Sanitizer::Create then throws TypeError at sanitizer.cc:65, entering the fail-open path.

Example

JavaScript
var el = document.createElement('div');
document.body.appendChild(el);
try {
  el.setHTML(
    '<details open ontoggle="alert(document.domain)"><summary>x</summary></details>' +
    '<img src=x onerror="alert(\'onerror XSS\')">',
    { sanitizer: { elements: ['div'], removeElements: ['span'] } }
  );
} catch(e) { console.log(e.message); }
console.log(el.innerHTML);

Expected: TypeError thrown, element remains empty and no script execution.

Actual: TypeError thrown but element contains unsanitized HTML. alert(document.domain) fires via ontoggle. alert('onerror XSS') fires via onerror. <script>, <iframe>, javascript: URLs all survive in the DOM.

Suggested Fix

Clear fragment on exception in SanitizeSafeInternal

The bug is that the error path at lines 107–109 does not clear the fragment, unlike the correct pattern at lines 90–92. The fix is to add root_element->setTextContent("") so all error paths consistently clear unsanitized content.

File: third_party/blink/renderer/core/sanitizer/sanitizer_api.cc

SanitizeSafeInternal, around line 107:

Diff
  const Sanitizer* sanitizer =
      SanitizerFromSafeOptions(options, exception_state);

  if (exception_state.HadException()) {
+   root_element->setTextContent("");
    return;
  }

This matches the existing correct pattern already used earlier:

C++
// Lines 90-92 (SanitizeSafeInternal)
if (exception_state.HadException()) {
    root_element->setTextContent("");  // Already correctly clears fragment here
    return;
}

Impact analysis

setHTML() fails to sanitize HTML when given an invalid SanitizerConfig. The unsanitized content, including event handlers and script tags, is inserted into the live DOM and executes. This violates the spec guarantee that setHTML() always strips XSS-unsafe content.


The cause

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

146.0.7680.164 stable

Is the security issue related to a crash?

No, it is not related to a crash.

Choose the type of vulnerability

Cross-site scripting (XSS)

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

Jungwoo Lee (@physicube) and Wongi Lee (@_qwerty_po)

The original report as published on the Chromium issue tracker, by Jungwoo Lee (@physicube) and Wongi Lee (@_qwerty_po). 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 an early-return error path in SanitizeSafeInternal that does not clear the parsed fragment when Sanitizer creation throws, unlike the earlier error path that does clear it.

Impact

Unsanitised HTML including event handlers, script tags, iframes and javascript: URLs reaches the live DOM and executes, breaking the spec guarantee that setHTML() strips XSS-unsafe content.

What the attacker needed

Chrome with Sanitizer API enabled; Page code calls setHTML() with attacker HTML; Attacker controls the HTML string passed in

The fix

The error path should clear the fragment with setTextContent("") so every failure path removes unsanitized content, matching the existing correct pattern.

How it was found

  1. Create a div element and append it to the page body.
  2. Call setHTML() on it with HTML containing event handler attributes and an invalid SanitizerConfig that lists both elements and removeElements.
  3. Observe that a TypeError is thrown but the element still contains the unsanitized HTML.
  4. Observe that the event handler attributes fire and run script.

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 HTML before it is put on a page, removing anything that can run code. Here, when the page passed a configuration the sanitiser rejected, the code returned early without emptying the already-parsed content, so the dirty HTML was still added to the page. That let event handlers such as onerror run JavaScript, which is the classic cross-site scripting problem.

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 Jungwoo Lee

View all

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