# Stored XSS on Trix Editor version latest (2.1.16) - Sanitizer Bypass 

Trix 2.1.16 DOMPurify hook keeps data-trix-* attributes, and serialization blindly setAttribute's JSON from data-trix-serialized-attributes, letting a smuggled onerror handler execute stored XSS.

- Payout: $337
- Severity: low
- Program: Basecamp
- Found by: newbiefromcoma
- Disclosed: 2026-07-14
- Write-up quality: 7/10
- Original: https://hackerone.com/reports/3581911
- Library page: https://bugbountylibrary.com/r/h1%3A3581911
- Tags: area:web domain:web impact:ato kind:bounty platform:hackerone sev:low tech:nodejs technique:chained technique:incomplete-fix technique:source-review vuln:xss

**Target:** Trix rich-text editor (html_sanitizer.js / serialization.js)
**Root cause:** DOMPurify hook whitelists any data-trix-* attribute, and the serializer parses data-trix-serialized-attributes JSON and calls el.setAttribute(name,value) without re-sanitizing, so on* handlers survive.
**Steps:**
1. Load trix@2.1.16 and render a figure with data-trix-attachment JSON whose content is `<img src="x" data-trix-serialized-attributes="{"onerror":"alert('XSS')"}">`
2. Paste the rendered `copy me` text into the Trix editor
3. Read `document.querySelector('trix-editor').value` to get serialized HTML
4. Assign that output to `div.innerHTML`; the onerror handler fires
**How found:** Noticed the DOMPurify hook regex /^data-trix-/ retains all data-trix-* attributes, then traced serialization.js where data-trix-serialized-attributes JSON is parsed and applied via setAttribute, spotting the gap between sanitize and re-serialize.
**Exploitation:** Attacker submits rich-text containing a data-trix-attachment with nested data-trix-serialized-attributes JSON carrying onerror; when the app saves and re-renders editor.value, the handler is set on the img and executes in victims' browsers.
**Insight:** When a sanitizer allowlists a prefix (data-*), audit every downstream consumer that parses those attributes and rebuilds DOM—serialize/deserialize round-trips are where sanitized state gets re-injected unsanitized.

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

**Trigger XSS by rendering serialized editor value**

```
function triggerXSS() {
            // 1. Get the serialized HTML output that Trix generated
            var output = document.querySelector("trix-editor").value;
            console.log("Serialized HTML:", output);

            // 2. Simulate the application rendering this saved output on another page
            var div = document.getElementById("output");
            div.innerHTML = output;
```

