Skip to content
XSS Disclosed report Advanced

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

An unpatched HTML file on staging.gitlab.com allowed cross-site scripting (XSS) via a parentOrigin parameter, and by chaining this with a service worker and GitHub OAuth flow, an attacker could take over a victim's gitlab.com account if the victim used a WebKit browser and had GitHub OAuth connected.

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 #2555601 by joaxcar on 2024-06-17:

Report | Attachments | How To Reproduce

Report

Summary

Instance of CVE-2024-4835 on staging.gitlab.com, leading to XSS on staging.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-20240501001436/vscode/out/vs/workbench/services/extensions/worker/webWorkerExtensionHostIframe.html leading to ATO on gitlab.com.

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 staging.gitlab.com

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

This means that we now have XSS on staging.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 staging.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 staging.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/staging/xss/poc.html
  2. Open dev tools and see this message
Got Worker XSS in https://staging.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/staging/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 staging.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.mov From the original on GitLab

Details of the ATO POC

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

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

to mount the new service worker.
4. 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
5. 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/staging/poc.html page we frame

https://staging.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 staging.gitlab.com
6. 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%2Fstaging.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.
7. The Github OAuth flow will land on https://staging.gitlab.com/users/auth/github/?code=CODE&state=STATE. As this is now on the same origin as our XSS on staging.gitlab.com we can reach over to this tab using top.opener and grab the code from the URL.
8. 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 staging.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 staging.gitlab.com

What is the expected correct behavior?

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

Output of checks

This bug happens on GitLab.com

Impact

XSS on staging.gitlab.com that can lead to ATO on staging.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 vulnerable HTML file from CVE-2024-4835 was still hosted on staging.gitlab.com, and its parentOrigin parameter allowed script execution in a web worker.

Impact

The XSS on staging.gitlab.com could lead to account takeover on staging.gitlab.com, and under specific conditions (WebKit browser and GitHub OAuth) also to account takeover on gitlab.com.

What the attacker needed

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

The fix

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

How it was found

  1. Visit the attacker's proof-of-concept page that loads the vulnerable HTML file with a malicious parentOrigin parameter.
  2. Open developer tools and observe the XSS message confirming script execution on staging.gitlab.com.
  3. As the attacker, obtain a GitHub OAuth state value by initiating a login request to gitlab.com.
  4. Craft a link to the attacker's page that includes the stolen state value.
  5. As the victim using Safari and logged in via GitHub OAuth, visit the attacker's link and click the button.
  6. Copy the URL shown in the alert popup and use it to log in as the victim on gitlab.com.

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 cross-site scripting (XSS) bug on a GitLab staging site. XSS lets an attacker run their own code in a victim's browser on that site. By chaining several browser features, the attacker could steal a login token and take over the victim's main GitLab account, but only if the victim used a Safari or iOS browser and had linked their GitHub account.

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.