Skip to content
UI spoofing Write-up Advanced

Insecure sandbox on Colaboratory

The sandboxed output iframe on Google Colaboratory lacked frame-ancestors protection, allowing an attacker to embed it and use postMessage to execute code in the context of the opener page. An attacker with local network access could leak the sandbox's subdomain via unencrypted DNS and then read data from the victim's Colaboratory session.

NDevTK Follow

Published on ndevtk.github.io

Bounty$1,337 View original

Google Colaboratory puts some output such as visualizations into a sandbox however it has no embedding protection such as csp frame-ancestors so the origin is exposed to attackers with local network access.

NDevTK, on ndevtk.github.io

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 4 min read.

Context

Google Colaboratory (Colab) is a hosted notebook environment. Some of its output, such as visualisations, is rendered inside a sandbox rather than directly in the main application origin. The report looks at how that sandbox is isolated and finds that the isolation can be bypassed by an attacker who can reach the user's local network.

The core observation is that the sandbox has no embedding protection such as a frame-ancestors Content Security Policy directive, so the sandbox origin is exposed to attackers with local network access.

Setup

The write-up does not describe any account setup, tooling versions or special roles. The preconditions that matter are implied by the attack itself:

  1. The victim visits an attacker-controlled page.
  2. The attacker can observe or influence the victim's DNS traffic, because the attack relies on unencrypted DNS.
  3. The victim has a Colab project open, in the example the "Welcome to Colaboratory" project, and the attacker embeds its sandbox on the attacker's website.

Finding it

The researcher noticed that Colab places certain output, such as visualisations, into a sandbox, but that the sandbox response carries no embedding protection. Without a frame-ancestors policy, any site can frame the sandbox origin. Combined with the fact that the sandbox is served from a subdomain derived from an identifier, and that DNS is frequently unencrypted, the origin becomes predictable to someone on the network path.

Exploitation

Step 1: open a blank window and navigate the opener

The attacker page first opens a blank window:

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

On that about:blank document, the attacker then navigates the opener to Colab:

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

Step 2: leak the identifier from DNS

The sandbox is hosted on a subdomain that includes an identifier. Because the DNS lookup is unencrypted, the attacker can read that identifier from the DNS traffic. In the write-up this is represented by a placeholder:

JavaScript
let IDfromDNS = 'blah';

Step 3: frame the sandbox and post a message into it

With the identifier known, the attacker creates a hidden iframe pointing at the sandbox output frame and appends it to the page:

JavaScript
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);

The iframe source is built from the leaked identifier, followed by -0-colab.googleusercontent.com/outputframe.html. After a short delay the attacker posts a message into the framed sandbox. The message uses the sandboxed_iframe_evaluation key, and its value is JavaScript that the sandbox evaluates. The target origin is '*', so the message is delivered regardless of the receiving origin.

The evaluated code reaches back out of the sandbox through parent.opener.

Step 4: read data through the opener

On the "Welcome to Colaboratory" project, with the sandbox embedded on the attacker's website, the researcher reports two useful references:

  • parent.opener[0].google refers to stuff.
  • parent.opener[5].document refers to the chart.

The report lists two references reachable through parent.opener: [0].google and [5].document, the latter described as the chart.

Root cause

The sandbox relies on origin separation: output is served from a separate googleusercontent.com subdomain so that it cannot touch the main application. Two weaknesses combine to defeat this.

First, the sandbox response has no embedding protection such as frame-ancestors, so any site can frame it. Second, the subdomain contains an identifier that is visible in unencrypted DNS, so the attacker can learn the exact origin to frame. The write-up notes that sandboxes sometimes use a randomly generated subdomain for isolation, but that this is not safe when DNS is unencrypted, linking to Cloudflare's explanation of DNS over TLS.

The report shows a message with an evaluation-style key posted into the framed sandbox, and references reached through parent.opener.

Impact

An attacker who can get a victim to visit a page and who can observe the victim's unencrypted DNS can frame the victim's Colab sandbox and run code inside it. The report lists references reachable through parent.opener, including [5].document, described as the chart. The attack depends on local network access to the DNS traffic and on the victim having the relevant Colab project open with the sandbox embedded.

Fix

The write-up does not describe a fix or a change made by Google. Based on the root cause, the sandbox response should send an embedding protection header such as a frame-ancestors CSP directive so that only intended origins can frame it, and the isolation should not depend on a subdomain identifier that is observable in unencrypted DNS.

Variants to test

  1. Frame a sandboxed output origin from an attacker page and check whether the response includes frame-ancestors or X-Frame-Options. A positive result is a sandbox that loads in the attacker's iframe.
  2. Inspect whether the sandbox hostname contains a predictable or leakable identifier, and whether that identifier appears in DNS queries. A positive result is an identifier visible on the network path.
  3. Send a postMessage with an evaluation-style key into the framed sandbox and observe whether the code runs. A positive result is execution inside the sandbox.
  4. From the evaluated code, walk parent.opener and try to read objects or documents on the opener. A positive result is access to page data such as a rendered chart.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 9 min read.

