Skip to content

fix(archive): symlink targets go to the kernel; digests and compares go slash-canonical - #577

Merged
David-Noble-at-work merged 1 commit into
developfrom
symlink-targets-to-the-kernel
Aug 20, 2026
Merged

David-Noble-at-work merged 1 commit into
developfrom
symlink-targets-to-the-kernel

Conversation

@David-Noble-at-work

Copy link
Copy Markdown
Contributor

4.5 §4 ruled it: the kernel restricts following, not making — and containedLinkTarget was a second
implementation 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. tar accepts the same residual, for
the same reason. file.Provider.Link's verbatim flag survives — writing the archive's target as authored
is simply correct once containment is the kernel's business.

What the deletion exposed (and this PR fixes)

  1. Resource.Resolve follows the link. Its existence check goes through Stat, 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 observes with lstat in Digest and
    Etag ("the link is the resource, not its referent"); it now has its own Resolve saying the same.
  2. Windows reads a link back with native separators — proven by the digest failure (fe57… ≠ sha256 of
    the authored slash target). SymbolicLink.Digest now hashes the target in canonical slash form, the
    same rule Path.Rel follows for document bytes: equal logical targets digest equally on every platform.
    On Unix ToSlash is the identity — no digest changes there.
  3. existingLinkMatches' verbatim compare was broken by the same fact: the authored slash target never
    equals the native read-back, so every Windows re-run replaced an already-correct link. Slash-canonical
    compare now.

Tests

TestExtract_SymlinkTargetEscapes pinned the deleted guard; it becomes
TestExtract_EscapingSymlinkTargetLandsVerbatim, pinning the new contract end to end: extraction succeeds
for ../../etc/passwd and /etc/passwd, 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.

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_SymlinkTargetEscapes
  • TestSymbolicLinkDigest_LiteralTarget

Baseline 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 vet GOOS=windows, GOOS=linux
  • gofmt -l — clean; repo-wide grep: zero containedLinkTarget references

Closes #556. Refs #430, #568.

…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.
@David-Noble-at-work David-Noble-at-work self-assigned this Aug 20, 2026
@David-Noble-at-work
David-Noble-at-work merged commit 203a540 into develop Aug 20, 2026
7 of 8 checks passed
@David-Noble-at-work
David-Noble-at-work deleted the symlink-targets-to-the-kernel branch August 20, 2026 17:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Archive symlink targets bypass containment on Windows

1 participant