šŸ› fix(kavach): git's --output is a write target on every subcommand

Merged
AT
16d ago
+113-2

Slice: #162

From a Claude-managed desktop worktree, kavach let a git subcommand outside READ_GIT write its --output file anywhere: git diff-files --output=/elsewhere/x passed, and so did diff-index, range-diff, shortlog, whatchanged, format-patch, reflog and stash show (#161). 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 used to return [] for every verb outside READ_GIT and worktree. Now it ends in git_output_options, which:

  • reads --output=<v> and --output <v> before -- as write targets, resolved from the -C folder;
  • refuses as unproven a strict prefix of --output (--o … --outpu), with or without =, and an empty or --leading value.

READ_GIT and git_inspection_outputs are unchanged, so git shortlog -sn and git format-patch -1 -o .tmp still run, and --output-directory, --output-indicator-* and --onto don't match.

Git 2.54 already rejects every --output abbreviation as ambiguous with --output-indicator-*, so refusing them guards other git versions, not a hole that's open today.

Tests

  • test_boundary.py, test_git_output_elsewhere_is_refused_on_every_subcommand, sits beside the existing --output tests rather than in test_worktree_guard.py. Its first 7 rows passed the guard before the fix. It also covers quoted and spaced values, -C nested with a relative path, abbreviations and missing values (unresolved), and the commands that must still run.
  • It also refuses --output="$HOME/x" and --output=$X as unresolved.
  • corpus.json: a new attack row, ow-git-diff-files-output, sits beside ow-git-output.
  • test_worktree_guard.py: #152's owned-clone row git whatchanged --outpu=.claude/hooks/guard.sh is now refused earlier, as unresolved, so it moves out of the fence rows and asserts that reason.
  • pnpm --filter @veda-hq/kavach check, run locally on #152's main: the full Python suite (725 tests) passed except that one row, which was then fixed, and both changed tests pass. typecheck and build pass. pnpm test passed 758 of 759: the failure was run-child's pipe test, the #147 race that #159 has since fixed on main. Since then the branch has been rebased onto #159, which changes only run-child.test.ts and the version in kavach. 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.
  • format-patch -o, archive -o, bundle create, clone <dir> and init <dir> name destinations the guard doesn't read either. They're filed as #163.

šŸ¤– Generated with Claude Code


Summary by cubic

Fixes kavach's git guard so --output is treated as a write target on every git subcommand, not just the read verbs in READ_GIT. Previously git diff-files --output=/elsewhere/x — and the same on diff-index, range-diff, shortlog, whatchanged, format-patch, reflog, and stash show — wrote anywhere from a Claude-managed worktree; now each is refused as outside the session's worktree.

  • Reads --output=<v> and --output <v> before -- as write targets, resolved from the -C folder; abbreviations and missing or option-like values fail closed as unresolved, while existing reads like git shortlog -sn and -o .tmp are unaffected.
  • Adds a boundary test and a corpus.json attack row covering spaced, quoted, and -C-relative values, and moves the owned-clone whatchanged --outpu row to the unresolved path.
  • Other destination options (format-patch -o, archive -o, bundle create, clone, init) remain unguarded, filed as #163.