Skip to content
XSS Disclosed report Advanced

CVE-2024-4835 on pre.gitlab.com leads to ATO on gitlab.com main domain

An unpatched HTML file on pre.gitlab.com allowed XSS via a parentOrigin parameter, and a WAF bypass using percent-encoding enabled the attack. By chaining this XSS with a GitHub OAuth flow and WebKit-specific service worker behaviour, an attacker could take over a victim's gitlab.com account.

GitLab

Originally disclosed on GitLab

  • Fixed in 15 days
  • Disclosed after 15 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 #2555904 by joaxcar on 2024-06-17:

Report | Attachments | How To Reproduce

Report

Summary

Instance of CVE-2024-4835 on pre.gitlab.com, leading to XSS on pre.gitlab.com and to ATO on gitlab.com main domain if victim uses Github OAuth and a Webkit browser.

[@]matanber reported an unauthenticated XSS in #2497024, that exploited the HTML file hosted at https://gitlab.com/assets/webpack/gitlab-vscode/0.0.1-dev-20240226152102/vscode/out/vs/workbench/services/extensions/worker/webWorkerExtensionHostIframe.html leading to ATO on gitlab.com.

(note that the version number of the vs-code files differs from the report #2555601. Also pre.gitlab.com has a WAF that we need to bypass)

This was done by making the victim navigate to the file with a malicious origin in the parentOrigin query parameter.

The parentOrigin parameter was then removed, but the old file was accessible using a WAF bypass, as shown in #2517090.

This bypass looks to be fixed now, as the old files are no longer hosted on gitlab.com. We, however, noticed that the same files are hosted under pre.gitlab.com

https://pre.gitlab.com/assets/webpack/gitlab-vscode/0.0.1-dev-20240501001436/vscode/out/vs/workbench/services/extensions/worker/webWorkerExtensionHostIframe.html  

There is a WAF on pre.gitlab.com as well checking for parentOrigin= but its easily bypassed using the string p%61rentOrigin=

This means that we now have XSS on pre.gitlab.com and can use the same POC from #2497024 to create an access token for a victim user if the victim is logged in to pre.gitlab.com. This attack works in all browsers.

Even if this shows some impact we decided to escalate this further and found a way to take over accounts on the main gitlab.com domain under these conditions:

ATO on gitlab.com if

  1. Victim uses a webkit browser (Safari on MacOS or any browser on iOS)
  2. The victim has github OAuth connected to his/her account

This attack does not require any authentication on pre.gitlab.com neither from the attacker or the victim.


Let's first just show the simple XSS

Steps to reproduce XSS

  1. Visit https://joaxcar.com/gitlab/pre/xss/poc.html
  2. Open dev tools and see this message
Got Worker XSS in https://pre.gitlab.com.  

printed by this code from the XSS

console.dir(`Got Worker XSS in ${origin}.`)  

Steps to reproduce ATO on gitlab.com

As the attacker:

  1. Open Chrome (or any other browser)
  2. Go to https://gitlab.com/users/sign_in
  3. Open dev tools and run this in the terminal
JavaScript
fetch("https://gitlab.com/users/auth/github", {  
  "headers": {  
    "content-type": "application/x-www-form-urlencoded",  
  },  
  "body": "authenticity_token=" + $$("meta[name='csrf-token']")[0].content,  
  "method": "POST",  
  "mode": "cors",  
  "credentials": "include"  
});  
  1. There should be an error message in the console stating
Refused to connect to 'https://github.com/login...  

right click the link and do copy link address
5. Past the link anywhere and only select the state part of the url (the random string after state=)
6. Use the state to form a link like this

https://joaxcar.com/gitlab/pre/start.php?state=STATE  

where STATE is the state from step 5
(note: this manual copy-pasting of state is just for the POC, this can be made server-side in a real attack and will not be part of the URL)

As the victim
7. Open Safari
8. Log in to GitLab.com using Github Oauth
9. Visit the attacker link from step 6
10. Click the button Click me (a real attack would use a cookie banner or similar)
11. There should be an alert popup after a few seconds
12. In the popup, there is an URL, copy this URL (this is just for the POC again, a real attack would just leak this to the attacker)

As the attacker
13. In the attacker's browser (where you ran step 2) visit the URL from step 12
14. The attacker should now be logged in to gitlab.com as the victim user

Video

I just realized that the name of the users in the video might be strange as the victim user here is named attacker saml user. But the setup is like this:

  1. Red browser (chrome) is the attacker, with no account on gitlab.com or pre.gitlab.com. The attacker generates the state param
  2. Grey victim browser (safari) is authenticated to gitlab.com using github oauth

In the end you can see that the red attacker gets logged in as the victim account.

gitlab_ATO_poc_pre.mov From the original on GitLab

Details of the ATO POC

We abuse a series of gadgets to jump from the worker XSS on pre.gitlab.com to ATO on gitlab.com

  1. CVE-2024-4835 allows for XSS in a web worker on pre.gitlab.com
  2. WAF bypass on pre.gitlab.com
  3. Safari allows for web workers to register service workers
  4. We use the same worker script
https://pre.gitlab.com/assets/webpack/gitlab-vscode/0.0.1-dev-20240501001436/vscode/out/vs/base/worker/workerMain.js  

to mount the new service worker.
5. workerMain.js has a built in XSS vector loading whatever script you send in as the first postmessage to the worker. Which now leads to XSS in a service worker
6. Safari allows for service workers to navigate frames in the workers scope to javascript: URLs. As you can see on the https://joaxcar.com/gitlab/pre/poc.html page we frame

https://pre.gitlab.com/assets/webpack/gitlab-vscode/0.0.1-dev-20240501001436/vscode/out/vs/base/worker/workerMain.js  

and refresh this frame every second. When the service worker XSS triggers this worker will navigate the iframe to a javascript URL, which now gives us full XSS on pre.gitlab.com
7. While the above 5 steps are happening, the original browser tab will in the background, redirect to

https://github.com/login/oauth/authorize?client_id=bbe1fe17fd3206756805&redirect_uri=https%3A%2F%2Fpre.gitlab.com%2Fusers%2Fauth%2Fgithub%2F&response_type=code&scope=user%3Aemail&state=STATE  

using the attackers STATE code. Notice how this client id bbe1fe17fd3206756805 is the app registration for using Github OAuth on gitlab.com. Gitlab have registered this app to have the redirect URI https://gitlab.com/auth/github but Github is very permissiv in what redirect is allowed. GitHub will allow us to change this redirect to any subdomain of the registered domain and still have the code returned there and being valid.
8. The Github OAuth flow will land on https://pre.gitlab.com/users/auth/google_oauth2/?code=CODE&state=STATE. As this is now on the same origin as our XSS on pre.gitlab.com we can reach over to this tab using top.opener and grab the code from the URL.
9. As the attacker generated the original state the attacker can now use this leaked code to log in to gitlab.com as the victim user.

The information here is mostly for explanation, its not necisary to understand each step, but if you want us to elaborate on the POC please reach out.

Severity

I want to emphasize that the bug this time is on pre.gitlab.com, but the impact of the provided POC is on gitlab.com without any restrictions regarding the access for either the attacker or victim. This puts the report on the scope for gitlab.com.

AC: high this time as there are limiting factors such as webkit only

other than that, it's the same as previous reports.

What is the current bug behavior?

CVE-2024-4835 is present on pre.gitlab.com

What is the expected correct behavior?

The unpatched files from CVE-2024-4835 should not be hosted on pre.gitlab.com

Output of checks

This bug happens on GitLab.com

Impact

XSS on pre.gitlab.com that can lead to ATO on pre.gitlab.com but also ATO on gitlab.com abusing Github OAuth flow

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 old vulnerable VS Code worker HTML file remained hosted on pre.gitlab.com, and the WAF could be bypassed by percent-encoding the parentOrigin parameter.

Impact

An attacker could achieve XSS on pre.gitlab.com and, under specific conditions (WebKit browser and GitHub OAuth), take over a victim's gitlab.com account.

What the attacker needed

Victim uses a WebKit browser; victim has GitHub OAuth connected; victim clicks attacker link

The fix

The unpatched files should not be hosted on pre.gitlab.com.

How it was found

  1. Visit the attacker's XSS proof-of-concept page.
  2. Open developer tools and observe the message confirming worker XSS on pre.gitlab.com.
  3. As the attacker, obtain a GitHub OAuth state value from the sign-in flow.
  4. As the victim using Safari and GitHub OAuth, visit the attacker link and click the button.
  5. Copy the URL shown in the alert popup.
  6. As the attacker, visit that URL to be logged in as the victim.

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.

A leftover web page on a GitLab test site let an attacker run their own code in a victim's browser (cross-site scripting, or XSS). The attacker then abused how GitHub login redirects work and a Safari-only feature to steal the victim's login code and sign in as them on the main GitLab site.

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.