Account takeover through XSS in Web-IDE when loading .ipynb files (yet again)
A stored cross-site scripting (XSS) vulnerability in GitLab's Web IDE when rendering .ipynb files allowed an attacker to execute arbitrary JavaScript in a victim's browser. By combining this XSS with a service worker path traversal and a CSP bypass, the attacker could steal the victim's CSRF token and add a new email address to the victim's account, leading to full account takeover.
GitLab
Originally disclosed on GitLab
- Fixed in 6 months
- Disclosed after 6 months
⚠️ 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 #2971485 by joaxcar on 2025-02-03, assigned to @ameyadarshan:
Report | Attachments | How To Reproduce
Report
Summary
Hi team, after reviewing the latest patch against "ATO in Web-IDE using XSS in .ipynb files" I found another way to achieve the same impact. It utilized another path in the code that was not used or patched last time
I believe that this is the fix for the previous report
https://gitlab.com/gitlab-org/gitlab-web-ide-vscode-fork/-/merge_requests/107
This patch adds a freeze for the Map object but, more importantly, replaces the remoteAuthority parameter with an empty string
const remoteAuthority = ''; // searchParams.get('remoteAuthority');
This effectively blocked the previous report. However, I found a way to use the resourceBaseAuthority parameter in combination with a CSP bypass to arrive at the same impact.
Note that the details section should be read in the context of previous reports. To just verify the attack skip to POC
Details
First of, I found that its possible to trigger the path traversal in fetch requests(see the previous report) using /%2e%2e/ as a pattern without hooking into any javascript objects.
The resourceBaseAuthority parameter can be used to hit this part of the service worker code in workbench/contrib/webview/browser/pre/service-worker.js
switch (event.request.method) {
case 'GET':
case 'HEAD': {
const firstHostSegment = requestUrl.hostname.slice(0, requestUrl.hostname.length - (resourceBaseAuthority.length + 1));
const scheme = firstHostSegment.split('+', 1)[0];
const authority = firstHostSegment.slice(scheme.length + 1); // may be empty
return event.respondWith(processResourceRequest(event, {
scheme,
authority,
path: requestUrl.pathname,
query: requestUrl.search.replace(/^\?/, ''),
}));
}
default: {
return event.respondWith(methodNotAllowed());
}
}
where we can control the scheme, authority and path by making the initial XSS do a fetch request of an URL of the format https://https+gitlab.com.com/assets/webpack/gitlab-vscode/0.0.1-dev-20250109231656/vscode/extensions/ipynb/%252e%252e/%252e%252e given a vscode-resource-base-authority=com
The problem is that requests to https://https+gitlab.com.com will get blocked by the CSP connect-src. To bypass the CSP we can take advantage of other files stored on the same domain that is not subject to CSP. Such as workbench/contrib/webview/browser/pre/fake.html.
If we frame workbench/contrib/webview/browser/pre/fake.html we can then write a script tag to the body of this new frame and have it execute without CSP. We can then fetch the resource using the https://https+gitlab.com.com domain, hit the path traversal and retrieve a CSRF token as in the previous reports.
The full flow of the attack is this
- XSS in
ipynbfile triggers when victim views the file in Web-IDE - The XSS removes the old service worker and registers a new version of the same worker but using the URL parameter
vscode-resource-base-authority=com - The XSS is used to create a new
iframepointing to/workbench/contrib/webview/browser/pre/fake.html - The XSS is used to write a new script into the body of this new iframe. This will then execute without CSP
- The script in the new iframe will make a fetch request like this
fetch("https://https+gitlab.com.com/assets/webpack/gitlab-vscode/0.0.1-dev-20250109231656/vscode/extensions/ipynb/" + "%252e%252e/".repeat(20) + "-/profile/emails")
the response will contain the victims CSRF token
6. The script in the new iframe now navigates the parent.parent to an attacker-controlled page leaking the CSRF token.
7. The attacker page (that is now framed on the page) directly use theCSRF token to register a new email to the victim account. Full ATO
The chain is a bit complicated, but it all happens automatically by just visiting the page in step 1. No further interaction is required.
Steps to reproduce
- Prepare a new payload by going to <redacted link>/iframe_message_payload2.[email protected] replacing [email protected] with any email you control
- Copy the content on the page, the full JSON you see on the page
- Go to https://gitlab.com and sign in
- Create a new public project
- Create a file in the project called attack.ipynb with the content from step 2
- As another gitlab user, visit the file in the Web IDE (https://gitlab.com/-/ide/project/GROUPNAME/PROJECTNAME/edit/main/-/attack.ipynb)
- Let the file load
- Visit https://gitlab.com/-/profile/emails and see that you have a new email on your account.
If you used a real email you can now take over the account
(note that the ATO is just one option, with the CSRF token we can do ALL actions as the victim and leak ALL data)
Video
<redacted>
What is the current bug behavior?
XSS in ipynb can still control cross-domain requests through a combination of vscode-resource-base-authority and CSP bypass
What is the expected correct behavior?
XSS in ipynb that seems to be by design should not be able to tamper with cross-domain resource requests
Output of checks
This bug happens on GitLab.com
Impact
Stored XSS that leads to full ATO by just viewing a file in WebIDE
Attachments
Warning: Attachments received through HackerOne, please exercise caution!
- <redacted>
- iframe_message_payload2.html
- inframe_message2.js
How To Reproduce
Please add reproducibility information to this section:
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 service worker's handling of the resourceBaseAuthority parameter allowed path traversal, and a CSP bypass via a same-origin HTML file enabled cross-domain requests to leak the CSRF token.
What the attacker needed
Victim views malicious .ipynb in Web IDE; attacker has a GitLab account; victim is logged in
How it was found
- Create a malicious .ipynb file with the XSS payload.
- As another user, open the file in the Web IDE.
- The XSS registers a new service worker with a manipulated resourceBaseAuthority parameter.
- The XSS creates an iframe to a same-origin HTML file and injects a script that bypasses CSP.
- The injected script fetches the victim's CSRF token via a path traversal request.
- The script navigates to an attacker-controlled page, leaking the CSRF token, which is then used to add a new email to the victim's account.
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 open a notebook file in GitLab's web-based code editor, the file can contain malicious code that runs in your browser. This code can then trick GitLab into giving it a special token that lets it change your account settings, like adding a new email address, which can lead to someone else taking over your account.
What is XSS?
Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.