Skip to content
XSS Disclosed report Advanced

Read any repo file (incl. private ones) via postMessage on both gitlab.com/self-hosted instance (bypass #1417680)

A cross-site scripting flaw in GitLab's Live Preview sandbox allowed an attacker to bypass a previous postMessage source check and read files from a victim's private repository. The attacker could steal source code and sensitive files such as .gitlab-ci.yml containing API keys or SSH keys.

GitLab

Originally disclosed on GitLab

  • Fixed in 4 months
  • Disclosed after 4 months

HackerOne report #1699831 by niraeth on 2022-09-14, assigned to GitLab Team:

Report | Attachments | How To Reproduce

Report

Summary

An attacker can use a specially crafted webpage to read the content of a victim's repo via postMessage when the victim uses the Live Preview feature.

The attack vector and impact is the same as report #1417680 or CVE-2022-2907 . Although it was fixed in the previous report, I have found a workaround/bypass for it.

Steps to reproduce

The reproduction below will be done on gitlab.com, but it works (and I have tested) for self-hosted instances as well. For self-hosted instances, you will need to manually enable the Live Preview feature for the exploit to work. You can follow the guide here to enable the feature.

Reproduce for gitlab.com:

  1. Login to https://gitlab.com using the credentials: email [email protected] and password 89J6\U^_tV?/yY7X
  2. Go to the poc page at https://exploits.niraeth.com/sites/gitlab/postMessage%20readFile%202/readFile%203499E693D443B4E6ED4CE8D0F815F991.html
  3. Follow instructions on the poc page.

Reproduce for your own instance:

  1. Download the HTML file :
  2. Modify the URL shown below
URL_to_be_modified.JPG
URL_to_be_modified.JPG From the original on GitLab
  1. Follow the instructions above (Reproduce for gitlab.com)
Vulnerable Code / Bypass Details

First, take a look at the fix implemented from the previous report. You can see below that it checks for the message's source, to check that it comes from this.frameWindow. this.frameWindow is an iframe that points to https://sandbox-prod.gitlab-static.net/. $id is now also checked against this.channelId (a random int from 100000-999999)

fix_from_prev_report.JPG
fix_from_prev_report.JPG From the original on GitLab

However, because there is a XSS vulnerability at https://sandbox-prod.gitlab-static.net/, an attacker can use this XSS to call postMessage and bypass the source check. The said XSS can be triggered via postMessage due to vulnerable code shown below

  1. This is the message event listener
cframe_-_1_-_message_listener.JPG
cframe_-_1_-_message_listener.JPG From the original on GitLab
  1. Eventually, the code below gets executed. The XSS is executed by the line eval(e.command)
cframe_-_2-_eval.JPG
cframe_-_2-_eval.JPG From the original on GitLab
Impact
  1. Read files of private repo - steal source code etc
  2. Read sensitive files such as .gitlab-ci.yml which is almost guaranteed to contain things like api keys, ssh keys that are necessary for the pipeline to work. This would then enable an attacker to further their attack, e.g gaining remote access to a server.
Examples

The repo used for this PoC is available at https://gitlab.com/nicgene/vue-todo . However, any other project/repo that is properly configured for the Live Preview feature would work too.
Note that the above repo is not controlled by me.

What is the current bug behavior?

Attacker is able to read repo files

What is the expected correct behavior?

The attacker should not be able to communicate with the message event listener.

Relevant logs and/or screenshots

Nil. Refer to the section Vulnerable Code / Bypass Details for screenshots of the affected code

Output of checks

This bug happens on GitLab.com and Self Hosted GitLab

Results of GitLab environment info
System information  
System:         Ubuntu 20.04  
Current User:   git  
Using RVM:      no  
Ruby Version:   2.7.5p203  
Gem Version:    3.1.6  
Bundler Version:2.3.15  
Rake Version:   13.0.6  
Redis Version:  6.2.7  
Sidekiq Version:6.4.0  
Go Version:     unknown

GitLab information  
Version:        15.3.3  
Revision:       c629a47f87f  
Directory:      /opt/gitlab/embedded/service/gitlab-rails  
DB Adapter:     PostgreSQL  
DB Version:     13.6  
URL:            http://ec2-13-228-76-134.ap-southeast-1.compute.amazonaws.com  
HTTP Clone URL: http://ec2-13-228-76-134.ap-southeast-1.compute.amazonaws.com/some-group/some-project.git  
SSH Clone URL:  [email protected]:some-group/some-project.git  
Using LDAP:     no  
Using Omniauth: yes  
Omniauth Providers:

GitLab Shell  
Version:        14.10.0  
Repository storage paths:  
- default:      /var/opt/gitlab/git-data/repositories  
GitLab Shell path:              /opt/gitlab/embedded/service/gitlab-shell  

Impact

Mentioned in the report.

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

Likely the sandbox page at sandbox-prod.gitlab-static.net used eval on a command received via postMessage without proper validation, allowing an attacker to execute JavaScript in the sandbox origin and bypass the source check in the parent page.

Impact

An attacker could read files from a victim's private repository, including sensitive files like .gitlab-ci.yml that may contain API keys or SSH keys, potentially leading to further compromise.

What the attacker needed

Victim uses Live Preview feature; victim visits attacker's webpage; self-hosted: Live Preview manually enabled

How it was found

  1. Log in to gitlab.com with the provided credentials.
  2. Visit the attacker's proof-of-concept page.
  3. Follow the instructions on the page to trigger the attack.

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 use GitLab's Live Preview, your browser talks to a separate sandbox website to show your code. The report found that this sandbox website had a bug that let an attacker run their own code inside it. That let the attacker pretend to be the sandbox and ask GitLab for your private files, which they could then steal.

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.