# Stored XSS via Mermaid Prototype Pollution vulnerability

Mermaid directive JSON merged into config without sanitization allowed __proto__ prototype pollution, breaking GitLab issue pages (DoS); report title claims stored XSS.

- Payout: $3,000
- Severity: high
- Program: GitLab
- Found by: taraszelyk
- Disclosed: 2021-07-12
- Write-up quality: 7/10
- Original: https://hackerone.com/reports/1106238
- Library page: https://bugbountylibrary.com/r/h1%3A1106238
- Tags: area:web domain:web impact:dos kind:bounty platform:hackerone sev:high tech:nodejs technique:source-review vuln:dos vuln:prototype-pollution

**Target:** GitLab GFM Mermaid diagram rendering (issue pages)
**Root cause:** Mermaid's %%{init: {...}}%% directive JSON is merged into the config object without blocking __proto__, allowing Object.prototype pollution.
**Steps:**
1. Create an issue in any repo
2. Insert mermaid block with `%%{init: { '__proto__': {'polluted': 'asdf'}} }%%` followed by a sequenceDiagram
3. Save and open the issue
4. Observe console exceptions and broken page interactions (cannot comment/edit)
**How found:** Researcher read Mermaid directive docs, noted JSON_OBJECT is merged into config and used to build CSS, hypothesized __proto__ could pollute Object.prototype; tried overwriting config for XSS but settled on DoS since pollution broke the app.
**Exploitation:** Attacker with issue-creation rights embeds the directive; on render, Object.prototype gains a 'polluted' key, breaking JS on the page for any viewer, preventing comments/edits.
**Insight:** Diagram/DSL libraries that merge user-supplied JSON config (Mermaid directives, chart themes) are prime prototype-pollution sinks; test __proto__/constructor keys in any %%{init}%%-style config merge, and check whether polluted keys flow into CSS/HTML sinks for XSS.

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

**Mermaid directive prototype pollution payload**

```
%%{init: { '__proto__': {'polluted': 'asdf'}} }%%
sequenceDiagram
Alice->>Bob: Hi Bob
Bob->>Alice: Hi Alice
```