What happened, in plain words

Google Colaboratory, usually called Colab, is a website where you write and run small programs in your browser, a bit like a shared notebook. When one of those programs produces a picture or a chart, Colab does not draw it directly on its own page. Instead it puts that output into a separate little web page, called a sandbox, and shows it inside the main page. The idea is that if the output is malicious, it is trapped in its own separate place and cannot touch the rest of Colab.

This report shows that the trap can be escaped. The researcher found that the sandbox page can be loaded inside any other website, including a website controlled by an attacker. The address of the sandbox contains an identifier, and that identifier can be read from the network because DNS is often not encrypted. Once the attacker knows the address, they can load the sandbox in a hidden frame on their own page and send it a message with an evaluation-style key. The report lists references reachable through parent.opener, including [5].document, described as the chart.

The researcher was paid a bounty of 1337.00 USD, and the report was disclosed on 2023-06-23.

The product and the feature

Colab is a hosted notebook environment: you open a project in your browser, type code into cells, run them, and see the results on the same page. Some results, such as visualisations, are not rendered directly in the main Colab page. They are rendered inside a sandbox, which here means a separate web page served from a different address, embedded in the main page through an iframe.

An iframe is a way to put one web page inside another, like a small television screen showing a different channel inside the room you are in. The outer page is called the parent, and the inner page is the child. Browsers keep pages from different addresses apart on purpose: a page from one address is normally not allowed to read the contents of a page from another address. This rule is called the same-origin policy, and it is the main reason a sandbox works at all.

The setup

The report does not describe any account setup, tooling versions or special roles. What matters is the situation the attack needs:

  1. The victim visits a page controlled by the attacker.
  2. The attacker can see or influence the victim's DNS traffic, because the attack relies on DNS being unencrypted.
  3. The victim has a Colab project open, in the example the "Welcome to Colaboratory" project, and the attacker embeds its sandbox on the attacker's website.

DNS is the phone book of the internet. When you type a name such as colab.research.google.com, your computer asks a DNS server what numeric address that name belongs to. If that question and answer travel unencrypted, anyone on the network path, for example someone on the same Wi-Fi, can read them. That is the second precondition, and it is the one that makes the rest possible.

Finding it

The researcher noticed that Colab puts certain output, such as visualisations, into a sandbox, but that the sandbox response carries no embedding protection. Embedding protection is a rule a website can send to the browser saying "only these other sites are allowed to put me in an iframe". The usual form is a Content Security Policy directive called frame-ancestors. Without it, any site can frame the sandbox address.

Two more facts combine with that. The sandbox is served from a subdomain that is derived from an identifier, so its exact address is predictable once you know the identifier. And DNS is frequently unencrypted, so the identifier can be read off the network. Together, the address of the sandbox becomes knowable to someone on the network path.

Exploitation

Step 1: open a blank window and navigate the opener

The attacker page first opens a blank window:

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

open('about:blank') asks the browser to create a new window showing an empty page. The result is stored in the variable w. The important part is not the blank page itself but the relationship it creates: the new window remembers which page opened it. That page is called the opener.

On that about:blank document, the attacker then navigates the opener to Colab:

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

opener refers to the page that opened this window, which is the attacker's page. Setting opener.location tells that page to go to a new address, so the attacker's own tab is sent to Colab. That handle is the thread the attack will pull on later.

Step 2: leak the identifier from DNS

The sandbox is hosted on a subdomain that includes an identifier. Because the DNS lookup is unencrypted, the attacker can read that identifier from the DNS traffic. In the write-up this is represented by a placeholder:

JavaScript
let IDfromDNS = 'blah';

This line just stores the leaked identifier in a variable. 'blah' stands in for whatever value was actually seen in the DNS query. The point is that the attacker did not have to guess it: it was visible on the network.

Step 3: frame the sandbox and post a message into it

With the identifier known, the attacker creates a hidden iframe pointing at the sandbox output frame and appends it to the page:

JavaScript
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);

Line by line:

  1. document.createElement('iframe') builds a new iframe element in memory. Nothing is visible yet.
  2. f.hidden = true marks it as hidden, so the victim sees nothing unusual on the page.
  3. f.src = ... sets the address the iframe will load. It is built from the leaked identifier, followed by -0-colab.googleusercontent.com/outputframe.html. This is the sandbox output page.
  4. document.body.appendChild(f) puts the iframe into the page, which makes the browser actually load that address.
  5. setTimeout(..., 100) waits 100 milliseconds before running the next part, giving the iframe time to load.
  6. f.contentWindow.postMessage(...) sends a message into the framed page. postMessage is the standard way for pages to talk to each other across addresses, like passing a note through a slot in the wall.
  7. The note has the key sandboxed_iframe_evaluation, and its value is a piece of JavaScript. The key is named sandboxed_iframe_evaluation.
  8. The second argument, '*', means the message is delivered regardless of which address is on the other side. It is the least restrictive setting.

