# Stored DOM XSS via Mermaid chart

Mermaid directive fontFamily value injected unsanitized into a <style> innerHTML, breaking out of the style tag to achieve stored DOM XSS in GitLab issues.

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

**Target:** GitLab GFM Mermaid diagram renderer (directive init JSON)
**Root cause:** Mermaid merges user-supplied directive JSON (fontFamily/altFontFamily/themeCSS) into config and writes it into a <style> element via innerHTML without sanitization, allowing `</style>` breakout.
**Steps:**
1. Create an issue in any repo
2. Insert mermaid block with `%%{init: { 'fontFamily': '\"></style><img src=x onerror=alert(document.cookie)>'} }%%` followed by a sequenceDiagram
3. Save issue; payload fires on every page view of the issue
**How found:** Read Mermaid source, noticed directive JSON merged into config and concatenated into userStyles, then into a <style> via innerHTML — no sanitization, so `</style>` breakout is possible.
**Exploitation:** Stored payload in issue description renders whenever any user opens the issue page; the `</style>` closes the injected style tag and the img onerror executes JS in the GitLab origin. CSP on gitlab.com blocked execution; author offered a CSP bypass.
**Insight:** When a library builds CSS from user JSON and injects via innerHTML, look for `</style>` breakout in fontFamily/themeCSS fields; also check whether CSP actually blocks the resulting inline handler before assuming impact.

