Repository navigation
fix: close git-worktree bypass via global options and quote sourced colcon args - #25
Merged
Merged
Conversation
…olcon args Harden the two trust boundaries where CWM consumes agent-supplied input. #6 git worktree interception bypass: Both the shell-function wrapper and the PATH-shim wrapper detected the 'worktree' subcommand with a literal `$1` comparison, so an invocation that prefixes git global options - e.g. `git -C <path> worktree add` (which agents use heavily) - slipped past both interceptors and could mutate the overlay structure directly. Add a `__cwm_git_has_worktree` scanner to both wrappers that skips leading global options, correctly consuming value-taking options (`-C`, `-c`, `--git-dir`, `--work-tree`, ...) in pairs so their value is not mistaken for the subcommand. When 'worktree' is found behind global options the original argv is forwarded unshifted to the hook. The policy lives in one place: `git_hook` strips the globals via `_strip_git_globals` and refuses invocations carrying repository-retargeting options (`-C`/`--git-dir`/`--work-tree`), since those target a different repository and cannot be safely re-homed onto the CWM-managed overlay. #7 unquoted arguments on the sourced colcon path: `run_colcon_sourced` joined colcon arguments with a bare space before handing them to `bash -c`, so a value containing spaces or shell metacharacters (such as a `--cmake-args` value) was word-split or interpreted by the subshell. Quote each argument with `shlex.quote`, matching the treatment the source paths already received. Tests: real-bash wrapper cases proving `-C <path> worktree` reaches the hook and `-C <path> status` still goes to real git; Python cases for the global-option parsing and retarget refusal; a quoting case for a spaced `--cmake-args` value.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hardens the two trust boundaries where CWM consumes agent-supplied input. From the §1 triage of the review report (follows PR #24, which closed report items 1/2/5); this is the security pair, report items 6 and 7, deliberately bundled as the report recommended.
Item 6 —
git worktreeinterception bypassBoth the shell-function wrapper (
shell_init_cmd.py) and the PATH-shim wrapper (worktree_state.py) detected theworktreesubcommand with a literal$1comparison. An invocation that prefixes git global options — e.g.git -C <path> worktree add, which agents use heavily — therefore slipped past both interceptors and could mutate the overlay structure directly.__cwm_git_has_worktreescanner to both wrappers that skips leading global options, consuming value-taking options (-C,-c,--git-dir,--work-tree, ...) in pairs so their value is not mistaken for the subcommand. (A naive "skip all-*" would still bypass, because the path after-Cwould be read as the subcommand.)worktreeis found behind global options, the original argv is forwarded unshifted to the hook.git_hookstrips the globals via_strip_git_globalsand refuses invocations carrying repository-retargeting options (-C/--git-dir/--work-tree) — those target a different repository and cannot be safely re-homed onto the CWM-managed overlay. Benign globals (-c,--no-pager, ...) are stripped and the command proceeds normally.The bare
git worktree ...fast path is unchanged.Item 7 — Unquoted arguments on the sourced colcon path
run_colcon_sourcedjoined colcon arguments with a bare space before handing them tobash -c, so a value containing spaces or shell metacharacters (such as a--cmake-argsvalue) was word-split or interpreted by the subshell. Each argument is now quoted withshlex.quote, matching the treatment the source paths already received.Tests
-C <path> worktree addreaches the hook (no bypass);-C <path> statusstill goes to real git (value not mistaken for a subcommand)._strip_git_globalsand__git_hookretarget refusal vs. benign-global pass-through.--cmake-argsvalue becomes a single token.uv run python -m pytest.