Skip to content
XSS Disclosed report Advanced

Serialization bug in <noscript> may lead to sanitizers bypass and XSS

Chromium's HTML serializer incorrectly serializes the contents of a <noscript> element when scripting is disabled, treating it as raw text instead of escaping it. This allows an attacker to craft markup that, after sanitization by DOMPurify, becomes executable HTML containing an event handler, leading to XSS.

Michał Bentkowski Follow

Originally disclosed on Mozilla

  • Fixed in 30 days
  • Paid in 36 days
  • Disclosed after 30 days
Text
According to HTML standard [1], the serialization of text nodes within NOSCRIPT element depends on whether scripting is enabled or not. 

If scripting is enabled, then the textContent is serialized literally; otherwise it is escaped ("<" to "&lt;", and "&" to "&amp;"). Similarly, when NOSCRIPT is parsed: if scripting is enabled then it is treated as rawtext, and like a "transparent" element if it is disabled.

There appears to be a bug in Chromium's serializer, that noscript is always serialized assuming that scripting is enabled even if it was parsed in a context where scripting was disabled.

Consider the following example:

'''javascript
const doc = 
new DOMParser().parseFromString('<body><noscript>&lt;/noscript&gt;&lt;img src onerror=alert(1)>', 'text/html');
console.log(doc.body.innerHTML);
// will print:
//   <noscript></noscript><img src onerror=alert(1)></noscript>
'''
Note that the original markup was harmless because the alert(1) was treated just as text. However, the serialized form contains an additional <img> tag that was not there initially.

The correct serialization of the markup should be:

'''
<noscript>&lt;/noscript&gt;&lt;img src onerror=alert(1)&gt;</noscript>
'''

I'm reporting this as a security bug because this issue allowed me to bypass DOMPurify[2], the popular HTML sanitizer.

Interestingly, the same serialization bug is present in Chromium, but not in Safari.

[1] https://html.spec.whatwg.org/multipage/parsing.html#serialising-html-fragments:html-fragment-serialisation-algorithm:~:text=If%20current%20node%20is%20a%20Text%20node
[2] https://github.com/cure53/DOMPurify

The original report as published on Mozilla's Bugzilla, by Michał Bentkowski. Images and videos are our own copies; raw HTML is shown as text. View it on Mozilla's Bugzilla.

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 serializer does not check the scripting flag when serializing text nodes inside a <noscript> element, always assuming scripting is enabled and thus not escaping special characters.

Impact

This bug allowed the reporter to bypass DOMPurify, a popular HTML sanitizer, potentially leading to cross-site scripting (XSS) in applications that rely on it.

What the attacker needed

Application uses DOMPurify for sanitization; attacker can supply HTML input

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.

When a web page includes a <noscript> tag, its content is normally shown only if JavaScript is turned off. The browser must handle this content differently depending on whether JavaScript is on or off. A bug in how Chromium converts the page back to text can turn harmless text into active code, which a security tool (DOMPurify) fails to clean, allowing an attacker to run scripts.

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 Michał Bentkowski

View all

15 more disclosed reports, best first.

More from Mozilla

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.