# Arbitrary file read  via the bulk imports UploadsPipeline

Bulk group import untarred uploads.tar.gz without stripping symlinks, letting an attacker read arbitrary server files like secrets.yml via a crafted archive.

- Payout: $29,000
- Severity: critical
- Program: GitLab
- Found by: vakzz
- Disclosed: 2022-03-21
- Write-up quality: 9/10
- Original: https://hackerone.com/reports/1439593
- Library page: https://bugbountylibrary.com/r/h1%3A1439593
- Tags: area:web domain:web impact:data-leak impact:internal-access kind:bounty platform:hackerone sev:critical tech:ruby technique:source-review vuln:path-traversal

**Target:** GitLab bulk imports UploadsPipeline (uploads.tar.gz extraction)
**Root cause:** untar_zxf only changes permissions and does not remove symlinks; extracted symlinks are globbed into file paths and followed by File.open during load, so symlink targets are read and re-uploaded.
**Steps:**
1. Create a group, add a milestone, upload a file `passwd`; note the 32-byte upload secret in the path.
2. Build archive: `mkdir ./<hash>; ln -s /etc/passwd ./<hash>/passwd; ln -s /srv/gitlab/config/secrets.yml ./<hash>/secrets.yml; tar cvzf uploads.tar.gz ./<hash>`
3. Run a Flask proxy that serves the malicious uploads.tar.gz in place of the real one; expose via ngrok.
4. Create a personal access token; start a group import pointing at the ngrok URL with the token.
5. Import the original group; the symlinks are followed and file contents stored as new uploads.
6. Open the milestone passwd link to read /etc/passwd; swap `passwd` for `secrets.yml` in the URL to download secrets.
**How found:** Code reading of UploadsPipeline: noticed extract() calls untar_zxf then globs all paths, and load() opens each path with File.open without checking for symlinks; compared to project import which strips symlinks, hypothesized tar symlinks would be followed.
**Exploitation:** Attacker with group-import capability hosts a malicious uploads.tar.gz via a proxy/ngrok, supplies it as the import source with a PAT, and the server extracts symlinks and follows them, storing target file contents as accessible uploads that the attacker then downloads.
**Escalation:** Reading secrets.yml exposes secret_key_base, otp_key_base, db_key_base, and RSA signing keys, enabling further compromise beyond file read.
**Insight:** When auditing archive-extraction import pipelines, check whether symlinks/hardlinks are stripped before globbing and File.open; compare the vulnerable importer against a sibling importer that already sanitizes, since the fix often exists in one path but not the other.

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

**Symlink tar payload for arbitrary file read**

```
mkdir ./d3209c811fee407218bff7cb3b4333e6
ln -s /etc/passwd ./d3209c811fee407218bff7cb3b4333e6/passwd
ln -s /srv/gitlab/config/secrets.yml ./d3209c811fee407218bff7cb3b4333e6/secrets.yml
tar cvzf uploads.tar.gz ./d3209c811fee407218bff7cb3b4333e6
```

**Malicious uploads.tar.gz proxy server**

```
Save the following simple proxy server as `api.py` and run it with `FLASK_APP=api flask run`, this will replace the `uploads.tar.gz` with a custom one
```

