Skip to content
CSRF Write-up Advanced

CSWSH vulnerability in Google Cloud Shell’s code editor

The Google Cloud Shell code editor's WebSocket endpoint on cloudshell.dev subdomains did not properly validate the origin of WebSocket connections, allowing cross-site WebSocket hijacking. An attacker could execute arbitrary commands on a victim's Cloud Shell virtual machine and access their GCP resources.

Psi Follow

Published on ψ.fun

Google Cloud Shell is a product of the Google Cloud Platform (GCP) that provides a number of interesting features, such as an interactive shell environment and an integrated code editor, with the intent of making experimenting and administration of GCP products easier while requiring very little setup.

Psi, on ψ.fun

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.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Root cause

The WebSocket endpoint on cloudshell.dev subdomains did not check the Origin header, so it accepted cross-site connections authenticated only by a cookie.

Impact

An attacker could execute arbitrary commands on the victim's Cloud Shell virtual machine and potentially access the victim's GCP resources, but only if the attacker knows the victim's Cloud Shell IP address or DNS name and can convince the victim to visit a malicious page.

What the attacker needed

Attacker knows victim's Cloud Shell IP or DNS name; victim clicks a link; attacker has own Cloud Shell instance

The fix

The vulnerability was fixed by having the virtual machine's server compare the Origin header of WebSocket requests with its own host name and reject mismatches.

How it was found

  1. The attacker obtains their own Cloud Shell instance and disables authentication on it, then hosts a malicious page that performs CSWSH.
  2. The attacker sends a request to the victim's Cloud Shell editor URL with a spoofed Host header pointing to the attacker's instance, which triggers an OAuth redirect.
  3. The attacker persuades the victim to follow that redirect link, which sets the authentication cookie and forwards the victim to the malicious page.
  4. The malicious page opens a WebSocket to the victim's editor and sends messages to spawn a shell and execute commands.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

WebSockets are a way for a browser to keep a two-way connection open with a website. Normally, a website cannot read data from another website, but WebSocket connections do not follow that rule. Here, the editor's WebSocket accepted connections from other sites, so a malicious page could take over the editor and run commands on the victim's machine.

What is CSRF?

Another site makes a signed-in user's browser perform an action they did not intend.

More by Psi

View all

3 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.

Cross-site request forgery (CSRF)

The lesson behind this report.

Another site makes a signed-in user's browser perform an action they did not intend.