# Stored XSS via Kroki diagram

Kroki filter used parent pre lang attribute unsanitized in img src string concat, enabling attribute injection and stored XSS with a CSP bypass via data-diff-for-path.

- Payout: $13,950
- Severity: high
- Program: GitLab
- Found by: vakzz
- Disclosed: 2023-06-02
- Write-up quality: 9/10
- Original: https://hackerone.com/reports/1731349
- Library page: https://bugbountylibrary.com/r/h1%3A1731349
- Tags: area:web domain:web impact:integrity kind:bounty platform:hackerone sev:high tech:ruby technique:chained technique:source-review vuln:xss

**Target:** GitLab Banzai Kroki markdown filter (lib/banzai/filter/kroki_filter.rb)
**Root cause:** CSS selector matches on child code lang but diagram_type is taken from node.parent['lang'] || node['lang'], and that value is string-concatenated into `<img src="#{image_src}" />`, allowing quote breakout and arbitrary attribute injection.
**Steps:**
1. Enable Kroki in admin application settings on self-hosted GitLab.
2. Create issue/comment with `<a><pre lang='f/" onerror=alert(1) onload=alert(1) '><code lang="wavedrom">xss</code></pre></a>`.
3. Reload page; alert fires if CSP disabled, else CSP violation logged.
4. For CSP bypass: host public snippet `aaa.json` with `{"html":"<script>alert(document.domain)</script>"}` and note raw path.
5. Comment on a commit line with payload injecting `data-diff-for-path=<raw json path>` plus a second pre with `style` overlay, `data-triggers=click`, `data-toggle=popover`, `data-html=true`, and `data-title` containing `<style>` that repositions `svg.chevron-right` full-page.
6. Reload and click anywhere twice to trigger popover/chevron and load JSON via jQuery, executing script.
**How found:** Code reading of kroki_filter.rb: noticed selector checks both pre[lang] and code[lang] but diagram_type uses parent lang preferentially, and image_src is string-concatenated into HTML rather than built with content_tag — hypothesis that a quote in parent lang breaks out of the src attribute.
**Exploitation:** Attacker posts a comment containing crafted pre/code blocks. The Kroki filter emits an img with injected attributes. With CSP enabled, injected `data-diff-for-path` points to attacker-controlled JSON; injected `style` and popover `data-title`/`data-html` overlay the page so a victim click hits the diff chevron, which axios-fetches the JSON and jQuery parses `data.html` into DOM, executing the script in GitLab origin.
**Escalation:** Chained attribute injection with a CSP bypass using data-diff-for-path JSON loading and CSS overlay to force victim interaction.
**Insight:** When a selector validates one node but the code reads a different (parent) node's attribute, that mismatch is a taint source; also grep for string-interpolated HTML tags in filters — quote breakout yields attribute injection even when class is overwritten, and data-* attributes consumed by JS (axios+jQuery html) are prime CSP-bypass gadgets.

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

**Basic stored XSS payload via pre lang attribute**

```
<a><pre lang='f/" onerror=alert(1) onload=alert(1) '><code lang="wavedrom">xss</code></pre></a>
```

**JSON file loaded and executed via jQuery**

```
{"html":"<script>alert(document.domain)</script>"}
```

