Skip to content

Promote the Guard's Shell-Token Fallback Fix to Main - #1912

Merged
ptr727 merged 1 commit into
mainfrom
develop
Sep 27, 2026
Merged

ptr727 merged 1 commit into
mainfrom
develop

Conversation

@ptr727

@ptr727 ptr727 commented Sep 27, 2026 •

Copy link
Copy Markdown
Owner

Summary

Promotes develop to main. It carries one change:

When gh-write-guard.py's primary tokenizer cannot parse a command's quoting, most often because of an apostrophe in a trailing comment, the fallback now strips comments over the whole command, carrying quote state across lines, before parsing it again. Where the strip is used, develop's plain per-line tokens are appended after its result, so the strip can reveal a loop or write the old fallback missed but never hide one it saw. A line that parses on its own also gets its operators isolated. A differential fuzz found no command that develop denies and this change allows.

Fixes #1635

Follow-ups filed from its reviews

  • Read a Multi-Line Quote Whole in the Guard's Token Fallback #1910: a fallback tokenizer that tracks bash's nested contexts. Its comments carry the residual shapes the reviews raised: a false deny on a multi-line quote read line by line, a =~ regex # that still hides a loop, and a backslash inside a comment that turns the strip off. None is a regression against develop.

Review coverage

CodeRabbit rate-limited its review of this pull request, so this promotion rests on its review of #1911, which read 0341099a. The content is identical, and any reader can re-run both checks:

  • git rev-parse 0341099a^{tree} and git rev-parse 9bd3f231^{tree} both print 23b0f7d9b8ac6c5a347deef924e65ce662e945de.
  • git diff 9bd3f231^ 9bd3f231 | sha256sum and git diff origin/main origin/develop | sha256sum match.

Copilot reviewed this head in full. Its one finding, another shape the skip list leaves uncovered and not a regression, is deferred to #1910.

Needs the maintainer

  • Machines pick up the guard change only when the agent-safety installer is re-run after release.

🤖 Generated with Claude Code

…ack (#1911)

## Summary

When the guard's primary tokenizer cannot parse a command's quoting,
most often because an apostrophe sits in a trailing comment, the
fallback split each line plainly and saw no operators. A loop like
`while ! <check>; do sleep 30; done # the PR's checks` then went unseen
(#1635).

- The per-line fallback now isolates operators on any line that parses
on its own. A line that does not parse falls back to plain splitting, as
before.
- `_strip_comments` strips every comment over the whole command, and
carries plain-quote state across lines as bash does. The stripped text
is parsed before the per-line fallback runs.
- The strip is skipped wherever bash nests a context the scan does not
model: a heredoc, `((`, an extglob opener, backslashes, backticks, and
`$(`, `${`, `$'` and `$"`.
- When the strip is used, develop's plain per-line tokens are appended
after its tokens. The strip can then reveal a command the base fallback
missed, but can never hide one it saw.
- `_heredoc_opener` keeps the base tokenizer, with no comment stripping.

The line flagged `comment-added` by the prose gate is the existing
`shlex` commenters comment, moved unchanged into the shared
`_operator_lex` helper.

## Verification

- The self-test passes. It includes new cases for a quote spanning
lines, arithmetic and extglob `#`, and a `=~` regex `#`, each proven to
fail without its fix.
- A differential fuzz against develop ran 30,000 generated commands per
run. None went from deny to allow on the final head.
- Across all runs, bash with stubbed `gh` and `git` confirmed that every
earlier deny-to-allow flip was a write inside a real comment. Bash never
runs any of them.
- No deny appears that develop would not make and the previous head
allowed. The remaining allow-to-deny cases are the #1635 fix: unbounded
loops that develop missed.
- Three recorded local strict-review passes. The last found only a false
deny in the per-line fallback, filed as #1910.

Closes on promotion: #1635

🤖 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**
* Improved shell command handling when quotes are malformed or comments
appear, so operators and subsequent commands are interpreted more
reliably.
* Improved recognition of heredoc openers and wait loops with trailing
comments, while preserving the behavior of quoted operators.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
Copilot AI lite review requested due to automatic review settings September 27, 2026 02:41
@coderabbitai

coderabbitai Bot commented Sep 27, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 52 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Repository: ptr727/ProjectTemplate/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 802364bc-7872-4c1d-b412-d55fe98313e5

📥 Commits

Reviewing files that changed from the base of the PR and between b8425b2 and 9bd3f23.

📒 Files selected for processing (1)
  • host-setup/agent-safety/claude/gh-write-guard.py

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 Sep 27, 2026

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
⚠️ Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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.

Copilot review overview

🟡 Changes recommended

The new comment-stripping fallback is currently skipped for many common commands (e.g., those containing $(, ${...}, or \\), which still allows unbounded wait loops to bypass Rule 7 when an apostrophe appears in a trailing # comment.

Review effort: Lite
Findings: 1 High severity

Open (1)
What changed in this PR

This promotion PR brings the updated gh-write-guard.py shell-token fallback from develop to main, aiming to prevent unbounded-wait-loop bypasses when shlex fails on apostrophes in trailing # comments by stripping comments and isolating operators during fallback tokenization.

Changes:

  • Add a whole-command comment-stripping fallback (_strip_comments) and operator-isolating tokenization helpers to improve detection when primary tokenization fails.
  • Adjust heredoc opener parsing to explicitly disable comment stripping for that path.
  • Expand the self-test corpus with cases covering comment stripping, quote carryover across lines, and the original apostrophe-in-comment bypass shape.
File Description
host-setup/​agent-safety/​claude/​gh-write-guard.py Improves fallback shell tokenization by stripping comments and isolating operators, plus additional self-tests.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

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.

An Apostrophe in a # Comment Defeats Requirement 7 Entirely

2 participants