Skip to main content
Menu
Advisories

File attestor follows symlinks outside the base path and records out-of-tree files

GHSA-V6PX-JQX8-8XWJPublished Updated GitHub

Description

RecordArtifacts resolves a symbolic link with filepath.EvalSymlinks and then recurses into the resolved path with no check that the target stays within the base path being attested. A symlink in the attested directory tree that points outside it causes the file attestor to open, hash, and record the out-of-tree target. Running witness run over an attacker-influenced directory (a checked-out repository, a pull-request build, an unpacked archive) therefore reads files outside the intended workspace (secrets, system files) and records their digests and paths into the attestation.

Impact

Two effects. First, arbitrary out-of-tree file read by the attestor: it opens and hashes the symlink target, so a malicious tree can make witness run read and fingerprint files outside the workspace (disclosing existence and digests of secrets or system files), and can point at large or special files. Second, attestation poisoning: the attestation claims artifacts that are actually files outside the intended tree. In CI this is reachable whenever witness run attests a directory whose contents an attacker can influence (a PR branch, an untrusted source checkout, an unpacked archive). Confidentiality and integrity impacts are Low individually (VC:L / VI:L); there is no availability impact in scope. PR:L reflects that the attacker must be able to place a symlink in the attested directory.

Real-world exploitation conditions. The attacker controls (or can write a symlink into) the directory tree that witness run attests. No special privileges beyond that are required (AT:N).

Details

In RecordArtifacts (go-witness attestation/file/file.go), when a path is a symlink the code resolves it and recurses into the resolved location (attestation/file/file.go:66):

if info.Mode()&fs.ModeSymlink != 0 {
    linkedPath, err := filepath.EvalSymlinks(path)
    ...
    visitedSymlinks[linkedPath] = struct{}{}
    symlinkedArtifacts, err := RecordArtifacts(linkedPath, baseArtifacts, hashes, visitedSymlinks, processWasTraced, openedFiles, dirHashGlob)
    ...
}

linkedPath is the fully resolved target. There is a visitedSymlinks set to prevent infinite loops, but no check that linkedPath is contained within the original basePath. So a symlink inside the attested tree that resolves to a file (or directory) outside the tree is followed, and the out-of-tree content is opened, hashed, and added to the returned artifact map under the in-tree link name.

Proof of Concept

A secret file is placed outside the attested tree; a symlink inside the working directory points to it. After witness run, the out-of-tree file's real SHA-256 appears in the attestation's material set.

# BUILD the witness CLI (needs Go; this PoC also needs openssl + python3):
#   git clone https://github.com/in-toto/witness && cd witness && git checkout main \
#     && go build -o /tmp/witness . && cd - && export PATH=/tmp:$PATH

SECRET=$(mktemp /tmp/outoftree-secret.XXXXXX); echo "TOP-SECRET-OUT-OF-TREE" > "$SECRET"
mkdir att && cd att
echo "in-tree" > realfile.txt
ln -s "$SECRET" leak.link            # symlink to a file OUTSIDE the attested tree
openssl genpkey -algorithm ed25519 -out k.key
witness run --step build -a environment -k k.key -o att.json -- /bin/echo hi

# The attestation's material set now contains the out-of-tree file (its real sha256):
SECRET="$SECRET" python3 - <<'PY'
import json,base64,hashlib,os
s=json.loads(base64.b64decode(json.load(open('att.json'))['payload']))
mats={v for a in s['predicate']['attestations'] if a['type'].endswith('material/v0.1')
        for ds in (a['attestation'] or {}).values() for v in ds.values()}
print("out-of-tree digest recorded:", hashlib.sha256(open(os.environ['SECRET'],'rb').read()).hexdigest() in mats)
PY
#   -> out-of-tree digest recorded: True

Observed: out-of-tree digest recorded: True. The file attestor followed leak.link outside the attested tree and recorded the secret's digest.

Suggested fix

After EvalSymlinks, verify the resolved target is within basePath before recursing (for example with filepath.Rel(basePath, linkedPath) and rejecting any result that escapes with .. or is absolute outside the base), and skip targets that resolve outside the attested tree. Optionally make the behavior configurable for operators who deliberately want to follow out-of-tree symlinks, but default to staying within the base path.

Affected versions

References

GitHub · in-toto/go-witness