šŸ› fix: writers refuse a symlink that leads out of the git toplevel

Merged
AT
20d ago
+267-6

Slice: #360

Closes #360.

niyam's writers no longer follow a symlink out of the git toplevel. kavach 0.6.9 (veda-hq/veda#95) lets these commands run from an owned worktree on the claim that niyam writes only under the toplevel, and a link broke that claim.

  • Sys.confine(root, path) is the one helper. It finds the nearest part of path that is there, by lstat, so a link that leads nowhere counts. It follows that part's links and throws unless the real path is the toplevel's real path or lies under it, compared by whole segments. The error names the path, where it leads and the toplevel.
  • cubic-dismiss checks its ledger before reading or writing it, and refuses with exit 1.
  • handoff --record / --assert-fresh check the run log before judging a push or opening a --open-brief issue, and again at the append.
  • keep-going --stop says no stop note was written. The Stop hook checks its counter and the stop note before either is read. It still fails open, but says why.

Tests use real symlinks: a linked file, a linked folder (committed and untracked), a linked .tmp/push, a linked .tmp and a dangling link. Each one refuses, and the outside folder stays empty or unchanged. With confine made a no-op, the cubic-dismiss, handoff and keep-going tests fail, and handoff and keep-going write outside.

docs/decisions.md records this as P-67. Left for its own slice: pr-autocreate has the same gap under .tmp/pr-autocreate, but kavach 0.6.9 does not let it run from a worktree.

Guards: none. Only src/ and docs/decisions.md change.

Checked: pnpm check passes.

šŸ¤– Generated with Claude Code


Summary by cubic

Writers that could follow a symlink out of the git toplevel now refuse, closing the gap kavach 0.6.9 opened by allowing these commands to run from an owned worktree.

  • Adds Sys.confine(root, path): it finds the nearest existing part of path by lstat, follows its links, and throws unless the real path stays under root; a dangling link refuses too, and the error names the path, its target, and the toplevel.
  • cubic-dismiss checks its ledger, handoff --record/--assert-fresh check the run log, and keep-going --stop checks the stop note and counter — before any read or write.
  • keep-going --stop exits 1 with "No stop note written" on refusal; pr-autocreate has the same gap but is left for its own slice.