fix: prevent symlink-following arbitrary file overwrite in zipx.Unzip (VU#293714)#163
Open
tomasilluminati wants to merge 2 commits into
Open
fix: prevent symlink-following arbitrary file overwrite in zipx.Unzip (VU#293714)#163tomasilluminati wants to merge 2 commits into
tomasilluminati wants to merge 2 commits into
Conversation
🦋 Changeset detectedLatest commit: 39853c6 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Author
VU#293714 - https://certcc.github.io - @laurie-tyz |
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.
Problem
zipx.Unzipcan overwrite files outside the output directory via symlink following. Two gaps:createSymlinkpasses the archive's link target straight toos.Symlink, with no check that it stays inside the output dir.O_NOFOLLOW, so a write follows a symlink an earlier entry planted at the same path. On case/Unicode-folding volumes (APFS, HFS+) the colliding names need not be byte-identical (ßfolds ontoss).A crafted archive (a symlink pointing outside, then a colliding regular entry) overwrites an arbitrary file the build user can write.
Fix
--outputstill compares correctly.O_NOFOLLOWto regular-file writes (syscall.O_NOFOLLOWon unix,0on windows via a build tag).Unsafe entries are skipped, not fatal (same as node-tar and bsdtar).
Tests
Regression tests that fail on current master and pass with this change: symlink-escape refusal, no write-through a planted symlink, the single-archive race (0 overwrites over 100 runs), the APFS
ss/ßvector (darwin), containment boundary cases, and a benign-archive guard.go vetclean; cross-compiles on linux/windows/darwin (amd64 + arm64).Update: added the coordination and CI items
Changeset / CHANGELOG. Added
.changeset/zipx-symlink-following-fix.md(app-builder-bin, patch). The repo uses changesets, so this makes the check pass and generates the CHANGELOG entry on the next release.Summary.
zipx.Unzipfollows symlinks it materializes from the archive, allowing an arbitrary file overwrite outside the output directory.createSymlinkwrites the entry's target verbatim with no containment check, and regular-file writes open withoutO_NOFOLLOW, so a write follows a symlink an earlier entry planted at the same path. On case/Unicode-folding volumes (APFS, HFS+) the colliding names need not be byte-identical (ßfolds ontoss).Impact. Attacker-controlled content written to an arbitrary path the build user can write (integrity and availability). Local, requires a build to consume a crafted archive.
Breaking changes. None for well-formed archives. Only unsafe entries (symlinks whose resolved target escapes the output dir) are skipped; this is non-fatal, matching node-tar and bsdtar.
Authorship and license. Authored by Tomas Illuminati (@tomasilluminati), coordinated with Laurie Tyzenhaus ( @laurie-tyz ) and CERT/CC under VU#293714. Contributed under the repository's existing MIT license.