# Stored XSS in repository file viewer

Old DOMPurify in GitLab's swagger-ui OpenAPI viewer allowed injecting arbitrary HTML attributes, enabling stored XSS via a crafted openapi.yaml that fires on any page click.

- Payout: $2,000
- Severity: medium
- Program: GitLab
- Found by: kannthu
- Disclosed: 2022-05-19
- Write-up quality: 7/10
- Original: https://hackerone.com/reports/1072868
- Library page: https://bugbountylibrary.com/r/h1%3A1072868
- Tags: area:web domain:web impact:ato impact:integrity kind:bounty platform:hackerone sev:medium tech:rest technique:chained technique:incomplete-fix technique:source-review vuln:xss

**Target:** GitLab OpenAPI/Swagger viewer (swagger-ui) rendering repository openapi.yaml files
**Root cause:** GitLab bundled an outdated swagger-ui whose old DOMPurify permitted arbitrary HTML elements/attributes (except script), so attacker-controlled OpenAPI content injected markup that bypassed CSP via a data-remote/data-type=script anchor.
**Steps:**
1. Create repo with openapi.yaml containing injected HTML anchor: `<a data-remote="true" data-method="get" data-type="script" href="/wbowling/wiki/raw/master/test.js" class='atwho-view select2-drop-mask pika-select'></a>`
2. Visit https://gitlab.com/kannthu/asdasdas123/-/blob/master/openapi.yaml
3. Click anywhere on the page; injected script executes (alert)
4. Alternatively append `?url=https://gitlab.com/kannthu/asdasdas123/-/raw/master/openapi.yaml` to any repo's openapi.yaml viewer URL to trigger on arbitrary repos
**How found:** Noticed GitLab used an old swagger-ui/DOMPurify version, tested whether arbitrary HTML attributes survived sanitization, then reused a known GitLab CSP bypass anchor pattern to get script execution.
**Exploitation:** Attacker commits a malicious openapi.yaml to a repo (or supplies url= param pointing to their raw file); victim opens the Swagger viewer and clicks anywhere, the data-remote anchor loads attacker JS under gitlab.com origin, allowing CSRF token theft and account takeover.
**Escalation:** Chained CSP bypass (data-remote/data-type=script anchor from issue 213273) to execute script despite CSP blocking inline event handlers; url= param extends reach to any repository's OpenAPI viewer.
**Insight:** When a target embeds third-party renderers (swagger-ui, markdown, PDF viewers), check the bundled dependency version against known sanitizer CVEs; and look for existing CSP-bypass gadget anchors (data-remote/data-type=script) in the app to convert HTML injection into script execution.

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

**XSS payload anchor with data-remote script load**

```
<a   
  data-remote="true"
  data-method="get"  
  data-type="script"
  href="/wbowling/wiki/raw/master/test.js" 
  class='atwho-view select2-drop-mask pika-select'>
</a>
```

**PoC URL with url parameter injection**

```
https://gitlab.com/gitlab-org/build/omnibus-mirror/alertmanager/blob/master/api/v2/openapi.yaml?url=https://gitlab.com/kannthu/asdasdas123/-/raw/master/openapi.yaml
```

