Repository navigation
fix(release): prevent tar/zip slip path traversal in artifact extraction - #333
Conversation
The tar.UntarGz() and zip.Unzip() extractors joined attacker-controlled archive entry names onto the destination directory without any confinement, so an entry named e.g. "../../go/bin/cosign" could escape the temporary unpack directory and overwrite arbitrary files on the shared Cloud Build volume, leading to code execution with the release credentials in scope (CWE-22 / CWE-59 / CWE-94). Guard both extractors with filepath.IsLocal() to reject absolute paths and parent-directory traversal, open regular files with O_EXCL so an entry can no longer silently overwrite an existing file, and mask the mode to permission bits to drop setuid/setgid/sticky. Symlink and hardlink tar entries are now rejected outright since their link targets are attacker-controlled. Add tests covering well-formed extraction and rejection of traversal, absolute-path and symlink/hardlink entries. Co-Authored-By: Claude Opus 4.8 <[email protected]> Signed-off-by: Felix Phipps <[email protected]>
|
Hi @FelixPhipps. Thanks for your PR. I'm waiting for a cert-manager member to verify that this patch is reasonable to test. If it is, they should reply with Tip We noticed you've done this a few times! Consider joining the org to skip this step and gain Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
/ok-to-test
It's important to say that the bundles don't come from an untrusted source. The only SAs with access to the staging bucket are trusted maintainers, CNCF admins and CI processes designed specifically for the purpose of releasing cert-manager. That doesn't mean this PR has no value - defence in depth is good! - but we'd consider it a code red high severity situation if anyone untrusted could ever access that bucket. |
SgtCoDFish
left a comment
There was a problem hiding this comment.
/lgtm
/approve
Hardening / defence in depth. We don't need to go super deep on this - thanks! 🚀
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: SgtCoDFish The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Description
Problem
The cmrel gcb publish command downloads pre-built artifact bundles from a GCS staging area and unpacks them inside the privileged Cloud Build worker. The extractors tar.UntarGz() and zip.Unzip() write each archive entry to filepath.Join(dst, header.Name) with the entry name taken at face value — and a bundle can come from an untrusted source (anyone with write access to the staging bucket). The current code writes them with no safeguards:
Solution
Guard both extractors with filepath.IsLocal() to reject absolute paths and parent-directory traversal, open regular files with O_EXCL so an entry can no longer overwrite an existing file, and mask the mode to permission bits to drop setuid/setgid/sticky. Symlink and hardlink tar entries are rejected outright. Legitimate release archives behave unchanged.
Test plan