fix: reject zip-slip / path-traversal entries in extractTarball#22
Merged
fix: reject zip-slip / path-traversal entries in extractTarball#22
Conversation
`tar.extract({ strip: 1 })` on an attacker-controlled tarball will happily
write `../../etc/passwd` if the entry path escapes cwd after the strip.
Add an explicit `filter` predicate that rejects:
- empty paths
- absolute paths (POSIX leading `/`)
- Windows drive-letter paths ("C:foo", "C:\\…")
- entries that normalize to something starting with `..` (escapes cwd)
The first rejected entry is captured and surfaced as a `DownloadError`
with a new `UNSAFE_ENTRY` code, instead of `filter` silently skipping it.
Tests: `isSafeTarEntry` is now exported and covered with safe + unsafe
cases including a regression check that mid-path `..` segments which
collapse back inside cwd are still accepted.
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.
From the 2026-05-01 audit (P1.4):
tar.extract({ strip: 1 })had nofilter— a hostile or corrupt tarball entry like../../etc/passwdwould extract outside the destination directory.Fix
isSafeTarEntry()predicate (exported) that rejects empty, absolute (POSIX), Windows drive-letter, and..-escape paths.filtercallback inextractTarballconsults the predicate.DownloadErrorcodeUNSAFE_ENTRY...that collapses back inside cwd.Test plan