The code inside the message is console.log(parent.opener[0].google). parent is the page that contains the iframe, which here is the attacker's page. opener is the page that opened the attacker's page, which step 1 sent to Colab. So the code refers to parent.opener, walking back out of the sandbox through the attacker's page.

Step 4: read data through the opener

On the "Welcome to Colaboratory" project, with the sandbox embedded on the attacker's website, the researcher reports two useful references:

  • parent.opener[0].google refers to stuff.
  • parent.opener[5].document refers to the chart.

The report lists two references reachable through parent.opener: [0].google and [5].document, the latter described as the chart.

Root cause

The sandbox relies on origin separation: output is served from a separate googleusercontent.com subdomain so that it cannot touch the main application. An origin, in browser terms, is the combination of scheme, host and port, for example https://colab.research.google.com. Pages from different origins are kept apart by the browser.

Two weaknesses combine to defeat that separation.

First, the sandbox response has no embedding protection such as frame-ancestors, so any site can frame it. Second, the subdomain contains an identifier that is visible in unencrypted DNS, so the attacker can learn the exact origin to frame. The write-up notes that sandboxes sometimes use a randomly generated subdomain for isolation, but that this is not safe when DNS is unencrypted, and links to Cloudflare's explanation of DNS over TLS. DNS over TLS is a way of encrypting DNS queries so that they cannot be read on the network path; without it, a random-looking name is still visible to anyone watching.

The report shows a message with an evaluation-style key posted into the framed sandbox, and references reached through parent.opener.

Impact

An attacker who can get a victim to visit a page, and who can observe the victim's unencrypted DNS, can frame the victim's Colab sandbox and run code inside it. The attack depends on local network access to the DNS traffic and on the victim having the relevant Colab project open with the sandbox embedded.

Fix

The write-up does not describe a fix or a change made by Google. Based on the root cause, the sandbox response should send an embedding protection header such as a frame-ancestors CSP directive so that only intended origins can frame it, and the isolation should not depend on a subdomain identifier that is observable in unencrypted DNS.

Variants to test

  1. Frame a sandboxed output origin from an attacker page and check whether the response includes frame-ancestors or X-Frame-Options. A positive result is a sandbox that loads in the attacker's iframe.
  2. Inspect whether the sandbox hostname contains a predictable or leakable identifier, and whether that identifier appears in DNS queries. A positive result is an identifier visible on the network path.
  3. Send a postMessage with an evaluation-style key into the framed sandbox and observe whether the code runs. A positive result is execution inside the sandbox.
  4. From the evaluated code, walk parent.opener and try to read objects or documents on the opener. A positive result is access to page data such as a rendered chart.

Glossary

  • API: a defined way for one piece of software to ask another to do something, like a menu of allowed requests.
  • Bounty: a payment made by a company to someone who reports a security problem to it.
  • Colab (Google Colaboratory): a hosted notebook environment where you write and run code in a browser page.
  • Content Security Policy (CSP): a set of rules a website sends to the browser to limit what the page may load or who may embed it.
  • DNS: the system that turns a name such as colab.research.google.com into a numeric address, like a phone book.
  • DNS over TLS: a way of encrypting DNS queries so they cannot be read on the network path.
  • frame-ancestors: a CSP directive that lists which other sites are allowed to embed this page in an iframe.
  • Identifier: a value that identifies a particular session or resource, here the part of the sandbox address that is unique to the user.
  • iframe: a way to embed one web page inside another.
  • Opener: the page that opened a given window; the opened window can refer back to it.
  • Origin: the combination of scheme, host and port that identifies a web page's home, for example https://colab.research.google.com.
  • parent: in a framed page, the page that contains the iframe.
  • postMessage: the browser function pages use to send messages to each other across origins.
  • Sandbox: a separate, restricted place where untrusted content is run so it cannot affect the main application.
  • Same-origin policy: the browser rule that pages from different origins cannot read each other's contents.
  • Subdomain: a name that sits under a larger domain, such as something.googleusercontent.com under googleusercontent.com.
  • Visualisation: a chart or other graphical output produced by a program.
  • X-Frame-Options: an older response header that tells the browser whether a page may be embedded in an iframe.

More by NDevTK

View all

31 more disclosed reports, best first.

More from Google

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Clickjacking and UI spoofing

The lesson behind this report.

The interface lies to the user: a framed page catches their clicks, or a browser shows the wrong address or a fake prompt. Paid when it leads to a sensitive action or convincing phishing.