Mutation XSS (mXSS) is an advanced XSS technique that bypasses HTML sanitizers by exploiting differences between how sanitizers parse HTML and how browsers render it. The payload appears harmless to the sanitizer but "mutates" into executable JavaScript when the browser parses the DOM.
HTML5 parsing is complex and browsers may rewrite or "fix" malformed HTML in unexpected ways. Attackers craft payloads that pass through sanitizers intact but become dangerous after browser normalization. This often involves exploiting edge cases in nested tags, encoding, or browser-specific parsing behaviors.
A payload that mutates during parsing:
// Input that passes sanitizer
<noscript><p title="</noscript><img src=x onerror=alert(1)>">
// After browser mutation
<noscript><p title="</noscript>
<img src=x onerror=alert(1)>"></p></noscript>
<img src=`x`onerror=alert(1)>