Skip to content

Fail Closed on Split Directory Values and Hidden Git Command Words in the Write Guard - #2994

Merged
ptr727 merged 9 commits into
developfrom
feature/guard-split-words
Oct 14, 2026
Merged

ptr727 merged 9 commits into
developfrom
feature/guard-split-words

Conversation

@ptr727

@ptr727 ptr727 commented Oct 14, 2026 •

Copy link
Copy Markdown
Owner

Summary

This fails closed on two more ways the write guard in host-setup/agent-safety/claude/gh-write-guard.py could miss a git command. Each change adds a reading or a deny beside develop's and replaces none of develop's readings.

  • An unquoted directory option value (Decide Whether an Unquoted Directory Option Value Fails Closed in the Write Guard #2977). Per the maintainer's decision on Decide Whether an Unquoted Directory Option Value Fails Closed in the Write Guard #2977, a -C, --git-dir, or --work-tree value 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"$W is denied on every git subcommand, since a split value can carry the subcommand itself, as in D='. 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_lex where that lex reads the whole command, so a quoted value there is not over-denied.
  • Git words the tokenizer kept inside one word (Read a Backtick-Opened or Run-Time Git Command Word in the Write Guard #2976). The body of a double-quoted $(...) or backtick substitution, and of an unquoted backtick substitution, is read as a command the way a bash -c body is read. So echo "$(git push origin develop)", x=`git push origin develop` , and echo `git commit -n -m x` reach every check. _skip_quote_body collects those bodies. A heredoc body inside such a substitution stays data, so the git 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.
  • A run-time command word (Read a Backtick-Opened or Run-Time Git Command Word in the Write Guard #2976). A command word holding a $ 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 is push or commit. The deny carries the explicit-refspec, own-command workaround. A word that an earlier git or gh word takes as an argument is not a command word, so git -C "$W" push origin feature/x stays allowed. Neither is a word in a for/select ... in or case list or an array assignment.
  • Both new denies leave a shape that sits only in a heredoc body no shell reads, so a commit message or a document describing it is not denied for it.

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-$HOMEPATH primary-checkout reading rather than the new split-value deny.

Over-Denials Accepted

  • An unquoted -C $HOME/... or -C $(pwd) is denied. Quoting it is the fix the deny names.
  • A run-time command word before push or commit is denied whatever it expands to, such as $HOME/bin/tool commit.
  • A double-quoted value is denied where the quote-keeping lex misaligns and the command also holds a heredoc, a comment holding a quote, a double-quoted substitution, or an ANSI-C word, as in 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_lex window 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 introduced wording 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_words docstring 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 own git -C $D example and the deny's form both name the directory option.

Follow-Ups Filed

Verification

  • gh-write-guard.py --selftest passes, with new _GIT_CASES rows 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, and prose_lint.py on the diff all pass locally.

Closes #2977
Closes #2976

🤖 Generated with Claude Code

ptr727 and others added 3 commits October 14, 2026 07:25
… 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]>
Copilot AI lite review requested due to automatic review settings October 14, 2026 15:03
@coderabbitai

coderabbitai Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration
  • Configuration used: Repository: ptr727/ProjectTemplate/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 6bfe2d0c-14b2-4478-9e7e-ea385dcb0c9b
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@ptr727

ptr727 commented Oct 14, 2026

Copy link
Copy Markdown
Owner Author

A recorded local strict-review pass covers head 3e3dffe95d1037fb70a2d7f59bf0e54238b061ee, the content this pull request carries at that commit against develop, and it recorded 2 findings.

@codecov

codecov Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 60.92%. Comparing base (4a0370f) to head (7cdc187).
⚠️ Report is 3 commits behind head on develop.

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     
Flag Coverage Δ
python-3.13 60.92% <ø> (+0.39%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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.

ptr727 and others added 5 commits October 14, 2026 08:10
…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]>
@ptr727

ptr727 commented Oct 14, 2026

Copy link
Copy Markdown
Owner Author

A recorded local strict-review pass covers head dab0e9587e1a7144e7c3565a9ab7829c1f901373, the content this pull request carries at that commit against develop, and it recorded 4 findings.

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]>
@ptr727

ptr727 commented Oct 14, 2026

Copy link
Copy Markdown
Owner Author

A recorded local strict-review pass covers head 7cdc1874e3acaaf7ac3af03e8785fe698a034aab, the content this pull request carries at that commit against develop, and it recorded 1 finding.

@ptr727
ptr727 merged commit dbd80de into develop Oct 14, 2026
13 checks passed
@ptr727
ptr727 deleted the feature/guard-split-words branch October 14, 2026 15:57
ptr727 added a commit that referenced this pull request Oct 14, 2026
…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]>
ptr727 added a commit that referenced this pull request Oct 14, 2026
…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 -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants