Author spoofing in Google Colaboratory
Published on ehpus.com
Recently, Google made public their new ‘Abuse Research Grant Program’ - an awesome tool for motivating researchers to delve into an often overlooked angle of software security that doesn’t get the attention it deserves.
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.
Context
Google Colaboratory is a tool for running Python Jupyter notebooks. You write Python code and execute it in a serverless environment, where a new container is spawned for every new session. Data can be persisted by integrating code with other Google products such as Drive, Docs or Big Query, and notebooks can be shared with peers just as any other Google document can.
Because a notebook contains executable code, Google warns users before they run someone else's notebook. When you try to execute a notebook owned by someone else, you face a clear warning. For anyone trying to get a victim to run malicious code, that warning is a serious blocker: even a naive user might think twice when facing such an alert.
The report describes an identity spoofing issue in Colaboratory that lets an attacker bypass that warning and trick a victim into running malicious code in their own environment. It was reported to the Google abuse team and paid a 500 USD bounty.
Setup
The attack needs no special tooling. It relies on two things every Google user has: Colaboratory and Google Drive's sharing settings. The preconditions are:
- An attacker account that can create a notebook in Colaboratory.
- A victim account that the notebook is shared with. The victim has to be a contributor to the file, because otherwise they could not access the code at all.
- The ability to change the notebook's owner through Google Drive, which the report shows is available to the current owner.
The whole flow is performed through the normal Colaboratory and Google Drive interfaces.
Finding it
The starting point was the warning itself. The researcher asked a simple question about its wording: the alert names an "Author", but a Colaboratory notebook, like any Google Drive document, can have several contributors. Since the victim must be made a contributor before they can even reach the code, who exactly is the "Author" the warning refers to?
The answer, once the question was formulated, was that the author must be the original user who created the document, or in Google Drive's terminology, the document owner.
That leads to the flaw. A document owner in Google Drive is not fixed: an owner can appoint another contributor as the new owner. This is deliberate design, and it makes sense. If you work with a colleague on a document they authored and they then leave the company and close their account, the shared document should not simply disappear; someone else has to become its owner. That cannot be decided automatically, so it is left to the current owner to choose the successor.
Quick testing confirmed that Colaboratory notebooks are managed like any other Google document: using Google Drive's settings, their owner, and therefore the "author" shown in the warning, can be changed to any of the file's contributors.
Exploitation
With the owner field under the attacker's control, the attack follows directly.
Step 1: Create the notebook
Create a new notebook in Colaboratory and write the malicious code in it. This notebook is owned by the attacker at this point.
Step 2: Share it with the victim
Share the notebook with the victim, making them a contributor. This is required anyway for the victim to be able to access the code and run it.
Step 3: Hand over ownership
Using Google Drive, locate the notebook and set the victim as its owner. The victim is now the document owner, which is the identity the execution warning treats as the "author".
Step 4: Send the link
Send the notebook link to the victim. When the victim opens it and runs the code, the warning no longer identifies the attacker as the author, because the notebook's owner is the victim. The security warning is effectively neutralised, and the victim runs the attacker's code in their own environment.
The report includes a proof of concept video showing first the normal behaviour and then the spoofed one. The video is not reproduced here.
Root cause
The warning derives the notebook's "author" from the document owner in Google Drive. Ownership, however, is a mutable sharing attribute that the current owner can transfer to any contributor. The security decision therefore trusts a value the attacker can set. The existing defence, the execution warning, was not broken technically; it was fed a false identity, so it displayed the victim's own name where the attacker's should have been.
Impact
An attacker can make a malicious notebook appear to be authored by the victim, removing the main obstacle to getting the victim to execute the attacker's code in the victim's own Colaboratory environment. The attack requires the victim to be a contributor to the notebook and to open the link and run the code.
Fix
Based on the root cause, the warning should not rely on the mutable owner field alone: it should identify the user who actually supplied the code, or otherwise make clear that ownership can be transferred and does not imply authorship.
Variants to test
- Other Google products that show an author or owner in a security-relevant prompt, such as Docs, Sheets or Apps Script. A positive result is a prompt that names a different person after ownership is transferred to the victim.
- Any sharing model where ownership can be reassigned, on other platforms. A positive result is a warning or trust indicator that changes to the victim's identity after the transfer.
- Notebooks with multiple contributors. A positive result is a warning that names the owner rather than the contributor who wrote the executed cell.
What happened, in plain words
Google Colaboratory is a free service from Google where you can write and run small programs (called notebooks) in your web browser. Because a notebook is a program, running someone else's notebook means running someone else's code on your own account. Google knows this is risky, so before you run a notebook that belongs to another person, it shows you a warning that names the "Author" of the notebook, so you can decide whether you trust them.
A security researcher, Zohar Shacha, noticed that this warning could be made to show the wrong name. By using a normal Google Drive feature that lets the current owner of a document hand ownership to someone else, an attacker could make a malicious notebook look as if the victim themselves had written it. The warning would then name the victim, not the attacker, and the victim would have far less reason to hesitate before running the code.
The researcher reported this to Google's abuse team, and Google paid a 500 USD bounty. The write-up appeared around the time Google announced its Abuse Research Grant Program, a scheme that pays researchers to look at abuse and misuse problems rather than only at classic software bugs.
This article walks through the same story for someone who has never done security work before. Every term is explained as it comes up, and nothing here goes beyond what the researcher described.
Background: what Colaboratory is and why the warning matters
Google Colaboratory (often shortened to Colab) is a tool for running Python Jupyter notebooks. A notebook is a document that mixes text, code and the output of that code. You type Python code into a cell, press run, and the result appears underneath. The code runs on Google's machines, not on your own computer: the report describes this as a serverless environment, where a new container is spawned for every new session. In plain terms, each time you start working, Google gives you a fresh, disposable computer in the cloud, and when the session ends that computer is thrown away.
If you want your work to survive between sessions, you can connect your code to other Google products such as Drive, Docs or Big Query. And you can share a notebook with other people, in exactly the same way you share any other Google document.
Because a notebook contains code that will actually execute, Google added a safety net. When you try to run a notebook owned by someone else, you get a clear warning first. The report shows this warning:
For anyone trying to trick a victim into running malicious code, that warning is a serious obstacle. Even a user who is not careful might stop and think when a message like that appears.
The issue the researcher found is an identity spoofing problem. Spoofing means pretending to be someone you are not, the way a caller can fake the number that shows up on your phone. Here, the notebook pretends to be written by the victim. The result is that the warning is bypassed, not by breaking it technically, but by feeding it a false identity, so the victim runs the attacker's code in their own environment.
What you need to carry out the attack
The attack needs no special tools, no hacking software and no programming skill beyond writing the malicious notebook itself. It relies on two things every Google user already has: Colaboratory and Google Drive's sharing settings. The preconditions are:
- An attacker account that can create a notebook in Colaboratory.
- A victim account that the notebook is shared with. The victim has to be a contributor to the file, because otherwise they could not open the code at all.
- The ability to change the notebook's owner through Google Drive, which the report shows is available to the current owner.
A contributor is anyone the document has been shared with who has permission to edit it, as opposed to someone who can only view it. The owner is the account that ultimately controls the document, including who else can access it and what happens to it if the owner's account goes away.
The whole flow is carried out through the normal Colaboratory and Google Drive screens, the same ones any user clicks through.
How the researcher found it
The starting point was the warning itself, and specifically its wording. The alert names an "Author". But a Colaboratory notebook, like any Google Drive document, can have several contributors. The victim has to be made a contributor before they can even reach the code. So who exactly is the "Author" the warning refers to?
Once the question was put that way, the answer was clear: the author must be the original user who created the document, or in Google Drive's terminology, the document owner.
That answer exposes the flaw. A document owner in Google Drive is not fixed. An owner can appoint another contributor as the new owner. This is deliberate design, and it makes sense in everyday life. Imagine you work with a colleague on a document they wrote, and then they leave the company and their account is closed. The shared document should not simply vanish. Someone else has to become its owner. That cannot be decided automatically, so the current owner is the one who chooses the successor.
Quick testing confirmed that Colaboratory notebooks are managed like any other Google document. Using Google Drive's settings, the owner, and therefore the "author" shown in the warning, can be changed to any of the file's contributors.
Carrying out the attack
With the owner field under the attacker's control, the attack follows directly. There are four steps.
Step 1: Create the notebook
Create a new notebook in Colaboratory and write the malicious code in it. At this point the notebook belongs to the attacker, which is normal: whoever creates a document owns it.
Step 2: Share it with the victim
Share the notebook with the victim, making them a contributor. This step is needed anyway, because the victim cannot open or run code in a file they have no access to. Sharing is the same action you would take to collaborate on any Google document: you enter the other person's address and give them edit rights.
Step 3: Hand over ownership
Using Google Drive, locate the notebook and set the victim as its owner. The victim is now the document owner, and the owner is exactly the identity the execution warning treats as the "author". The attacker has not touched the warning at all; they have only changed the fact the warning reads.
Step 4: Send the link
Send the notebook link to the victim. When the victim opens it and runs the code, the warning no longer names the attacker as the author, because the notebook's owner is now the victim. The security warning is effectively neutralised, and the victim runs the attacker's code in their own environment.
The report includes a proof of concept video showing first the normal behaviour and then the spoofed one. The video is not reproduced here.
Why it worked
The warning works out the notebook's "author" from the document owner in Google Drive. Ownership, however, is a sharing setting that can change: the current owner can transfer it to any contributor. The security decision therefore trusts a value the attacker can set. This is a common pattern in security problems: a check that looks solid, but bases its answer on information the attacker controls.
The existing defence, the execution warning, was not broken technically. It was given a false identity, so it displayed the victim's own name where the attacker's should have been.
What the impact is
An attacker can make a malicious notebook appear to be authored by the victim, which removes the main obstacle to getting the victim to execute the attacker's code in the victim's own Colaboratory environment. The attack still requires the victim to be a contributor to the notebook, and to open the link and run the code.
What the fix would look like
Based on the root cause, the warning should not rely on the mutable owner field alone. It should identify the user who actually supplied the code, or at least make clear that ownership can be transferred and does not imply authorship.
Other places to look
The same idea can be tested elsewhere. These are starting points, not confirmed bugs:
- Other Google products that show an author or owner in a security-relevant prompt, such as Docs, Sheets or Apps Script. A positive result is a prompt that names a different person after ownership is transferred to the victim.
- Any sharing model where ownership can be reassigned, on other platforms. A positive result is a warning or trust indicator that changes to the victim's identity after the transfer.
- Notebooks with multiple contributors. A positive result is a warning that names the owner rather than the contributor who wrote the executed cell.
Glossary
- Abuse research: security work that looks at how a product can be misused to harm people, rather than only at programming mistakes.
- Author (in the warning): the person the warning says wrote the notebook; in this case it is taken from the document owner.
- Bounty: a payment a company makes to a researcher who reports a valid security problem.
- Colaboratory (Colab): Google's service for writing and running Python notebooks in the browser.
- Container: a small, isolated computer environment created for a session and discarded afterwards.
- Contributor: someone a document has been shared with who can edit it.
- Endpoint: a specific address or function of a service that a program talks to; the report names none.
- Identity spoofing: making something appear to come from a person other than the real one.
- Jupyter notebook: a document format that mixes text, code and code output.
- Owner: the account that ultimately controls a Google Drive document, including who can access it.
- Parameter: a named value passed to a service in a request; the report names none.
- Proof of concept (PoC): a demonstration that a problem is real, often a video or a small script.
- Python: a popular programming language, the one used in Colab notebooks.
- Root cause: the underlying reason a problem exists, as opposed to its visible symptom.
- Serverless: a way of running code where the provider manages the machines, so you never see or maintain a server yourself.
- Session: one period of working in Colab, backed by a fresh environment.
- Vulnerability class: the general category a bug belongs to, such as spoofing or injection.