Skip to content
XSS Disclosed report Intermediate

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:

Ruby
###  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
  1. create a public snippet with a json file alert.json containing {"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
snippet.png
snippet.png From the original on GitLab
  1. In an existing project, (or create a new project then make some commits), then goto Code / Commits and open a commit to view its diff, then enter the following comment (after replacing data-diff-for-path within the path noted above)
HTML
<i>&lt;div class=files &gt; &lt;div class=diff-file&gt; &lt;div class=diff-content&gt; &lt;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&gt; &lt;!-- [[ ]]</i>  
comment.png
comment.png From the original on GitLab
  1. 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:

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

What the attacker needed

A public snippet; a project with commits; victim views the commit diff

How it was found

  1. Create a public snippet with a JSON file containing a script payload and note its raw URL.
  2. Open a commit diff in a project and enter a comment that includes HTML referencing the snippet's raw path.
  3. 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.

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.