š fix(kavach): read where git bugreport, diagnose, index-pack, config and checkout-index write
Slice: #181
From a Claude-managed desktop worktree, kavach let these git commands write outside the worktree (#179):
git bugreport -o /elsewhereandgit diagnose -o /elsewheregit index-pack -o /elsewhere/x.idx x.packgit config -f /elsewhere/x core.x ygit checkout-index -a --prefix=/elsewhere/git --namespace x init /elsewhere
The guard counted only the folder git runs in. In the last one it also read x as the subcommand. Now each is refused with "outside this session's Claude worktree".
The change
All in packages/kavach/python/kavach/boundary.py.
- Global options (
git_command): the options before the subcommand are read from git 2.54's exact list. Git takes no abbreviations there;--git-d=is refused. Any other word fails closed. Before, an unknown option was skipped one word at a time, so an option that takes the next word (--namespace,--attr-source) moved which word was read as the verb.-c,--config-env,--git-dirand--work-treewere already refused as unproven, and they stay refused. - bugreport, diagnose (
git_dash_o_outputs): these read-o <v>,-o<v>, and every prefix of--output-directoryfrom--oon, anywhere in the arguments. An option that takes the next word takes--too, so git 2.54 writes bothbugreport --suffix -- -o <dir>andbugreport --suffix -- --o=<dir>. - index-pack (
git_index_pack_outputs): this reads-oand the pack operand. Git writes the.idx,.revand.keepbeside the pack, and with--stdinit writes the pack itself. index-pack reads its own arguments, not through parse-options, so the option table is exact and an unknown option fails closed. - config (
git_config_file_outputs): this reads-f/--file, its abbreviations and its clusters (-zf,-f<file>).- A write to
--globalor--systemfails closed. - A read writes nothing:
get,list,--get*,--list, or a lone key with no action. - Any option the reader doesn't know fails closed, file option or not, as
git_safetydoes. An abbreviated value option swallows--, and git 2.54 writesconfig --comm -- -f <file> core.x y.
- A write to
- checkout-index (
git_checkout_index_paths):--prefixand its abbreviations are resolved from the top of the work tree, as git does.git -C sub checkout-index --prefix=../x/ ../awrites<top>/../x/a, not<top>/x/a.
Evidence
- Before the fix, probe rows in
test_boundary.py(fromself.claude, writing toself.external) passed the guard for every spelling above. Git 2.54 wrote each one for real into.tmp/. - No other
--outputverb wrote with--taken as an option's value. Ondiff-index,diff-files,diff-tree,reflog,stash show,shortlog,whatchangedandrange-diff, git refused the value.
Tests
test_boundary.py,test_git_more_destinations_elsewhere_are_refused, beside the #175 test. It has three groups of rows:- refused: the spellings, options after operands,
--as a value, abbreviations after it, and-C nested, including the top-relative--prefix - unproven: the
-c/--git-dir/--work-treeforms, unknown globals and options, and missing or option-like values - still running:
bugreport -o .tmp,config -f .tmp/x,config --global user.name,config -f <outside> --listandcheckout-index -a --prefix=.tmp/co/
- refused: the spellings, options after operands,
test_worktree_guard.py,OwnCheckoutTest: in a hosted clone,git config --global user.name xis refused as unproven, and a read of it runs.config -f,bugreportandcheckout-indexare refused there by clone_writers' own rule, as before.corpus.json: six attack rows besideow-git-init-dir:ow-git-bugreport-o,-diagnose-o,-index-pack-o,-config-f,-checkout-index-prefixand-namespace-shifts-verb. The corpus tests pass (112).- Local runs:
test_boundary.pyandtest_worktree_guard.pypass (181 tests).- The full
pnpm --filter @veda-hq/kavach checkpasses.
What sessions will see
These are now refused inside the worktree too:
git config --globalor--systemwrites, such asgit config --global user.name X- a
git configoption the reader doesn't know - an option before the subcommand that git 2.54 doesn't list
Not here
- No version bump. The release slot comes from veda's release queue. Sessions are guarded by this only after a release, a pin bump and an install in the main checkout.
- Other git writes that slip through are filed as #182:
merge-file,fast-export/fast-importmarks,pack-objectsandread-tree --index-output- the
GIT_DIR=-style prefixes - verbs that run a command (
rebase -x,bisect run, ā¦) --attr-sourcemissing from the command guard's own global tables
Closes #179.
š¤ Generated with Claude Code
Summary by cubic
Fixes kavach letting git bugreport, git diagnose, git index-pack, git config -f, and git checkout-index --prefix write outside the Claude worktree. The guard only counted the folder git ran in, so each could name a destination elsewhere; git 2.54 writes them all for real. Also fixes git --namespace x init reading x as the subcommand, since --namespace takes the next word.
git config --global/--systemwrites and unknowngit configor global options are now refused; reads still run.git checkout-index --prefixis resolved from the top of the work tree as git does, andgit index-packoptions are matched against an exact table.