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:
### 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
-
Within the current user, e.g.,
user_a, create a public projectuser_a/a -
Switch to another user, e.g.,
user_b:2.1. Fork
https://gitlab.com/user_a/ato a public projectuser_b/b
2.2. Cloneuser_b/bto your local machine usingssh:git clone [email protected]:user_b/b
2.3. Push a new branch touser_b/b:
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>
- The XSS should be existing at:
https://gitlab.com/user_a/a/-/merge_requests/1 - 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:
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
- Create a public project as user_a.
- Fork that project to a public project as user_b.
- Push a new branch with a crafted name containing HTML and script tags.
- Create a merge request from that branch to the original project.
- 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.