Repository navigation
/cso audits repositories that track symlinks - #4540
nathanshox wants to merge 3 commits into
Conversation
A repository that tracks any symlink cannot be audited: gstack-cso start fails with UNSAFE_PATH "Symlink or special source file", even when the link is a relative pointer to another file in the same repository, such as a CLAUDE.md that points to AGENTS.md. The capture loop refused the same links a second time with "Special source input". Nothing records why ordinary links were refused; the existing tests only cover links that escape the repository or are broken. Accept a link whose relative target resolves, lexically and through every intermediate link, to a regular file or directory inside the repository, and record it like a nested repository boundary: one manifest entry, originalHash not-read, an excluded: transformation that discloses the omission in snapshot-inputs coverage, nothing followed or copied, and an identity check during capture so a retargeted, replaced or deleted link fails with SNAPSHOT_RACE. The identity covers the inode, the target and the repository path the link resolves to, so an intermediate link that moves the chain elsewhere also fails, and the target is re-read to rule out inode reuse between the two lstat calls. The target is captured under its own path. Git hashes a link as its target string, so base comparison stays exact. When nothing at the target is audited, the link is withheld instead, so coverage counts it as a gap. That covers a target the snapshot does not capture, such as an ignored file or Git metadata, and a target outside --paths. A link inside a host dependency tree such as node_modules, or outside --paths, is bound by identity without resolving its target: excluded with the rest of the dependency tree, or listed as out of scope. A dangling node_modules/.bin link does not block the run. A --paths entry that is itself a symlink would audit only the link, so it is refused with the path it points to. Absolute, escaping, broken and cyclic links, links that resolve to a FIFO or device, and chains that escape through an ignored link are still refused.
--paths scopes what an audit reads, but the special-file walk covers the whole checkout. One escaping link or untracked FIFO anywhere in the repository blocks a run that would never read it, and narrowing --paths cannot get around it. Walk only the audit scope and its ancestors, comparing names without case: on a case-insensitive filesystem the on-disk name can differ from Git's spelling, and walking too much is the safe error. A symlink outside the scope, escaping or not, is then recorded as withheld, bound to its identity without resolving its target, so it still appears in the out-of-scope list and a change during capture still fails closed. Inside the scope an escaping, broken or special link is still refused, and so is a tracked path outside the scope that has been replaced on disk by a FIFO.
|
Merging to
After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here |
|
Thank you @nathanshox. I confirmed this by reading main (92c6c8a): |
…4540) (#4567) `/cso` no longer stops on a repository that tracks a symlink, such as gstack's own `connect-chrome` or `CLAUDE.md -> AGENTS.md`: each link is listed in the report by its target string, or as withheld when the target matches a secret pattern, and it is never followed. Why: a security audit that refuses ordinary repositories audits nothing, and following a link would let it point the scanner at `/etc/passwd` or out through `..`. Nothing to do. FIFOs, sockets and devices are still refused, and `--paths` now limits that check to the audited directories. Co-authored-by: nathanshox <[email protected]> Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> Review-Finding: p1/specialist-batched#1 reader=security Review-Finding: p1/red-team#3 reader=red-team Review-Finding: p2/red-team#1 reader=red-team Review-Finding: p3/outside-voice#1 reader=outside-voice
|
Thanks @nathanshox for finding this and for the first fix. We rebuilt it on current main as #4567, which is now merged, and credited you as co-author. /cso now audits repositories that track symlinks. It records each link by its target string and never follows it. A target that looks like a secret is withheld from the report. FIFOs, sockets and devices inside the audited paths are still refused, and |
/csocan now audit a repository that tracks symlinks, such as aCLAUDE.mdthat links toAGENTS.md. Today one such link stops every run. A link that stays inside the repository is now listed as an exclusion in coverage and never followed, and its target is audited under its own path. Users need no new flag or setting.What this fixes
gstack-cso startfails withUNSAFE_PATH "Symlink or special source file"whenever the checkout tracks a symlink, even a relative link to another file in the same repository. Many repositories linkCLAUDE.mdtoAGENTS.mdso that every agent reads one instruction file.--pathsdoesn't help either. The special-file walk inrejectSpecialFilescovers the whole checkout whatever the scope, and the capture loop refuses a symlink outside--pathswithSpecial source input.Why the refusal looks unintended
No comment, doc or commit explains why a contained link is refused. The tests cover only links that escape the repository (
/etc/passwd, an outside directory) or are broken. The rest of the codebase already treats contained links as safe:treeManifest(..., allowContainedSymlinks)inlib/cso/preparation-executor.tsaccepts a relative link whose target stays inside the tree, andtest/cso-preparation-adversarial.test.tspins it.excluded:snapshot entries instead of failing the run. This PR uses the same shape.What changed
In-repository links (
fix(cso): record in-repository symlinks as explicit snapshot exclusions)realpath), to a regular file or directory inside the repository.originalHash: not-read, transformationIN_REPOSITORY_LINK(excluded: ...). So it appears under snapshot-inputs exclusions, not as a gap. Nothing is followed or copied; the target is captured under its own path.withheldand coverage counts it as a gap. That covers a target the snapshot doesn't capture (an ignored file,.git/config) and, under--paths, a target outside the scope.assertEntriesStablere-checks the link's inode, its target and the repository path it resolves to. A link that is retargeted, replaced or deleted during capture, or whose intermediate links come to resolve elsewhere, fails withSNAPSHOT_RACE. The target is read twice, so a link that reuses the inode between the twolstatcalls is caught too.node_modulesis excluded like the rest of that tree, and a link outside--pathsis listed as out of scope. Both are bound by identity without resolving their target, so a danglingnode_modules/.binlink does not block the run.--pathsentry that is itself a symlink is refused withINVALID_ARGUMENT, naming the path it points to; otherwise the scope would audit only the link.../escapes, broken or looping links, links that resolve to a FIFO or device, and chains that escape through an ignored link.A link's target is not part of the snapshot's original identity. That matches every other not-read entry, since the link is never followed.
Scope (
fix(cso): a special file outside --paths no longer blocks the audit)--pathsscope and its ancestors. It compares names without case, so a directory whose on-disk case differs from Git's spelling is still walked.This is a separate commit, so it can be dropped if you'd rather keep the walk repository-wide. The first commit stands on its own; the changelog's last clause about an untracked FIFO or a symlink outside
--pathswould go with it.Tests
New cases in
test/cso-ordinary-repos.test.ts, next to the nested-repository ones:starton a repository with a tracked file link and an untracked directory link succeeds. Both links are listed as exclusions, there are no gaps, and the snapshot holds the targets but not the links.web/README.md -> ../README.md) is accepted and is not a changed path against a base that already had it..git/configare gaps, and the ignored target is not in the snapshot.node_modulesis excluded, not refused.UNSAFE_PATH.SNAPSHOT_RACE.--paths: a link entry is refused, an in-scope link to an out-of-scope target is a gap, an out-of-scope link is listed as out of scope, and an entry deleted from disk is recorded as a deletion.Existing symlink tests in
test/cso-snapshot-state.test.tsandtest/cso-ordinary-repos.test.tspass unchanged.Checks (macOS)
bun run typecheck: no errors.bun run typecheck:test: no new diagnostics.bun run format:cso:check: clean.test/cso-ordinary-repos.test.tsandtest/cso-snapshot-state.test.ts: all pass at each commit.test/cso-*.test.tsfiles: 836 pass, 35 skip, 3 fail. The same 3 fail onmainon this machine: the archive-cache lease recovery, the forged TAP summary witness and the Python runner import order.gstack-cso start --scope auth --offlinenow starts, and its links are listed asexcluded: symlink to a file or directory inside this repository. Before the fix, the same command failed withUNSAFE_PATH.