Skip to content
XSS Disclosed report Intermediate

Stored-XSS with CSP-bypass in Merge requests

A stored cross-site scripting vulnerability existed in GitLab's merge request page because the source branch name was marked as HTML-safe without proper escaping. An attacker could create a branch with a malicious name and, when a victim viewed a merge request from that branch, execute arbitrary JavaScript in the victim's browser, bypassing the Content Security Policy.

GitLab

Originally disclosed on GitLab

  • Fixed in 35 days
  • Disclosed after 35 days

⚠️ Please read the process on how to fix security issues before starting to work on the issue. Vulnerabilities must be fixed in a security mirror.

HackerOne report #1965750 by yvvdwf on 2023-04-28, assigned to @rshambhuni:

Report | How To Reproduce

Report

Hi,

Gitlab recently added icon to indicate fork in the Merge requests page. This modification indicates source_branch as html_safe, which can cause XSS:

Ruby
###  https://gitlab.com/gitlab-org/gitlab/-/blob/f728534d7f6a357cf049cfd7a640a32504a1b9d6/app/helpers/merge_requests_helper.rb#L251  
    branch_title = if merge_request.for_fork?  
                     _('%{source_project_path}:%{source_branch}').html_safe % { source_project_path: merge_request.source_project_path.html_safe, source_branch: merge_request.source_branch.html_safe }  
                   else  
                     merge_request.source_branch  
                   end  

Reproduce

  1. Within the current user, e.g., user_a, create a public project user_a/a

  2. Switch to another user, e.g., user_b:

    2.1. Fork https://gitlab.com/user_a/a to a public project user_b/b
    2.2. Clone user_b/b to your local machine using ssh: git clone [email protected]:user_b/b
    2.3. Push a new branch to user_b/b:

Bash
   git clone [email protected]:user_b/b  
   cd b  
   git push origin HEAD:"XSS<i/class=hidden><form/class=gl-show-field-errors><input/title='<script>alert(document.domain)</script>'>"  

2.4. Back to the website gitlab.com, create a new merge request from the created branch above to user_a/a
2.5. After creating the merge request, you should see a popup that is created by <script>alert(document.domain)</script>

  1. The XSS should be existing at: https://gitlab.com/user_a/a/-/merge_requests/1
  2. Example: https://gitlab.com/yvvdwf/test-xss-in-merge-request-via-fork/-/merge_requests/1 (in private mode)

Impact

Stored-XSS with CSP-bypass allows attackers to execute arbitrary actions on behalf of victims at the client side.

How To Reproduce

Please add reproducibility information to this section:

The original report as published on GitLab. Images and videos are our own copies; raw HTML is shown as text. View it on GitLab.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Impact

Stored XSS with CSP bypass allows attackers to execute arbitrary actions on behalf of victims at the client side.

What the attacker needed

Attacker can create a public project and fork; victim views the merge request page

How it was found

  1. Create a public project as user_a.
  2. Fork that project to a public project as user_b.
  3. Push a new branch with a crafted name containing HTML and script tags.
  4. Create a merge request from that branch to the original project.
  5. View the merge request page to trigger the script.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

When a website shows text from users, it must escape special characters so they are displayed as text, not run as code. Here, the branch name was inserted into the page without escaping, so a branch name containing HTML and JavaScript could run code in the browser of anyone who viewed the merge request. This is called stored cross-site scripting because the malicious code is saved on the server and runs later for other users.

What is XSS?

Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.

More from GitLab

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Cross-site scripting (XSS)

The lesson behind this report.

Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.