Repository navigation
Fail Closed on Split Directory Values and Hidden Git Command Words in the Write Guard - #2994
Conversation
… the Write Guard Deny an unquoted -C, --git-dir, or --work-tree value on every git command, since word splitting can turn it into more options or a subcommand hidden behind a read such as status. A literal path and a double-quoted variable stay allowed, and the deny names quoting the variable as the fix. Where the quote-keeping lex misaligns, the value's spelling is read from the marked lex of the text, or of the text its comments or heredoc bodies leave. Read the body of a double-quoted $(...) or backtick substitution, and of an unquoted backtick substitution, as a command, the way a wrapper body is read, so a push or a commit inside one reaches every check. A heredoc body inside such a substitution stays data. Deny a run-time command word, such as a variable or a substitution, whose subcommand word past git's global options is push or commit. Closes #2977 Closes #2976 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…dings Answer the local review of the split-value and command-word change. - Skip an unquoted directory value or a run-time command word that sits only in a heredoc body no shell reads, so a commit message or a document describing the shape is not denied for it. - Read no command word in a for, select, or case word list. - Read a run-time command word right after an unquoted parenthesis, as a process substitution opens one, and read its subcommand past a redirection. - Collect substitution bodies in _skip_quote_body rather than in a second double-quote scanner. - Shorten the new docstrings to one short sentence per line. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Answer the second local review pass. - Spell an unquoted directory value from _context_lex, which drops a comment and reads a heredoc body and nested quoting as bash does, rather than from a POSIX lex that a quote in a comment or a heredoc body could misalign. A spelling inside a heredoc body counts as unknown, so a quoted decoy cannot vouch for it. This drops the spelled mode the previous round added to _marked_lex. - Read a for or select run as a word list only where it holds in, so a for loop with no word list still has its body read. - Read no command word in an array assignment. - Keep each new docstring sentence on one line. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configuration
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
A recorded local strict-review pass covers head |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #2994 +/- ##
===========================================
+ Coverage 60.53% 60.92% +0.39%
===========================================
Files 17 17
Lines 8904 8996 +92
===========================================
+ Hits 5390 5481 +91
- Misses 3514 3515 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
🟡 Changes recommended
The split-value fallback can substitute a decoy spelling and allow an unsafe unquoted directory value.
1 open finding
What changed in this PR
Hardens the Git write guard against hidden substitutions, runtime command words, and split directory values.
Changes:
- Adds parsing for command substitutions and runtime command words.
- Denies potentially splittable directory-option values.
- Expands regression and self-test coverage.
| File | Summary |
|---|---|
host-setup/agent-safety/claude/gh-write-guard.py |
Implements the guard changes and test coverage; a critical decoy-spelling bypass remains unresolved. |
🧠 Review effort: Lite
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
…ite Guard A double-quoted decoy spelled to match the shlex window could be the only spelling the _context_lex window search found, so it vouched for an unquoted value spelled differently there, such as $'.'$D. Where the quote-keeping lex misaligns but the POSIX lex read the tokens, spell the value by index from a _marked_lex that keeps each token's spelling, so no window search runs. Where the POSIX lex did not read them, the tokens hold _context_lex's own copy of each command, whose run of words then finds its real spelling. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The previous commit spelled the value by index from the POSIX lex, which disagrees with bash exactly where a nested quote, a heredoc body, an ANSI-C string, or a comment sits, so a quoted decoy could again read as the value. Keep the POSIX lex only for where the value starts, and read the _context_lex word holding that offset, which bash reads the same way. Every run of words matching the value in _context_lex is read too, and every spelling read must be split-free. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… the Write Guard Two rounds of spelling a directory value from _context_lex each let a quoted decoy elsewhere in the command vouch for an unquoted value, since that lex and the token list disagree in places. Drop that reading and the spans it added to _context_lex. Where the quote-keeping tokens are unknown, spell the value from _marked_lex, which raises on any syntax whose quoting it does not model, and trust it only where its tokens are the token list exactly. Everywhere else the value fails closed. A quoted value beside a double-quoted substitution, a heredoc, a comment holding a quote, or an ANSI-C word is now denied where the quote-keeping lex also misaligns, and the deny names running that git command on its own as the fix for an already quoted value. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The split-value deny now also refuses a quoted value the guard cannot read beside the rest of the command, so it no longer calls that value unquoted, and its fix names writing the directory out, which clears a value beside a heredoc where running the command alone would not. The _dir_value_split_free docstring states what _split_free actually decides. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The directory value deny chained three relative clauses onto the shared rewritten-word template and claimed word splitting for a value that is double-quoted. Its form now says only that the guard cannot read the value as quoted, and its fix carries the rest of the deny in sentences of its own, stating the split for an unquoted value alone. The _rewritten_git_words and _dir_value_split_free docstrings say what the pair and _split_free now do. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
A recorded local strict-review pass covers head |
Answer the four wording findings the last local pass left open on the pull request. The fix names quoting the value rather than a variable, since the value may be a substitution, and keeps one tense. The _rewritten_git_words docstring now says a quoted value the guard cannot read is denied too, and that the fix stands in for the reason and the advice rather than for everything after the form. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
A recorded local strict-review pass covers head |
…tution Readings (#3001) Brings the two READMEs that describe the write guard in line with the readings the guard gained in #2994. - A `-C`, `--git-dir`, or `--work-tree` value that word splitting may split is denied on every git subcommand, with the quoting fix named for an unquoted variable. - A command word holding a `$` or a backtick is denied where the subcommand is `push` or `commit`. - The body of a command substitution is read as a command. Two review rounds narrowed the wording to what the guard delivers. The gaps they found in the guard itself are filed as #2998, #2999, and #3000. Closes #2990 Verification: prose_lint with `--diff`, `repo_gate.py`, `spec/validate.py`, `build_dist.py --check`, and the docker linters pass. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Sonnet 5.5 <[email protected]>
…and Write-Guard Split Directory and Substitution Denies to Main (#3002) - #2986 makes `pr_review.py` count a Copilot finding named only in the overview file table, or only in a headline total larger than the open sections list, under `FINDINGS WITH NO THREAD`, so the gate reads a finding the round opened no thread or open-findings entry for - #2988 makes `pr_review.py cleanup` refuse a branch delete where another open pull request in the repository uses the branch as its head or base, naming them, and drops the hand-typed `git push origin --delete` fallback from `drive-pr` step 4 and `merge-and-release` step 8, so a seat that cannot run `cleanup` reports the delete to the maintainer. The failed-rules-read test now asserts the stub's stderr text and exit code - #2992 names `pr_review.py cleanup` as the branch delete in `backlog-burndown` and in `scripts/README.md`, with any nonzero exit, or a seat that cannot run it, reported to the maintainer - #2994 makes `gh-write-guard` deny an unquoted `-C`, `--git-dir`, or `--work-tree` value that word splitting may split, on every git subcommand, naming quoting the variable as the fix, deny a command word holding a `$` or a backtick where its subcommand is `push` or `commit`, and read the body of a double-quoted `$(...)` or backtick substitution, and of an unquoted backtick substitution, as a command, so a git push or commit hidden there reaches every check. A heredoc body inside such a substitution stays data - #3001 describes those readings in the two agent-safety READMEs After this merges, the host-safety installer payload changes, so the maintainer runs the installer after promotion. Closes #2982 Closes #2969 Closes #2971 Closes #2983 Closes #2987 Closes #2976 Closes #2977 Closes #2990 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Branch cleanup now checks that the branch still matches the pull request and is not used by another open pull request before deletion. If checks fail or cleanup cannot run, maintainers are asked to handle it; remotely pushed abandoned branches are not deleted automatically. * Review summaries now account for findings in file-table annotations and headlines, reducing the chance that unthreaded findings go uncounted. * **Safety** * Command safeguards now inspect command substitutions and reject ambiguous directory values and command forms that could conceal Git operations. <!-- end of auto-generated comment: release notes by coderabbit.ai -->

Summary
This fails closed on two more ways the write guard in
host-setup/agent-safety/claude/gh-write-guard.pycould miss a git command. Each change adds a reading or a deny beside develop's and replaces none of develop's readings.-C,--git-dir, or--work-treevalue is exempt only where word splitting cannot split it. A literal path and a double-quoted"$W"stay allowed. An unquoted$W,${W}, or partly quoted"a"$Wis denied on every git subcommand, since a split value can carry the subcommand itself, as inD='. commit -n -m'; git -C $D status. The deny names quoting the variable as the fix. Where the quote-keeping lex cannot align its tokens, as with--format='%H %s'beside the value, the value is spelled from_marked_lexwhere that lex reads the whole command, so a quoted value there is not over-denied.$(...)or backtick substitution, and of an unquoted backtick substitution, is read as a command the way abash -cbody is read. Soecho "$(git push origin develop)",x=`git push origin develop`, andecho `git commit -n -m x`reach every check._skip_quote_bodycollects those bodies. A heredoc body inside such a substitution stays data, so thegit commit -m "$(cat <<'EOF' ... EOF)"idiom is unchanged even where its text names a push. Substitutions nested past the wrapper reading cap fail closed as wrappers already do.$or a backtick, such as$G,"$GIT",`which git`, or$(which git), is denied where its subcommand word past git's global options and any redirection ispushorcommit. The deny carries the explicit-refspec, own-command workaround. A word that an earliergitorghword takes as an argument is not a command word, sogit -C "$W" push origin feature/xstays allowed. Neither is a word in afor/select ... inorcaselist or an array assignment.Differential Against Develop
A probe classified a constructed corpus with develop's guard and this branch's, each with the primary-checkout seam both off and on. The corpus held the issue shapes, their near-allowed neighbours, and every command in the guard's own case tables, about 990 commands. It found no deny-to-allow flip. Every allow-to-deny flip is one of the shapes above. The one existing table row it moved,
git -C /opt/$HOMEPATH/primary reset --hard origin/main, now quotes its value, so it still tests the unexpanded-$HOMEPATHprimary-checkout reading rather than the new split-value deny.Over-Denials Accepted
-C $HOME/...or-C $(pwd)is denied. Quoting it is the fix the deny names.pushorcommitis denied whatever it expands to, such as$HOME/bin/tool commit.git -C "$W" log --format='%H %s' -1 && echo "$(date)". The deny names writing the directory out as the fix.Local Review
Local strict-review passes ran before the first push and before each fix push, and every finding was fixed here or filed. A Copilot finding on the first head, that a differently spelled quoted decoy could vouch for an unquoted value through a
_context_lexwindow search, is fixed by dropping that search. Where the quote-keeping lex cannot align its tokens, the value is now spelled from_marked_lex, which raises on syntax whose quoting it does not model. That spelling is trusted only where its tokens are the guard's tokens exactly, and everywhere else the value fails closed.Local Findings Answered After the Fix Push
The four
introducedwording findings the last pass before the fix push left open were fixed in 7cdc187: the fix names quoting the value rather than a variable, the form and the fix share one tense, and the_rewritten_git_wordsdocstring states that a quoted value the guard cannot read is denied and what the fix stands in for. A further pass over 7cdc187 raised one optional precision nit on that docstring's bullet, declined as a preference, since the bullet's owngit -C $Dexample and the deny's form both name the directory option.Follow-Ups Filed
${...}or$((...)), or in an unquoted-delimiter heredoc body, are still not read. Develop does not read them either.eval, or a glob can still split a directory value the guard reads as one word. Develop exempts every directory value, so it has these too.Verification
gh-write-guard.py --selftestpasses, with new_GIT_CASESrows for each shape and its allowed control.test_install.py,python3 -m unittest discover -s tests, ruff check and format, mypy,build_dist.py --check,repo_gate.py(eol and eol-coverage included),spec/validate.py, andprose_lint.pyon the diff all pass locally.Closes #2977
Closes #2976
🤖 Generated with Claude Code