Repository navigation
Description
Instance of: #547
An archive entry whose symlink target is a POSIX-absolute path is accepted on Windows and materialized
verbatim, pointing outside the extraction root. TestExtract_SymlinkTargetEscapes reports it as
absolute target = <nil> -- the guard returned no error at all.
Why both guards miss it
containedLinkTarget (pkg/op/provider/archive/provider.go:978) asks the extracting host whether the
archive's string is absolute:
if filepath.IsAbs(linkname) { ... } // Windows: FALSE for "/etc/passwd"
resolved := filepath.Clean(filepath.Join(filepath.Dir(filepath.Clean(entryName)), linkname))
if resolved == ".." || strings.HasPrefix(resolved, ".."+string(filepath.Separator)) { ... }Windows absoluteness requires a volume (C:\) or a UNC prefix, so /etc/passwd is rooted but not
absolute and the first guard does not fire. filepath.Join(".", "/etc/passwd") then yields
\etc\passwd, which does not begin with .., so the second does not fire either.
The entry is accepted and handed to Link unchanged:
product, receipt, err := fileProvider.Link(activationRecord, entry.Linkname, target, true)A leading backslash on Windows resolves against the current drive's root, so the link points at
C:\etc\passwd -- outside the prefix that containment exists to enforce.
Entry names are not affected. containedTarget makes the same filepath.IsAbs mistake but follows it
with securejoin.SecureJoin, which catches the escape. Symlink targets have no equivalent backstop,
because ruling 1a writes them verbatim on purpose.
Mitigating factor, not a fix: creating a symlink on Windows normally requires Developer Mode or
elevation, so the follow-on write is not guaranteed to land. The guard is the defense-in-depth layer and it
is off on one platform.
The actual defect
Not "the absoluteness test is incomplete". Enumerating every absolute form -- leading /, leading \,
drive letter, UNC -- would patch the symptom and leave the cause.
A file object should be created from a URI, and the resource should compute the native source path. An
archive entry's Linkname is a portable string in the archive format's syntax, written on one machine and
read on another. It is URI-space, not path-space. Nothing here constructs a resource from it, so the
transform has no place to happen, and every site downstream is left guessing which world the string is in.
filepath appearing in containedLinkTarget is the tell.
Under the construction rule the guard becomes unambiguous: containment is answered in URI space, where a
leading / is absolute by definition and path semantics apply. No platform branch, nothing to get wrong.
Why the verbatim policy exists, and why the rule resolves it
Ruling 1a writes the target literally for two reasons, both in the comment at the call site: on-disk
fidelity, and the SymbolicLink digest hashing the literal target. Both pull against normalizing, which is
presumably why the guard was left carrying the whole burden.
A resource owning both forms serves both without conflict:
- the URI form is what the digest hashes, so the value stops changing with the separator
- the native form is what reaches the syscall
- containment is decided in URI space
Closes two of the campaign's sixteen
TestExtract_SymlinkTargetEscapes-- the bypass aboveTestSymbolicLinkDigest_LiteralTarget--Digest = fe57fce9...; want ...a3cd6f54..., the same string
doing duty as both a URI and a path
Both are in the windows-latest known-failure set tracked under #430 / #373.
Activity
docs: fsroot follows the kernel on symlink targets, and charters the …