Repository navigation
fix: reject symlinks with rooted/absolute targets in Untar, for #8213 (#8625) [skip ci] - #8625
Conversation
There was a problem hiding this comment.
Looks good to me.
I see the error during import. Although it's err: mkdir file exists rather than archive entry escapes destination directory, but it's fine.
Test with an absolute symlink:
Prepare an archive:
rm -rf $HOME/tmp/outside-vault $HOME/tmp/pack-a $HOME/tmp/pack-b $HOME/tmp/breakout-archive.tar $HOME/tmp/breakout-archive.tar.gz
mkdir -p $HOME/tmp/outside-vault $HOME/tmp/pack-a/data $HOME/tmp/pack-b/breakout
echo SAFE-CONTENT > $HOME/tmp/outside-vault/secret.txt
# ordinary files that should extract normally
echo "hello from archive" > $HOME/tmp/pack-a/data/hello.txt
echo "just some info" > $HOME/tmp/pack-a/data/info.txt
# the malicious pair
ln -s $HOME/tmp/outside-vault $HOME/tmp/pack-a/breakout
echo TAMPERED-BY-TARBALL > $HOME/tmp/pack-b/breakout/secret.txt
# benign files + symlink first, write-through entry last
tar -cf $HOME/tmp/breakout-archive.tar -C $HOME/tmp/pack-a data breakout
tar -rf $HOME/tmp/breakout-archive.tar -C $HOME/tmp/pack-b breakout/secret.txt
gzip -f $HOME/tmp/breakout-archive.tar
tar -tvf $HOME/tmp/breakout-archive.tar.gzTest it (before):
$ rm -rf foobar && ddev import-files --source=$HOME/tmp/breakout-archive.tar.gz --target=foobar
Successfully imported files for test-project
$ tree -a foobar
foobar
├── breakout -> /home/stas/tmp/outside-vault
└── data
├── hello.txt
└── info.txt
3 directories, 2 filesTest it (after):
$ rm -rf foobar && ddev import-files --source=$HOME/tmp/breakout-archive.tar.gz --target=foobar
Error: failed to import files for test-project: failed to extract provided archive: symlink target "/home/stas/tmp/outside-vault" in archive entry "breakout" is absolute, which is not allowed
$ tree -a foobar
foobar
└── data
├── hello.txt
└── info.txt
2 directories, 2 filesTest with a relative symlink (confirming that previous fix works as expected):
Prepare an archive:
rm -rf $HOME/tmp/outside-vault $HOME/tmp/rel-pack-a $HOME/tmp/rel-pack-b $HOME/tmp/relative-escape.tar $HOME/tmp/relative-escape.tar.gz
mkdir -p $HOME/tmp/outside-vault $HOME/tmp/rel-pack-a/data $HOME/tmp/rel-pack-b/breakout
echo SAFE-CONTENT > $HOME/tmp/outside-vault/secret.txt
# ordinary file that would extract normally
echo "hello from archive" > $HOME/tmp/rel-pack-a/data/hello.txt
# relative symlink climbing out of the project to an absolute-ish host location
ln -s ../../../../../../../../home/stas/tmp/outside-vault $HOME/tmp/rel-pack-a/breakout
echo TAMPERED-BY-TARBALL > $HOME/tmp/rel-pack-b/breakout/secret.txt
# benign file + relative symlink first, write-through entry last
tar -cf $HOME/tmp/relative-escape.tar -C $HOME/tmp/rel-pack-a data breakout
tar -rf $HOME/tmp/relative-escape.tar -C $HOME/tmp/rel-pack-b breakout/secret.txt
gzip -f $HOME/tmp/relative-escape.tar
tar -tvf $HOME/tmp/relative-escape.tar.gzTest it (before):
$ rm -rf foobar && ddev import-files --source=$HOME/tmp/relative-escape.tar.gz --target=foobar
Error: failed to import files for test-project: failed to extract provided archive: symlink target "../../../../../../../../home/stas/tmp/outside-vault" in archive entry "breakout" escapes destination directory
$ tree -a foobar
foobar
└── data
└── hello.txt
2 directories, 1 fileTest it (after):
$ rm -rf foobar && ddev import-files --source=$HOME/tmp/relative-escape.tar.gz --target=foobar
Error: failed to import files for test-project: failed to extract provided archive: symlink target "../../../../../../../../home/stas/tmp/outside-vault" in archive entry "breakout" escapes destination directory
$ tree -a foobar
foobar
└── data
└── hello.txt
2 directories, 1 file|
Download the artifacts for this pull request:
See Testing a PR. |
…basing
Tar Linkname strings are POSIX-style regardless of the host OS. On
Windows, filepath.IsAbs("/var/www/html/...") returns false (no drive
letter), so that absolute-looking target skipped rebasing entirely and
was written to disk raw and unconstrained by dest, per the
ddev-windows-mutagen CI failure on
#8625.
Separately, a genuinely native-Windows absolute Linkname (e.g. a
drive-lettered path) would have been naively concatenated onto dest
via filepath.Join, producing an invalid path with an embedded drive
letter/colon.
isArchiveAbsolutePath now recognizes POSIX-style ("/"-prefixed),
bare-rooted ("\"-prefixed), and native (drive-lettered/UNC) absolute
targets uniformly. rebaseUnderDest strips any volume name and leading
slashes before joining onto dest, so absolute targets of either style
are always rebased into a single valid path under dest, on every
platform.
Co-Authored-By: Claude Sonnet 5 <[email protected]>
|
Changed it to reject rooted tarballs, thanks for re-review. Much more satisfying. |
stasadev
left a comment
There was a problem hiding this comment.
Thank you!
The error is now clear, I tested it again and updated my comment.
|
The This is a real, deterministic hit, not flakiness. The These were baked in whenever the fixture was originally tarred up from a live project directory, and until this PR I don't think this says anything bad about the fix itself — it's arguably the fix working as intended, just surfacing a 2-year-old quirk in this one test fixture. @rfay is going to regenerate/update the test artifact to drop the absolute symlinks. |
…he escape check ## The Issue Follow-up to CVE-2026-32885 (GHSA-9hq4-hm3j-jmph). The ZipSlip fix in 05cbe29 validated absolute symlink targets by rebasing them under `dest` (`filepath.Join(dest, file.Linkname)`), but then created the symlink with the raw, un-rebased `file.Linkname` via `os.Symlink`. The value that was validated was not the value that was written, so the on-disk symlink could point at an arbitrary absolute host path even though the check passed. A follow-up regular-file entry traversing that planted symlink could then overwrite arbitrary files outside `dest` (e.g. shell rc-files), reachable via `ddev add-on get` and `ddev import-db`/`import-files`. ## How This PR Solves The Issue `Untar`'s `tar.TypeSymlink` case now creates the symlink using `resolvedTarget` (the rebased path) whenever the original target is absolute, instead of the raw `file.Linkname`. Relative targets are unchanged, since their resolution already matches what was validated. ## Manual Testing Instructions 1. Build an archive containing a `tar.TypeSymlink` entry with an absolute `Linkname` pointing outside the extraction directory, followed by a `tar.TypeReg` entry whose name traverses that symlink. 2. Run `archive.Untar(tarball, dest, "")`. 3. Before this fix, the file outside `dest` is overwritten. After this fix, the symlink is rebased under `dest`, so the write lands inside `dest` instead. ## Automated Testing Overview - Extended `TestUntarPathTraversal/absolute_symlink_container_path_allowed` to assert the created symlink target is actually rebased under `dest`, not just that `Untar` returns no error. - Added `TestUntarPathTraversal/absolute_symlink_write_through_escape`, a regression test reproducing the advisory's PoC (planted absolute symlink + traversing regular-file entry); fails against the old code and passes with this fix. ## Release/Deployment Notes Security fix; no user-facing behavior change for legitimate archives. Absolute symlink targets in tar archives (e.g. container paths like `/var/www/html/...`) are still permitted, but are now consistently confined under the extraction destination on disk. Co-Authored-By: Claude Sonnet 5 <[email protected]>
…basing
Tar Linkname strings are POSIX-style regardless of the host OS. On
Windows, filepath.IsAbs("/var/www/html/...") returns false (no drive
letter), so that absolute-looking target skipped rebasing entirely and
was written to disk raw and unconstrained by dest, per the
ddev-windows-mutagen CI failure on
#8625.
Separately, a genuinely native-Windows absolute Linkname (e.g. a
drive-lettered path) would have been naively concatenated onto dest
via filepath.Join, producing an invalid path with an embedded drive
letter/colon.
isArchiveAbsolutePath now recognizes POSIX-style ("/"-prefixed),
bare-rooted ("\"-prefixed), and native (drive-lettered/UNC) absolute
targets uniformly. rebaseUnderDest strips any volume name and leading
slashes before joining onto dest, so absolute targets of either style
are always rebased into a single valid path under dest, on every
platform.
Co-Authored-By: Claude Sonnet 5 <[email protected]>
…asing Rebasing absolute symlink targets under dest was the root cause of the escape bugs in this function (GHSA-9hq4-hm3j-jmph and the Windows filepath.IsAbs gap it exposed). A dev-environment archive extracted by Untar has no legitimate need to plant an absolute symlink target, so rather than continue trying to safely place one under dest, reject any absolute Linkname outright and only allow relative targets, which are resolved against and confined to the symlink's parent directory as before. This removes isArchiveAbsolutePath's now-unnecessary companion (pathUnderDest) along with the absolute-target branch entirely, closing the whole class of bugs rather than patching around it. Updated TestUntarPathTraversal accordingly: the container-path test now expects rejection instead of asserting a rebased target, and the write-through regression test now asserts Untar itself returns an error for the planted absolute symlink. Co-Authored-By: Claude Sonnet 5 <[email protected]>
The comment asserted Linkname is always POSIX-style regardless of host OS, then justified checking for non-POSIX (backslash/drive-letter) forms anyway. Linkname comes from the archive being extracted and cannot be trusted to follow that convention, so all three forms need checking explicitly, regardless of which OS is running. No logic change. Co-Authored-By: Claude Sonnet 5 <[email protected]>
…ymlink [skip buildkite]
Magento 2.4.9 requires MariaDB 12.3 (recommended) or 11.8 per Adobe's system requirements; the magento2ConfigOverrideAction was still hardcoding the 2.4.7-era MariaDB 10.6, which no longer matches the supported version or the rebuilt test-magento2 fixture.
…Rs [skip buildkite] An inline `git commit -m "$(cat <<'EOF' ... EOF)"` heredoc just failed silently when chained with `&&`, even though this pattern was already warned against for PR-initial commits. Generalize the rule so it's not missed on ordinary commits.
a3a05d6 to
92ea701
Compare
|
I updated the test-magento2 test fixture to current 2.4.9, which also required a minor change to magento.go. I think this is probably OK, but may be reviewed with slight suspicion. The files tarball now is explicitly created without the rooted symlink. |
The Issue
Follow-up to CVE-2026-32885 / GHSA-9hq4-hm3j-jmph.
The ZipSlip fix in 05cbe29 (#8213) added a symlink-target escape check to
Untar, but for an absolute (rooted)Linknameit validated a copy rebased underdestwhile creating the symlink on disk with the raw, un-rebased target. The value that was validated was not the value that was written: a malicious archive could plant a host-absolute symlink that passed the check, and a follow-up regular-file entry that traversed that symlink could overwrite arbitrary files outsidedest(e.g.$HOMErc-files), reachable viaddev add-on get <repo|url>andddev import-db/import-files.Attempting to fix this by rebasing absolute targets under
dest(rather than rejecting them) turned out to be its own recurring source of bugs: a Windows CI run surfaced a second escape, becausefilepath.IsAbsis host-OS-dependent and doesn't recognize a POSIX-style rooted path (/var/www/...) as absolute on Windows, so that rebasing was silently skipped there too.How This PR Solves The Issue
Rather than continue trying to safely rebase absolute symlink targets under
dest,Untarnow rejects any rooted/absoluteLinknameoutright — a dev-environment archive has no legitimate need to plant one.isArchiveAbsolutePathdetects a rooted target in any spelling (POSIX/..., bare-rooted\..., or a native drive-lettered/UNC path), regardless of which OS is running, andUntarreturns an error for it instead of trying to place it somewhere safe. Only relative symlink targets are extracted, resolved against and confined to the symlink's own parent directory, as before.Manual Testing Instructions
tar.TypeSymlinkentry with a rootedLinkname(e.g. an absolute path outside the extraction directory), optionally followed by atar.TypeRegentry whose name traverses that symlink.archive.Untar(tarball, dest, "").outside
dest. After this PR:Untarreturns an error for the rooted symlink entry and nothing is written outsidedest.Automated Testing Overview
In
pkg/archive/archive_test.go,TestUntarPathTraversal:absolute_symlink_target_with_traversal/absolute_symlink_target_rejected: any rooted symlink target — including one shaped like a container path (/var/www/html/...) that a prior version of this fix special-cased as allowed — is now rejected outright.absolute_symlink_write_through_escape: regression test reproducing the advisory's PoC (planted rooted symlink + traversing regular-file entry). Verified this fails against the pre-fix code (host file overwritten) and now passes:Untarerrors out on the rooted symlink entry before the write-through can happen.go test ./pkg/archive/...andmake staticrequiredpass. Cross-compiled and vetted forGOOS=windows(no Windows machine available locally); verification of the actual Windows path handling depends on theddev-windows-mutagenBuildkite pipeline.Release/Deployment Notes
Security fix for GHSA-9hq4-hm3j-jmph. Behavior change: tar archives containing a symlink with a rooted/absolute target will now fail to extract with an explicit error, instead of being silently rebased under the destination directory. No code elsewhere in the repository was found to depend on absolute symlink targets surviving extraction.
Moved from a private fork because merging a security advisory ignores the configured merge strategy and commit message: