š fix(kavach): read where format-patch, archive, bundle, clone and init write
Slice: #174
From a Claude-managed desktop worktree, kavach let five git verbs write outside the worktree, because it read only --output on them (#163): git format-patch -1 -o /elsewhere, git archive -o /elsewhere/x.tar HEAD, git bundle create /elsewhere/x.bundle HEAD, git clone <repo> /elsewhere/copy and git init /elsewhere/repo. Now each is refused with "outside this session's Claude worktree".
The change
In packages/kavach/python/kavach/boundary.py, the git branch of mutation_path_operands now joins git_output_options (#162) with a new git_destination_operands. Both are resolved from the -C folder, and a None from either fails the command closed.
- format-patch, archive (
git_dash_o_outputs):-o <v>and-o<v>, plus--output-directoryand--outputon format-patch. Every word is read, since git permutes options. A--doesn't stop the read either: an option that takes the next word takes--too, and git 2.54 still writesformat-patch -1 --subject-prefix -- -o <dir>. A short-flag cluster hidingo(-ko, which git takes as-k -o), an abbreviation of--output-directory, and a missing or option-like value fail closed. - bundle create (
git_bundle_outputs): the first word after create's own options is the file it writes. An unknown option before it fails closed. - clone, init (
git_repository_destinations): the directory operand and--separate-git-dirare write targets. Git takes abbreviations here (--sep=wrote) and lets options follow operands, so this parses an exact option table, and an unknown option or too many operands fails closed.-c,-uand--templateare left out of the table because they run or install programs. clone's repository is never resolved, since it may be a URL. With no directory, git writes under the folder it runs in, which the guard already counts:git -C <outside> initwas and is refused. -ostays unread on other verbs (git grep -o,git push -o).
Evidence
- Before the fix, a probe row per command, from
self.claudewriting toself.external, passed the guard: 11 of 11. Onlyarchive --output=was refused, by #162. - Git 2.54 wrote every one, run for real into
.tmp/. The git behaviour the parsers rely on is recorded on #163.
Tests
test_boundary.py,test_git_destination_operands_elsewhere_are_refused, sits beside the--outputtest. It has refused rows (spellings, permuted options,--as a value,-C nestedwith a relative path), unproven rows (missing values, abbreviations, unknown options, clusters, too many operands), and rows that must still run:git format-patch -1 -o .tmp,git archive -o .tmp/x.tar HEAD,git clone . .tmp/copy,git init .tmp/repo,git grep -o,git push -o.corpus.json: five attack rows (ow-git-format-patch-o,-archive-o,-bundle-create,-clone-dir,-init-dir) besideow-git-diff-files-output.- #152's owned-clone row
git clone . .tmp/copystill reaches clone_writers' refusal; no row moved. - Locally,
test_boundary.pyandtest_worktree_guard.pypass (179 tests). The fullpnpm --filter @veda-hq/kavach checkwas stopped partway when the--fix went in and hasn't been rerun locally. CI runs the whole check.
Not here
- No version bump. The release slot comes from veda's release queue, and sessions are guarded by this only after a release, a pin bump and an install in the main checkout.
- Same-class gaps listed on #163 for later:
git --git-dir=/--work-tree=before the subcommand,-c format.outputDirectory=<dir>(probed: writes),git_output_optionsstopping at--, andbugreport -o,diagnose -o,index-pack -o,config -fandcheckout-index --prefix(from reading the code, not probed).
Closes #163.
š¤ Generated with Claude Code
Summary by cubic
Fixes kavach letting five git verbs write outside the Claude worktree by only reading --output on them: git format-patch -o, git archive -o, git bundle create <file>, git clone <repo> <dir>, and git init <dir> are now refused with "outside this session's Claude worktree".
Bug Fixes
- Each verb now has its own destination reader, resolved from the
-Cfolder:-o/-o<v>plus--output-directoryon format-patch, bundle create's first operand, and clone/init directory operands plus--separate-git-dir. - Missing values, unknown options, option abbreviations, clusters hiding
o, and extra operands fail closed. -oongit grep -oandgit push -ostays unread.