Repository navigation
Fix path traversal (Zip Slip, CVE-2026-112302) in extract() - #75
Open
tsurutanmen wants to merge 2 commits into
Open
tsurutanmen wants to merge 2 commits into
tsurutanmen wants to merge 2 commits into
Conversation
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
Fixes the Zip Slip path traversal in
extract()reported as CVE-2026-112302 / GHSA-m3xg-f8vh-5p22 (CWE-22), affecting releases up to 2.3.02.Problem
ArchiveZip::extract()built the destination path by concatenating the extraction path with the raw entry name, without validating the entry name. An archive containing entries such as../escaped.txtorsub/../../escaped2.txttherefore writes files outside the extraction directory, with attacker-controlled contents.I verified this locally against the current main: extracting a crafted ZIP wrote both files outside the target directory. (
extractAll()is not affected, as it delegates to PHP's nativeZipArchive::extractTo().)Fix
BaseArchive::safeExtractPath(), which lexically resolves an entry name against the destination directory and throws an exception if the entry would escape it. Entries containing..that stay inside the destination (e.g.sub/../file.txt) still extract as before.ArchiveZip::extract(),ArchivePhar::extract()andArchiveRar::extract()now resolve their write paths through this helper, since they share the same sink pattern.Tests
tests/ArchiveZipSlipTest.phpregression tests: traversal entries are rejected and nothing is written outside the destination. These tests fail on the unfixed code and pass with this change.