Repository navigation
fix(archive): symlink targets go to the kernel; digests and compares go slash-canonical - #577
Merged
Merged
Conversation
…go slash-canonical 4.5 section 4 ruled it: the kernel restricts following, not making, and containedLinkTarget was a second implementation of that rule -- the hand-rolled copy, broken on Windows, where a POSIX-absolute target is rooted but not filepath.IsAbs and both guards wave it through. Deleted, not fixed. An escaping or absolute target now extracts exactly as authored, and the containment lives where the kernel enforces it: a follow through a confined root is refused at use. tar accepts the same residual, for the same reason. Deleting the guard exposed the defect it had been standing in front of: Resource.Resolve verifies existence through Stat, which FOLLOWS the link, so the post-create check turned the kernel's refusal into a Link failure -- the exact Windows trace (statat out/link: path escapes from parent). SymbolicLink already rules that the link is the resource, not its referent, and observes with lstat in Digest and Etag; Resolve now says the same: rebind, lstat, not-exist is a legal observation. The digest failure proved a second fact: Windows reads a created link back with native separators, so the sha256 of the raw readlink bytes changes with the platform. The digest now hashes the target in canonical slash form -- the same rule Path.Rel follows for document bytes: equal logical targets digest equally everywhere, and on unix ToSlash is the identity so no digest changes there. The same fact broke existingLinkMatches' verbatim compare -- an authored slash target never equals the native read-back, so every Windows re-run replaced an already-correct link; the compare is slash-canonical now too. TestExtract_SymlinkTargetEscapes pinned the deleted guard's refusal; it is now TestExtract_EscapingSymlinkTargetLandsVerbatim, which pins the new contract end to end: extraction succeeds, the link lands verbatim modulo separator rendering, and a confined Stat through it is refused with something that is not not-exist. TestSymbolicLinkDigest_LiteralTarget needed no change -- its expectation was the slash form all along; the implementation now meets it on Windows. Expected Windows movement: TestExtract_SymlinkTargetEscapes and TestSymbolicLinkDigest_LiteralTarget leave the known-failure set -- the baseline goes 8 to 6, the first count movement since 28 to 8. Verified with make check (103 packages ok, 0 failures) and make vet under GOOS windows and linux. Closes #556. Refs #430, #568.
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.
4.5 §4 ruled it: the kernel restricts following, not making — and
containedLinkTargetwas a secondimplementation of that rule, the hand-rolled copy that is broken on Windows (a POSIX-absolute target is
rooted but not
filepath.IsAbs, so both guards wave it through). Deleted, not fixed.The contract now
An escaping or absolute symlink target extracts exactly as authored, and containment lives where the
kernel enforces it: a follow through a confined root is refused at use.
taraccepts the same residual, forthe same reason.
file.Provider.Link'sverbatimflag survives — writing the archive's target as authoredis simply correct once containment is the kernel's business.
What the deletion exposed (and this PR fixes)
Resource.Resolvefollows the link. Its existence check goes throughStat, so the post-create checkturned the kernel's refusal into a
Linkfailure — the exact Windows trace(
statat out/link: path escapes from parent).SymbolicLinkalready observes with lstat inDigestandEtag("the link is the resource, not its referent"); it now has its ownResolvesaying the same.fe57…≠ sha256 ofthe authored slash target).
SymbolicLink.Digestnow hashes the target in canonical slash form, thesame rule
Path.Relfollows for document bytes: equal logical targets digest equally on every platform.On Unix
ToSlashis the identity — no digest changes there.existingLinkMatches' verbatim compare was broken by the same fact: the authored slash target neverequals the native read-back, so every Windows re-run replaced an already-correct link. Slash-canonical
compare now.
Tests
TestExtract_SymlinkTargetEscapespinned the deleted guard; it becomesTestExtract_EscapingSymlinkTargetLandsVerbatim, pinning the new contract end to end: extraction succeedsfor
../../etc/passwdand/etc/passwd, the link lands verbatim (modulo separator rendering), and aconfined
Statthrough it is refused with something that is not not-exist.TestSymbolicLinkDigest_LiteralTargetneeded no change — its expectation was the slash form all along.Expected Windows movement — the review check
The name-for-name diff against develop's baseline 8 should show exactly two names removed, none added:
TestExtract_SymlinkTargetEscapesTestSymbolicLinkDigest_LiteralTargetBaseline 8 → 6 — the first count movement since 28 → 8.
Verified
make check— 103 packages ok, 0 failures (the rewritten test passes on Unix: escaping links extract,confined follow refused)
make vetGOOS=windows, GOOS=linuxgofmt -l— clean; repo-wide grep: zerocontainedLinkTargetreferencesCloses #556. Refs #430, #568.