šŸ› fix(kavach): read where format-patch, archive, bundle, clone and init write

Merged
AT
15d ago
+351-4

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-directory and --output on 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 writes format-patch -1 --subject-prefix -- -o <dir>. A short-flag cluster hiding o (-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-dir are 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, -u and --template are 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> init was and is refused.
  • -o stays unread on other verbs (git grep -o, git push -o).

Evidence

  • Before the fix, a probe row per command, from self.claude writing to self.external, passed the guard: 11 of 11. Only archive --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 --output test. It has refused rows (spellings, permuted options, -- as a value, -C nested with 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) beside ow-git-diff-files-output.
  • #152's owned-clone row git clone . .tmp/copy still reaches clone_writers' refusal; no row moved.
  • Locally, test_boundary.py and test_worktree_guard.py pass (179 tests). The full pnpm --filter @veda-hq/kavach check was 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_options stopping at --, and bugreport -o, diagnose -o, index-pack -o, config -f and checkout-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 -C folder: -o/-o<v> plus --output-directory on 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.
  • -o on git grep -o and git push -o stays unread.