Security Hardening: Prevent Zip Slip (Arbitrary File Write) in ExtractUtil#337
Open
Samer666569 wants to merge 2 commits intogoogle:masterfrom
Open
Security Hardening: Prevent Zip Slip (Arbitrary File Write) in ExtractUtil#337Samer666569 wants to merge 2 commits intogoogle:masterfrom
Samer666569 wants to merge 2 commits intogoogle:masterfrom
Conversation
|
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. |
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.
This PR patches a potential Zip Slip vulnerability in ExtractUtil.java by validating that the destination path of extracted archive entries resolves strictly within the intended target directory.
Previously, malicious archives containing directory traversal sequences (EX: ../../evil.txt) could potentially write files outside the working directory during extraction.
Changes:
ExtractUtil.java: Added normalize() and startsWith() checks to sanitise entry paths before writing. Throws IOException if a traversal attempt is detected.
ExtractUtilTest.java: Added a regression test (testExtractArchive_zipSlipVulnerability) to verify that path traversal attempts are correctly blocked.
Context & Background:
This issue was originally reported to the Google VRP (Report #474540831). While the security team determined that malicious build rules fall outside the immediate threat model, they acknowledged that the victim relies on the tool to handle upstream archives safely.
I am submitting this fix as a Defense in Depth measure. It protects developers from compromised upstream repositories or "Honeypot" archives, ensuring that even if a user configures Copybara to fetch from an untrusted source, the tool does not facilitate arbitrary file writes on the host machine.
Existing tests passed.
New test case confirms the fix blocks the exploit.
For better context, I am attaching the PoC video that was originally submitted with VRP Report #474540831.
Video demonstrates the Zip Slip vulnerability in action: simply running Copybara against a malicious archive results in a file being written outside the destination directory (Arbitrary File Write), confirming the need for the path validation logic added in this PR.
2026-01-09.19-13-45.mp4