Stored-XSS injected in diff viewer
A stored cross-site scripting (XSS) vulnerability in GitLab's diff viewer allowed an attacker to inject arbitrary HTML elements via a crafted comment, bypassing the Content Security Policy (CSP). An attacker could execute arbitrary actions on behalf of a victim when they viewed the affected commit diff.
GitLab
Originally disclosed on GitLab
- Fixed in 13 days
- Disclosed after 13 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 #2441257 by yvvdwf on 2024-03-29, assigned to @cmaxim:
Report | Attachments | How To Reproduce
Report
Hello,
Gitlab recently changed in sanitization of Gollum links:
### https://gitlab.com/gitlab-org/gitlab/-/blob/5368a427e4ee6be16d8d38f62268efaf19ef0dea/lib/banzai/filter/gollum_tags_filter.rb#L67
doc.xpath('descendant-or-self::text()').each do |node|
next if has_ancestor?(node, IGNORED_ANCESTOR_TAGS)
next unless node.content =~ TAGS_PATTERN
html = node.content.gsub(TAGS_PATTERN) do
process_tag(Regexp.last_match(1)) || Regexp.last_match(0)
end
node.replace(html)
end
Because node.content is used, it will all emit plaintext.
It allows injecting arbitrary HTML elements.
Steps to reproduce
- create a public snippet with a json file
alert.jsoncontaining{"html":"<script>alert(document.domain)</script>"}, then open the raw version and make note of the path, for example:https://gitlab.com/-/snippets/3683972/raw/main/alert.json

- In an existing project, (or create a new project then make some commits), then goto
Code / Commitsand open a commit to view its diff, then enter the following comment (after replacingdata-diff-for-pathwithin the path noted above)
<i><div class=files > <div class=diff-file> <div class=diff-content> <div data-diff-for-path=/-/snippets/3683972/raw/main/alert.json class=js-file-title style=position:fixed;top:0px;right:0px;bottom:0px;left:0px;z-index:99999> <!-- [[ ]]</i>

- Refresh the page, then you might notice a topmost transparent layer. Click any where to trigger an alert.
Impact
Stored-XSS with CSP-bypass allows attackers to execute arbitrary actions on behalf of victims at the client side.
Output of checks
This bug happens on GitLab.com
Impact
Stored-XSS with CSP-bypass allows attackers to execute arbitrary actions on behalf of victims at the client side.
Attachments
Warning: Attachments received through HackerOne, please exercise caution!
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
What the attacker needed
A public snippet; a project with commits; victim views the commit diff
How it was found
- Create a public snippet with a JSON file containing a script payload and note its raw URL.
- Open a commit diff in a project and enter a comment that includes HTML referencing the snippet's raw path.
- Refresh the page to see a transparent overlay; clicking anywhere triggers the alert.
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.
This report describes a stored cross-site scripting (XSS) bug in GitLab. XSS lets an attacker sneak malicious code into a web page that other people view, so the code runs in their browser. Here, a specially crafted comment in a commit diff could inject HTML, and because the site's security policy (CSP) was bypassed, the script could run and act as the victim.
What is XSS?
Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.