# The File uploading CSRF in Google Cloud Shell Editor

CSRF on Cloud Shell Editor's /files upload endpoint let an attacker write arbitrary files into the victim's VM, leading to stored XSS and persistent code execution via .bashrc.

- Payout: $5,000
- Severity: high
- Program: Google
- Found by: Obmi
- Disclosed: 2019-12-15
- Write-up quality: 8/10
- Original: https://obmiblog.blogspot.com/2019/12/gcp-5k-file-uploading-csrf.html
- Library page: https://bugbountylibrary.com/r/blog%3Aobmiblog-blogspot-com-2019-12-gcp-5k-file-uploading-csrf-html
- Tags: area:cloud domain:cloud impact:integrity impact:rce kind:bounty platform:blog sev:high tech:gcp technique:chained technique:parser-differential vuln:csrf vuln:file-upload vuln:xss

**Target:** Google Cloud Shell Editor (Theia) file upload endpoint /files and /mini-browser
**Root cause:** The /files multipart upload endpoint lacked CSRF protection (no X-XSRF-PROTECTED check on the cloudshell.dev:970 origin), and the multipart parser accepted a malformed Content-Disposition where name/filename were embedded in a single quoted field, enabling a plain HTML form to forge the upload.
**Steps:**
1. Identify victim editor host via CSP-report leak: serve a page with CSP allowing all but *.appspot.com and *.cloudshell.dev, embed an iframe to the editor; auth redirects to victim's own devshell-vm-<id>.cloudshell.dev:970 domain, which is reported as a CSP violation.
2. Craft HTML form POSTing multipart to https://<victim_devshell_domain>/files with input name=`target` value=`file:///home/userhome/folder` and input name=`upload; filename=the_filename; x` value=`<payload>`.
3. Submit form from attacker origin; server writes file with attacker content into victim home dir.
4. Load uploaded HTML via /mini-browser/home/<user>/uploaded.html to execute JS (XSS).
5. Use XSS to overwrite .bashrc or other startup files so code runs on every VM restart.
**How found:** Noticed the editor is reachable via two URLs and that the cloudshell.dev:970 origin lacked the X-XSRF-PROTECTED header protection present on the appspot origin; then fuzzed the multipart upload and found the parser accepted `name="upload; filename=the_filename; x"` as a single quoted field, which is expressible as an HTML input name, making a pure-form CSRF possible.
**Exploitation:** Attacker page auto-submits a cross-origin multipart form to the victim's Cloud Shell Editor /files endpoint (hostname leaked via CSP reports), writing an HTML/JS payload into the victim's home directory; the payload is then loaded through the /mini-browser feature to execute JS in the editor origin, which is used to persist code in .bashrc for execution on VM restart.
**Escalation:** Chained CSRF file-write -> stored XSS via /mini-browser -> persistent code execution by modifying .bashrc so payload runs on every Cloud Shell VM restart.
**Insight:** When a target exposes the same app on two origins, diff their CSRF/auth protections — the secondary origin often skips the header check. Also fuzz multipart Content-Disposition quoting: if the parser accepts name/filename inside one quoted token, a plain HTML form can forge the upload without JS.

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

**CSRF multipart file upload request**

```
POST /files HTTP/1.1

Host: devshell-vm-74ecb0ce-6db1-43df-a2f9-c77142a1e79e.cloudshell.dev:970

Content-Length: 337

Cookie: auth_cookie

Content-Type: multipart/form-data; boundary=------WebKitFormBoundaryduZBRk1aIPiq0b1V

------WebKitFormBoundaryduZBRk1aIPiq0b1V

Content-Disposition: form-data; name="target"

file:///home/userhome/folder

------WebKitFormBoundaryduZBRk1aIPiq0b1V

Content-Disposition: form-data; name="upload"; filename="the_filename"

the_content_of_file

------WebKitFormBoundaryduZBRk1aIPiq0b1V--
```

**HTML form PoC for upload CSRF**

```
<form action="https://<user_devshell_domain>/files" enctype="multipart/form-data" method="POST" target="upload_iframe">

 <input name="target" value="file:///home/userhome/folder">

 <input name="upload; filename=the_filename; x" value="the content of file">

</form>
```

