šŸ› fix(kavach): read where git bugreport, diagnose, index-pack, config and checkout-index write

Merged
AT
14d ago
+487-9

Slice: #181

From a Claude-managed desktop worktree, kavach let these git commands write outside the worktree (#179):

  • git bugreport -o /elsewhere and git diagnose -o /elsewhere
  • git index-pack -o /elsewhere/x.idx x.pack
  • git config -f /elsewhere/x core.x y
  • git 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-dir and --work-tree were 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-directory from --o on, anywhere in the arguments. An option that takes the next word takes -- too, so git 2.54 writes both bugreport --suffix -- -o <dir> and bugreport --suffix -- --o=<dir>.
  • index-pack (git_index_pack_outputs): this reads -o and the pack operand. Git writes the .idx, .rev and .keep beside the pack, and with --stdin it 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 --global or --system fails 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_safety does. An abbreviated value option swallows --, and git 2.54 writes config --comm -- -f <file> core.x y.
  • checkout-index (git_checkout_index_paths): --prefix and its abbreviations are resolved from the top of the work tree, as git does. git -C sub checkout-index --prefix=../x/ ../a writes <top>/../x/a, not <top>/x/a.

Evidence

  • Before the fix, probe rows in test_boundary.py (from self.claude, writing to self.external) passed the guard for every spelling above. Git 2.54 wrote each one for real into .tmp/.
  • No other --output verb wrote with -- taken as an option's value. On diff-index, diff-files, diff-tree, reflog, stash show, shortlog, whatchanged and range-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-tree forms, 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> --list and checkout-index -a --prefix=.tmp/co/
  • test_worktree_guard.py, OwnCheckoutTest: in a hosted clone, git config --global user.name x is refused as unproven, and a read of it runs. config -f, bugreport and checkout-index are refused there by clone_writers' own rule, as before.
  • corpus.json: six attack rows beside ow-git-init-dir: ow-git-bugreport-o, -diagnose-o, -index-pack-o, -config-f, -checkout-index-prefix and -namespace-shifts-verb. The corpus tests pass (112).
  • Local runs:
    • test_boundary.py and test_worktree_guard.py pass (181 tests).
    • The full pnpm --filter @veda-hq/kavach check passes.

What sessions will see

These are now refused inside the worktree too:

  • git config --global or --system writes, such as git config --global user.name X
  • a git config option 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-import marks, pack-objects and read-tree --index-output
    • the GIT_DIR=-style prefixes
    • verbs that run a command (rebase -x, bisect run, …)
    • --attr-source missing 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/--system writes and unknown git config or global options are now refused; reads still run.
  • git checkout-index --prefix is resolved from the top of the work tree as git does, and git index-pack options are matched against an exact table.