fix: prevent zip-slip/tar-slip path traversal in gcs-fetcher#1086
Open
mohammadmseet-hue wants to merge 1 commit intoGoogleCloudPlatform:masterfrom
Open
fix: prevent zip-slip/tar-slip path traversal in gcs-fetcher#1086mohammadmseet-hue wants to merge 1 commit intoGoogleCloudPlatform:masterfrom
mohammadmseet-hue wants to merge 1 commit intoGoogleCloudPlatform:masterfrom
Conversation
The archive extraction functions in fetcher.go use filepath.Join(dest, untrustedName) without verifying that the result stays within the destination directory. An archive entry named "../../../etc/cron.d/evil" resolves to /etc/cron.d/evil, escaping the extraction directory. Three independent vectors are affected: - unzip() line 777: ZIP entry file.Name - fetchFromTarGz() line 887: tar header h.Name - fetchObject() line 289: manifest j.filename This adds a safeJoin() helper that validates the resolved path remains under the base directory, matching the pattern used in Google's own go-containerregistry (mutate.go:298-320). Ref: CVE-2018-1002200 (Zip Slip class)
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
94376fa to
a674346
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The archive extraction functions in
gcs-fetcher/pkg/fetcher/fetcher.gousefilepath.Join(dest, untrustedName)without verifying the result stays within the destination directory. Archive entries with../in the filename escape the extraction directory and write files to arbitrary paths.Affected Code (3 vectors)
filepath.Join(dest, file.Name)filepath.Join(gf.DestDir, h.Name)filepath.Join(dest, j.filename)None of these validate that the resolved path remains under the base directory.
Why filepath.Join does NOT prevent this
filepath.Joincleans paths but does NOT constrain them. This is the well-known Zip Slip class (CVE-2018-1002200).The Fix
Adds a
safeJoin()function that validates the resolved path stays under the base directory usingstrings.HasPrefixafterfilepath.Clean. Applied to all 3 vectors.This matches the pattern used in Google's own
go-containerregistry(mutate.go:298-320).Impact
gcs-fetcher runs as the first step in Google Cloud Build pipelines. A malicious source archive (zip/tar.gz) with traversal entries can write files outside
/workspace/, overwriting build scripts or injecting code into downstream build steps that execute with the build service account's credentials.