Repository navigation
fix: prevent path traversal (ZipSlip) in Untar and Unzip - #8213
Merged
Merged
Conversation
|
Download the artifacts for this pull request:
See Testing a PR. |
…x2xq-qhjf-5mvg ## The Issue - Fixes GHSA-x2xq-qhjf-5mvg `filepath.Join(dest, file.Name)` resolves `../` sequences, allowing a crafted archive entry to write files outside the intended destination directory. Symlink targets in tar archives had the same issue. The affected functions are used in `ddev import-db`, `ddev import-files`, and all CMS-specific file import handlers — a realistic attack vector when a developer receives a database dump or file archive from an untrusted or compromised source. ## How This PR Solves The Issue Added path containment checks to both `Untar()` and `Unzip()` in `pkg/archive/archive.go`: 1. After computing `fullPath`, verify `filepath.Clean(fullPath)` is prefixed by `filepath.Clean(dest)+/`. Any entry that escapes the destination returns an error immediately. 2. For symlinks in tar archives, resolve the link target (relative targets resolved against the symlink's parent directory; absolute targets used as-is) and apply the same containment check. ## Manual Testing Instructions Run the new tests: ``` go test -v -run "TestUntarPathTraversal|TestUnzipPathTraversal" ./pkg/archive/ ``` ## Automated Testing Overview - `TestUntarPathTraversal`: three subtests covering `../` in file path, `../` in symlink target, and absolute symlink target outside dest - `TestUnzipPathTraversal`: verifies zip traversal is blocked - All existing archive tests continue to pass ## Release/Deployment Notes Any archive containing entries that escape the destination directory will now return an error instead of writing outside it. Legitimate archives are unaffected. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
rfay
force-pushed
the
20260310_tar_traversal
branch
from
March 10, 2026 17:04
c1461e4 to
257cdba
Compare
rfay
marked this pull request as ready for review
March 11, 2026 19:05
Member
Author
|
I think this is probably OK. I'm running TestDdevFullSiteSetup manually, as all the tarballs in that could have been broken. |
rfay
added a commit
that referenced
this pull request
Mar 27, 2026
… them PurgeDirectory and PurgeDirectoryExcept used os.Stat (via util.Chmod) which follows symlinks. If a symlink's target was already removed earlier in the loop, the stat would fail with ENOENT. Use os.Lstat instead and skip chmod for symlinks — symlinks have no meaningful permissions of their own and os.RemoveAll removes the symlink entry itself without following it. This surfaced in TestDdevImportFilesDir for TYPO3: the v13.4.19 files.tgz contains test.txt as a symlink to README.txt. After #8213 added TypeSymlink handling to Untar, symlinks are now extracted to the host. When README.txt was removed before test.txt in the purge loop, test.txt became a dangling symlink and the subsequent util.Chmod failed. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
rfay
added a commit
that referenced
this pull request
Mar 27, 2026
… them [skip buildkite] PurgeDirectory and PurgeDirectoryExcept used os.Stat (via util.Chmod) which follows symlinks. If a symlink's target was already removed earlier in the loop, the stat would fail with ENOENT. Use os.Lstat instead and skip chmod for symlinks — symlinks have no meaningful permissions of their own and os.RemoveAll removes the symlink entry itself without following it. This surfaced in TestDdevImportFilesDir for TYPO3: the v13.4.19 files.tgz contains test.txt as a symlink to README.txt. After #8213 added TypeSymlink handling to Untar, symlinks are now extracted to the host. When README.txt was removed before test.txt in the purge loop, test.txt became a dangling symlink and the subsequent util.Chmod failed. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
rfay
added a commit
that referenced
this pull request
Jul 29, 2026
…#8625) [skip ci] Co-authored-by: Claude Sonnet 5 <[email protected]>
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.
The Issue
filepath.Join(dest, file.Name)resolves../sequences, allowing a crafted archive entry to write files outside the intended destination directory. Symlink targets in tar archives had the same issue.The affected functions are used in
ddev import-db,ddev import-files, and all CMS-specific file import handlers — a realistic attack vector when a developer receives a database dump or file archive from an untrusted or compromised source.How This PR Solves The Issue
Added path containment checks to both
Untar()andUnzip()inpkg/archive/archive.go:fullPath, verifyfilepath.Clean(fullPath)is prefixed byfilepath.Clean(dest)+/. Any entry that escapes the destination returns an error immediately.Manual Testing Instructions
Run the new tests:
Automated Testing Overview
TestUntarPathTraversal: three subtests covering../in file path,../in symlink target, and absolute symlink target outside destTestUnzipPathTraversal: verifies zip traversal is blockedRelease/Deployment Notes
Any archive containing entries that escape the destination directory will now return an error instead of writing outside it. Legitimate archives are unaffected.