Repository navigation
Check Placeholders Inside a String Handed to a Second Shell in Paste-Safe - #4382
Conversation
…Safe The paste-safe rule now reads the string argument of su -c, runuser -c, sh -c, bash -c (and the other POSIX shells), and ssh again as the command the second shell runs. A bare placeholder there is a finding, since that shell reads it as a redirection, a glob, or a pipe. The option tables live in prose-gate.json, and the inner scan recurses for a nested second shell. The agent-safety README's two timeout examples are rewritten as concrete constructed loops, since the rule now flags their bare loop placeholder. Co-Authored-By: Claude Opus 5.5 <[email protected]>
GOVERNANCE.md "Copy-and-Run Commands" said the rule reads such a string as a plain quotation, which the rule no longer does. The generated comment-and-doc-style include is refreshed from it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The local review found three wrong behaviors in the first cut, each now covered by a constructed test: - An escaped quote such as '\'' was dropped from the handed string, so a correctly quoted placeholder was reported. Quote removal now goes through the standard library's shlex rather than a hand-written pass. - A shell's name anywhere in a command was read as a launched shell, so rsync -e ssh and apt install ssh reported their arguments. The shell is now the command a simple command runs, read past its assignments, reserved words, and launchers with their own options and operands. - su and runuser read past a --, missed runuser -u, and missed --session-command. A -- with no command string now hands the rest on as a command, so runuser -u app -- sh -c names sh. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The second local review found three more misses, each now a test case:
- Whitespace inside a ${...} expansion split the handed word, so its
quoting never closed and the string went unread. The expansion is now
one literal run.
- A second shell inside $(...) or backticks was never read. Each
outermost substitution's commands are now read on their own.
- sudo's -r, -t, -a and -c, and doas's -a, were missing from the launcher
tables, so their values were read as the command.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 40 minutes. View limit details
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. |
|
A recorded local strict-review pass covers head |
- A shell opening a backtick substitution failed the name prefilter, so it went unread. The prefilter now allows a backtick before the name. - Every shape inside a second shell's string got the "quote it" advice. Each shape now keeps its own advice, with only the place it sits named differently. - For su, and for runuser without -u, a -- does not open a command, since the user and the shell's arguments follow it. - A leading $ prompt hid the second shell behind it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
🟡 Changes recommended
Several moderate active findings remain in shell-command parsing, causing nested-shell placeholders and shape-specific guidance to be missed or misclassified.
5 open issues
What changed in this PR
This PR extends the paste-safe prose-gate rule to inspect commands passed as strings to known second-shell commands, including nested shell invocations.
Changes:
- Adds shell-command parsing for shells, launchers, assignments, reserved words, redirections, and nested substitutions.
- Adds tests covering detected, quoted, nested, multiline, and launcher-based command forms.
- Updates governance documentation, agent-safety examples, generated skill distributions, and the source digest.
| File | Description |
|---|---|
| tests/test_prose_lint.py | Adds regression coverage for placeholders inside second-shell command strings and related quoting and boundary behavior. |
| host-setup/agent-safety/README.md | Replaces flagged placeholder loop examples with concrete bounded commands. |
| GOVERNANCE.md | Documents that strings handed to second shells are analyzed as commands run by those shells. |
| .github/skills/comment-and-doc-style/SKILL.md | Refreshes the generated comment-and-documentation skill guidance. |
| .github/actions/prose-gate/prose-gate.json | Defines second-shell commands, launchers, parser options, and diagnostic messages. |
| .github/actions/prose-gate/prose_lint.py | Implements shell word splitting, option handling, nested command extraction, and placeholder scanning. |
| .claude-plugin/fleet-skills/skills/comment-and-doc-style/SKILL.md | Refreshes the Claude fleet skill distribution with the updated guidance. |
| .claude-plugin/fleet-skills/.source-digests/comment-and-doc-style | Updates the generated skill source digest. |
| .agents/skills/comment-and-doc-style/SKILL.md | Refreshes the canonical generated guidance include. |
Review effort: Lite
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #4382 +/- ##
===========================================
- Coverage 81.60% 79.35% -2.26%
===========================================
Files 26 45 +19
Lines 9070 16046 +6976
===========================================
+ Hits 7402 12734 +5332
- Misses 1668 3312 +1644
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:
|
- A placeholder or bracket inside a second shell's string was told to be quoted the way the first shell quotes it, which does not clear the finding. Its advice now says to quote it inside that string. - A heredoc token hid the rest of its opening line, so a second shell piped to from there went unread. That rest is now read as code, and the heredoc's body ends the command. - timeout, env, and xargs each get a positive launcher case. Co-Authored-By: Claude Opus 5.5 <[email protected]>
- ssh joins every word after its destination with spaces, and the remote shell parses the result as one command. Those words are now read as that one command, so ssh host sudo sh -c "'ls <dir>'" is reported. A placeholder the first shell already reported in an unquoted word is not reported again. - bash and the other POSIX shells give -o and -O the next word wherever the letter sits in a cluster, and keep reading it. So bash -oc pipefail now reads -c. - Docstring lines over the line length are rewrapped. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
A recorded local strict-review pass covers head |
…thing - A code span's line breaks render as spaces, so a second shell wrapped across them is now read as one command. A fence keeps its line breaks. - A placeholder the first shell reported is blanked from any word ssh joins, a word mixing quoted and unquoted text included, so it is reported once. - Every second-shell and launcher name now opens a command span, and a test holds the tables to that. - Inside a handed string, a bracket, an optional flag, or an alternation may be a pattern, so its advice now says to quote it there first. - command -v, sudo -l, and sudo -e run nothing, so the command after them is not read. Co-Authored-By: Claude Opus 5.5 <[email protected]>
- A line break between the words ssh joins now becomes a line continuation, so the remote command stays one line while each placeholder keeps its line. A wrapped or continued ssh command is read as the one-line form is. - A no-run option is matched only among a cluster's own letters, up to the first that takes a value, so sudo -upostgres no longer reads as sudo -e. - An alternation inside a handed string keeps the "space a real pipe" remedy. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
A recorded local strict-review pass covers head |
…Cluster Helpers - The ssh join now reads each word from the line-break-flattened text, so a code span's break inside a quoted word renders as the space it is. - A command substitution in an ssh argument is blanked before the join, since the first shell runs it, so a placeholder quoted for that local command is not reported. - xargs --replace and --max-lines take a value only after =, so they no longer take the next word. - handed_strings reads a value or rest shell's option cluster through cluster and takes_value rather than a second copy of that walk. Co-Authored-By: Claude Opus 5.5 <[email protected]>
- The new shell and launcher names no longer open a command span by themselves. A device console's `time <seconds>` is prose, and the widened list reported it in a fleet repository. A launcher is still read past inside a command, and a fence reads them all. - takes_value reads a short cluster through cluster, so one walk decides which letter takes a value. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
A recorded local strict-review pass covers head |
|
@coderabbitai review |
|
/review |
Action not completed
|
…, Shared Run Deadline, and Second-Shell Paste-Safe (#4388) Promotes the ten pull requests that landed on develop since the last promotion: backlog burndown round 5, plus #4374 and #4376. - #4374: Quote the last paste-safe placeholders and run the check in the local block (the #1615 remainder). - #4376: Declare host-secrets for HomeAutomation-Config in the registry. - #4378: GOVERNANCE.md "Verification Discipline" requires the whole test suite before every push. The Husky hook bullet says it passes the staged paths to the prose gate. The `pr-review-conduct` Merge Gate names the rate-limit `success` check trap, the only part of #1298 kept per the maintainer's 2026-11-23 answer. - #4379: `validate-task.yml` fails a promotion when main's first-parent chain since the previous promotion holds a single-parent commit, an accidental squash into main. The conflicted-promotion cut and the squash recovery are documented in `branching-and-release-model`, and `drive-pr` points at them. - #4380: `canonical_review.py record` binds each unit's pass to the reviewer's written report rather than a typed `--findings` count. - #4381: Every argument refusal in the `host-setup/linux` scripts exits 64 through `die_usage`, and an EXIT trap maps a stray 64 to 1. The contract is stated in CODESTYLE.md "Command-Line Arguments". - #4382: The prose gate's `paste-safe` rule reads the string handed to `su`/`runuser -c`, a POSIX shell's `-c`, and `ssh`. This edits `host-setup/agent-safety/README.md` (two example loops only), which the maintainer approved and merged on 2026-11-24. - #4384: `upstream-contribution-workflow` says what a refused lease push on the dirty branch means. `audit-a-repo` carries the convention-layout note on its `--checkout` path. - #4385: Every timed captured run in the review and install tooling goes through one shared `scripts/run_deadline.py`, so a captured timeout holds its deadline on Windows. - #4386: The canonical `.editorconfig` sets every IDE code-style rule to `warning`, per the maintainer's strictest-defaults answer, and the `dotnet-codestyle` skill now agrees with the rules it enforces. ## Owed by the maintainer before rollout - A fleet resync is owed, because carried text changed: GOVERNANCE.md, CODESTYLE.md, `.editorconfig`, the reusable `validate-task.yml`, and several skills. - Every carrying C# repository has to fix its code at its next `.editorconfig` resync (#4386). The rules likely to fire most are IDE0058, IDE0046, IDE0210, IDE0290 and IDE0047/IDE0048. - HomeAutomation-Config#1466 can adopt the exit-64 contract once this is released. - #4379 keeps the `048a442f` floor your decision named, but the walk always stops at a later promotion merge, so the floor is never reached. Whether to drop it is your call. Fixes #1615 Fixes #2280 Fixes #3820 Fixes #1298 Fixes #2510 Fixes #4373 Fixes #3804 Fixes #3605 Fixes #4375 Fixes #4345 Fixes #3854 Fixes #1842 🤖 Generated with [Claude Code](https://claude.com/claude-code)

Summary
The
paste-safeprose-gate rule now reads a string that a command hands to a second shell, and checks it as the command that shell runs. A bare placeholder inside it is a finding. The outer shell takessu -l root -c 'usermod -aG sudo <account>'literally, butsugives the string to a shell that reads<account>as a redirection.prose_lint.py: the rule splits each command into words at the boundaries Pygments' bash lexer gives, the lexer the rule already uses. It then removes each word's quoting with the standard library'sshlex. The second shell is the command a simple command runs. That is found past its assignments, its reserved words, and launchers such assudoandtimeout, with each launcher's own options and operands. So a shell's name as another command's argument, as inrsync -e ssh, runs no shell. The rule reads that shell's options to pick out the string it runs. It removes the quoting, blanks the first shell's own code, and scans the string again with the same shapes and exemptions. A nested second shell is read too, as inssh host 'sudo sh -c "id <account>"'.sh,bash,dash,zsh,ksh,ash,mksh: the first operand once-cis set.su,runuser: the value of-c,--command, or--session-command. After a--with none of those, the command that follows is read as a command, as inrunuser -u app -- sh -c '...'.ssh: every operand after the destination.prose-gate.json: the option tables for those commands and the launchers, the reserved words, apaste-safe-second-shellmessage, and a widened rule summary.tests/test_prose_lint.py: constructed cases.'\''form.GOVERNANCE.md"Copy-and-Run Commands": the sentence saying the rule reads such a string as a plain quotation now says it reads the string as the command the second shell runs. The generatedcomment-and-doc-styleinclude is refreshed byscripts/build_dist.py.host-setup/agent-safety/README.md: the new rule flagged the twotimeout ... bash -c '<the loop>'spans in requirement 7. They now carry a concrete constructed loop. The maintainer approved this edit, and the gate gains no exemption.The whole-tree local prose invocation flagged only those two README spans before the rewrite, and it is clean now.
Introduced findings from the opening push, answered
The opening push spent its two-round edit budget and listed four
introducedfindings from its third pass. The second push fixes each one, with a test:su, and forrunuserwithout-u, a--no longer opens a command.$prompt is read past.The second push's own pass found four more. Three are fixed here, each with a test:
timeout,env, andxargseach get a positive launcher case.The fourth is the consolidation finding below, which is declined.
A further pass found three more, all fixed here:
sshjoins every word after its destination into one command, and that command is now read whole. Sossh host sudo sh -c "'ls <dir>'"is reported. A placeholder the first shell already reported in an unquoted word is not reported a second time.-otakes the next word wherever it sits in an option cluster, sobash -oc pipefail '...'now reads its-c.Introduced findings from the second push, answered
The third push fixes the four the second push listed, each with a test:
sshjoins, so it is reported once.Its own passes found four more. Each is fixed here with a test:
command -v,sudo -l, andsudo -erun nothing, so the command after them is not read.sshjoins stays one line: a source line break between its words becomes a line continuation.sudo -upostgresis not read assudo -e.Introduced findings from the third push, answered
The fourth push fixes the four the third push listed, each with a constructed test:
sshjoin reads each word from the flattened text, so a span's line break inside a quoted word is the space it renders as.sshargument is blanked before the join, since the first shell runs it.xargs --replaceand--max-linestake a value only after=.handed_stringsreads a value or rest shell's option cluster throughclusterandtakes_value.Its pass found no regression and no crash. Its round fixed two more:
commands.namesis unchanged from develop. The widened list read a device console'stime <...>in a fleet repository as a command. A launcher is still read past inside a command, and a fence reads them all.takes_valuereads a short cluster throughcluster, so one walk decides which letter takes a value.Edge cases declined
From here, an edge case in the shell reading is declined under the trust-boundary and hardening-effort rule. The input is the fleet's own authored Markdown. Develop's rule and this branch's report the same findings over the fleet's checkouts, and a false positive costs its author one quoting fix. A regression or a crash would still be fixed, and none was found. Each declined case:
sshword shifts a later placeholder's reported line up by one.find -exec sh -c '...'andwsl bash -c '...'do not read the shell they launch, nor dodocker execandbusybox sh.commands.names, such asdashornice, is not read as a command. A fence is.sshline is reported once.ssh <host> 'ls <dir>'ortimeout <seconds> bash -c '...', is read as a redirection. So the operand count shifts and the handed string goes unread until that first placeholder is quoted. The first placeholder is reported either way.sudo -s,sudo -h,env -, a leading redirection, a heredoc onssh's stdin, a backtick substitution in double quotes, and${x:-<default>}are not read.The final pass compared develop's rule and this branch's over every tracked Markdown file in 33 fleet checkouts, and found no difference. It also ran 12,000 random token mixes through both. It found no regression and no crash.
Pre-existing findings, filed
prose_lint.pyshell_literals: it does not blank the quotations on a heredoc's opening line after its label, so a quoted placeholder there is reported. Class:pre-existingcorrectness defect. Filed as Blank Quotations After a Heredoc Label on Its Opening Line in Paste-Safe #4383.Design findings declined
launcher_spanandhanded_strings: the two read different things. A launcher counts its own operands before a command, and a second shell picks out a string by mode. Merging them is a refactor past the bounded push this change was given. The walkers differ on one shape, a redirection right aftersu -c, which no fleet document uses.no_runoption to the launchers fleet documents use today, which areexec,sudo,timeout, andxargs: each entry is one line of data.no_runanswers a hosted review finding thatcommand -vruns nothing. Removing entries would turn their commands into misses the day a document uses one.gh-write-guard.py's tokenizer: that file is a standard-library-only hook the host kit installs on each machine. The gate is a composite action run from a hub fetch, so neither can import the other at run time.shell_literalsfrom the new character classes: the two classify a command substitution differently. One blanks a quotation inside$(...), and the other keeps the substitution whole. They also treat a heredoc's opening line differently.handed_wordsandopens_commandwith one helper:opens_commanddecides from a span's raw text whether to read the span at all. It runs on every inline code span in the tree, and the lexer runs only on the spans it accepts. Moving it onto lexed words would lex every span.bashlexpackage: that adds a third-party dependency to a composite action every fleet repository runs, which is a design change beyond this issue. Each defect raised against the splitter was fixed inside the pinned lexer's token stream, with a test.Closes on promotion: #4375
This pull request edits
host-setup/agent-safety/, so the maintainer merges it.🤖 Generated with Claude Code