# Path traversal in Nuget Package Registry

NuGet package registry concatenated attacker-controlled nuspec version into a filename, enabling path traversal to write .nupkg files anywhere, chained with a Gitaly race to read arbitrary files.

- Payout: $12,000
- Severity: high
- Program: GitLab
- Found by: saltyyolk
- Disclosed: 2022-06-07
- CVE: CVE-2020-12448
- Write-up quality: 8/10
- Original: https://hackerone.com/reports/822262
- Library page: https://bugbountylibrary.com/r/h1%3A822262
- Tags: area:web domain:web impact:data-leak impact:internal-access kind:bounty platform:hackerone sev:high tech:ruby technique:chained technique:race-window technique:source-review vuln:path-traversal vuln:race-condition

**Target:** GitLab EE NuGet package registry upload endpoint (/api/v4/projects/:id/packages/nuget/)
**Root cause:** MetadataExtractionService extracts the nuspec <version> via XPath and UpdatePackageFromMetadataService concatenates it unsanitized into the filename `#{package_name}.#{package_version}.nupkg`, allowing `../` traversal.
**Steps:**
1. Craft `dummy.nuspec` with `<id>DummyProject.DummyPackage</id>` and `<version>../../../../../nyangawa</version>`
2. Zip it into `dummy.nupkg`
3. Upload via `PUT /api/v4/projects/#{id}/packages/nuget/`
4. GitLab writes `nyangawa.nupkg` at a traversed filesystem path
5. Combine with Gitaly race condition to read arbitrary files (e.g. `.gitlab_shell_secret`)
**How found:** Code review of the new NuGet registry: noticed the nuspec <version> XPath value is concatenated directly into the output filename without sanitization, then reused a prior Gitaly race exploit from npm registry reports.
**Exploitation:** Attacker uploads a crafted nupkg whose nuspec version contains `../` sequences, causing GitLab to write a `.nupkg` file at an arbitrary path. Chained with a Gitaly race condition (previously used in npm registry reports) to convert the arbitrary write into arbitrary file read of sensitive files like `.gitlab_shell_secret`.
**Escalation:** Path traversal write alone only creates .nupkg files; chaining with a Gitaly race condition escalates to arbitrary file read of sensitive secrets.
**Insight:** When a new package registry format is added, check whether metadata fields (name/version) parsed from the package manifest are used to build filesystem paths; version strings are a common traversal vector since they're rarely validated.

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

**Upload endpoint for malicious nupkg**

```
PUT /api/v4/projects/#{id}/packages/nuget/` endpoint  will make GitLab to create a `nyangawa.nupkg`
```

