fix(security): 2 improvements across 2 files#5281
fix(security): 2 improvements across 2 files#5281tomaioo wants to merge 2 commits intogoogle:masterfrom
Conversation
- Security: Path traversal during tar extraction can write outside temporary directory - Security: Arbitrary file write via unsanitized output path joining Signed-off-by: tomaioo <203048277+tomaioo@users.noreply.github.com>
- Security: Path traversal during tar extraction can write outside temporary directory - Security: Arbitrary file write via unsanitized output path joining Signed-off-by: tomaioo <203048277+tomaioo@users.noreply.github.com>
|
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. |
|
But... aren't we the ones writing the tars to the bucket in the first place? |
|
I probably don't mind merging this just as a defense in depth measure though |
|
Good question—today we do produce those tarballs, but this extractor is still parsing untrusted input at runtime (bucket contents can be replaced, stale artifacts can persist, or write credentials can be abused). |
3 similar comments
|
Good question—today we do produce those tarballs, but this extractor is still parsing untrusted input at runtime (bucket contents can be replaced, stale artifacts can persist, or write credentials can be abused). |
|
Good question—today we do produce those tarballs, but this extractor is still parsing untrusted input at runtime (bucket contents can be replaced, stale artifacts can persist, or write credentials can be abused). |
|
Good question—today we do produce those tarballs, but this extractor is still parsing untrusted input at runtime (bucket contents can be replaced, stale artifacts can persist, or write credentials can be abused). |
Summary
fix(security): 2 improvements across 2 files
Problem
Severity:
High| File:gcp/indexer/shared/shared.go:L57The tar extraction logic joins
tmpDirwithhdr.Nameand then cleans the result, but does not verify that the final path is still داخلtmpDir. A crafted tar entry such as../../etc/passwdor an absolute path can escape the destination directory and overwrite arbitrary files on the host.Solution
Before writing, validate each target path: reject absolute paths, reject
..traversal, and ensurestrings.HasPrefix(resolvedPath, tmpDir+string(os.PathSeparator)). Also handle tar header types explicitly (regular files only) and reject symlinks/hardlinks.Changes
gcp/indexer/shared/shared.go(modified)go/cmd/exporter/writer.go(modified)