# Stored-XSS injected in Wiki page via Banzai pipeline

Banzai reference filter re-runs gsub on link text, letting crafted wiki markup inject attributes and mXSS via SVG/style to execute JS in GitLab.

- Payout: hidden
- Severity: high
- Program: GitLab
- Found by: yvvdwf
- Disclosed: 2024-05-28
- Write-up quality: 9/10
- Original: https://hackerone.com/reports/2257080
- Library page: https://bugbountylibrary.com/r/h1%3A2257080
- Tags: area:web domain:web impact:ato impact:data-leak kind:bounty platform:hackerone sev:high tech:ruby technique:chained technique:parser-differential technique:source-review vuln:misconfiguration vuln:xss

**Target:** GitLab Wiki page rendering (Banzai markdown pipeline)
**Root cause:** AbstractReferenceFilter checks only the link_pattern prefix but then gsub-replaces all occurrences inside already-rendered anchor inner_html, allowing injected reference text to expand into attributes; combined with GollumTagsFilter-generated hrefs bypassing Sanitize's quote escaping and Nokogiri HTML4 vs browser HTML5 parsing differences.
**Steps:**
1. Create project wiki page titled `_sidebar` with crafted content.
2. Craft payload: `<dl><a href="BASE*<i><a href="http:'&quot;...&gt;...">BASE*<i>[[a|http:'"...]]</i></a></dl>` so the reference gsub expands inside the alt/href attribute.
3. Use GollumTagsFilter `[[a|http:'"<]]` to inject `"` into generated href, breaking out of attribute since Sanitize only escapes user-supplied hrefs.
4. Inject `<svg><style><img/src="0"onerror="alert(0)"></style></svg>` — Nokogiri HTML4 parses `<img>` as child of style, browser HTML5 mutates it out of svg context.
5. Final payload uses `<i class=gl-show-field-errors><input title="<script>alert(document.domain)</script>"/>` to execute JS.
6. Save page; victim viewing wiki triggers alert(document.domain).
**How found:** Noticed link_pattern_start only checks prefix while gsub replaces all occurrences in inner_html; hypothesized attribute expansion inside nested anchors, then explored quote handling in Sanitize vs GollumTagsFilter-generated hrefs, and finally leveraged HTML4/HTML5 parser differential for mXSS.
**Exploitation:** Attacker stores crafted wiki page content; when any user (including privileged) views the page, the Banzai pipeline renders the mutated HTML and the browser executes the injected script under gitlab.com origin, bypassing CSP via the gl-show-field-errors input title trick, enabling arbitrary REST API calls as the victim.
**Escalation:** Chained three primitives: reference gsub attribute injection, GollumTagsFilter href quote injection bypassing Sanitize, and Nokogiri HTML4 vs browser HTML5 mXSS to escape svg/style context.
**Insight:** When a filter re-runs pattern substitution on already-rendered inner_html, nested anchors let reference expansion land inside attributes; also, sanitizer escaping applies only to user input, not to hrefs synthesized by other filters — audit those synthesized attributes for quote injection.
