Skip to content
XSS Disclosed report Intermediate

HTML injection in Global Search, can lead to XSS with CSP bypass in MR diff view

Filenames in GitLab's global search popup were inserted into the page as HTML without escaping. An attacker could create a file with a malicious name that, when searched, would execute JavaScript and bypass the Content Security Policy on gitlab.com.

GitLab

Originally disclosed on GitLab

  • Fixed in 54 days
  • Disclosed after 54 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 #2659386 by joaxcar on 2024-08-14, assigned to @kmorrison1:

Report | Attachments | How To Reproduce

Report

Summary

An HTML injection exists in the "global search" popup when searching for files.

This is the sink in app/assets/javascripts/super_sidebar/components/global_search/command_palette/search_item.vue

JavaScript
 highlightedName() {  
      return highlight(this.item.text, this.searchQuery);  
    },

...

<span v-safe-html="highlightedName" class="gl-text-gray-900"></span>  

the item.text is generated in app/assets/javascripts/super_sidebar/components/global_search/command_palette/utils.js

JavaScript
export const fileMapper = (projectBlobPath, file) => {  
  return {  
    icon: 'doc-code',  
    text: file,  
    href: joinPaths(projectBlobPath, file),  
    extraAttrs: {  
      'data-track-action': TRACKING_CLICK_COMMAND_PALETTE_ITEM,  
      'data-track-label': 'file',  
    },  
  };  
};  

the data sent into here comes from here app/assets/javascripts/super_sidebar/components/global_search/command_palette/command_palette_items.vue

JavaScript
const response = await axios.get(this.projectFilesPath);  
          this.projectFiles = response?.data.map(fileMapper.bind(null, this.projectBlobPath));  

This means that filenames are sent directly into v-safe-html and filenames can contain HTML

One place in the app where this can lead to XSS in new merge request diff pages bypassing CSP on gitlab.com

Steps to reproduce

  1. Go to https://gitlab.com/-/snippets/new and create a new public snippet with a file called alert.json and the content
JSON
{"html":"<script>alert(document.domain)</script>"}  

take note of the snippet ID
2. Create a new project
3. In the project create a file with this name (replace 3737908 with your snippet ID)

HTML
<i class=inline-parallel-buttons><a href=\-\snippets\3737908\raw\main\alert style="position:fixed;transform:translate3d(-2000px,-5000px,0px);width:10000px;height:20000px">  
  1. Go to https://gitlab.com/GROUPNAME/PROJECTNAME/-/new/main and create a new file, fill out whatever but make sure to change the target branch from main to new_branch. Keep "start a new merge request" checked.
  2. Click commit changes
  3. Go to https://gitlab.com/GROUPNAME/PROJECTNAME/-/merge_requests/new/diffs?merge_request%5Bsource_branch%5D=new_branch&merge_request%5Btarget_branch%5D=main (note that the source_branch%5D=new_branch if you did not name your branch like this in step 4)
  4. Click Search or go to.. in the upper left corner (or click / or s which are shortcuts)
Screenshot_2024-08-14_at_23.40.46.png
Screenshot_2024-08-14_at_23.40.46.png From the original on GitLab
  1. In the search box type ~
  2. There should now be some result in the search list, but it will be the HTML that is now covering the whole page
  3. Click anywhere on the page, and an alert box should pop
Screenshot_2024-08-14_at_23.42.50.png
Screenshot_2024-08-14_at_23.42.50.png From the original on GitLab

Impact

XSS with CSP bypass on gitlab.com

What is the current bug behavior?

Filenames are not escaped in global search

What is the expected correct behavior?

Filenames should not render as HTML

Output of checks

This bug happens on GitLab.com

Impact

XSS with CSP bypass on gitlab.com

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

Root cause

The application used a Vue directive that renders raw HTML (v-safe-html) on filenames without proper sanitisation, allowing HTML injection.

Impact

An attacker could execute JavaScript in the context of gitlab.com, bypassing the Content Security Policy.

What the attacker needed

Ability to create a public snippet and project; victim uses global search on the merge request diff page

The fix

Filenames should be properly escaped or sanitised before being rendered in the global search results.

How it was found

  1. Create a public snippet with a file named alert.json containing a script payload.
  2. Create a new project.
  3. In the project, create a file with a name that contains HTML and links to the snippet.
  4. Create a new branch and start a merge request.
  5. Go to the new merge request diff page.
  6. Open the global search, type '~', and click the page to trigger 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.

When you search, matching filenames are shown. Here special characters in filenames were treated as HTML, so a script in a filename could run when someone searched.

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.