Skip to content

Check Placeholders Inside a String Handed to a Second Shell in Paste-Safe - #4382

Merged
ptr727 merged 12 commits into
developfrom
burndown/paste-safe-second-shell
Nov 24, 2026
Merged

ptr727 merged 12 commits into
developfrom
burndown/paste-safe-second-shell

Conversation

@ptr727

@ptr727 ptr727 commented Nov 24, 2026 •

Copy link
Copy Markdown
Owner

Summary

The paste-safe prose-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 takes su -l root -c 'usermod -aG sudo <account>' literally, but su gives 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's shlex. The second shell is the command a simple command runs. That is found past its assignments, its reserved words, and launchers such as sudo and timeout, with each launcher's own options and operands. So a shell's name as another command's argument, as in rsync -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 in ssh host 'sudo sh -c "id <account>"'.
    • sh, bash, dash, zsh, ksh, ash, mksh: the first operand once -c is 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 in runuser -u app -- sh -c '...'.
    • ssh: every operand after the destination.
    • An option that takes a value, and a redirection, are skipped.
  • prose-gate.json: the option tables for those commands and the launchers, the reserved words, a paste-safe-second-shell message, and a widened rule summary.
  • tests/test_prose_lint.py: constructed cases.
    • Each command form reports its placeholder.
    • A placeholder quoted inside the string passes, including the '\'' form.
    • A shell's name as an argument passes.
    • A newline ends the handed command, a continued line reports the right line, and a reserved word is read past.
  • 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 generated comment-and-doc-style include is refreshed by scripts/build_dist.py.
  • host-setup/agent-safety/README.md: the new rule flagged the two timeout ... 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 introduced findings from its third pass. The second push fixes each one, with a test:

  • A shell right after an opening backtick now passes the name prefilter.
  • Each shape inside a second shell's string keeps its own advice.
  • For su, and for runuser without -u, a -- no longer opens a command.
  • A leading $ prompt is read past.

The second push's own pass found four more. Three are fixed here, each with a test:

  • The advice for a placeholder or bracket inside a second shell's string now says to quote it inside that string. The first shell's "quote it" advice did not clear such a finding.
  • The rest of a heredoc's opening line is now read as code, so a second shell piped to from there is read.
  • timeout, env, and xargs each get a positive launcher case.

The fourth is the consolidation finding below, which is declined.

A further pass found three more, all fixed here:

  • ssh joins every word after its destination into one command, and that command is now read whole. So ssh 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.
  • A POSIX shell's -o takes the next word wherever it sits in an option cluster, so bash -oc pipefail '...' now reads its -c.
  • Docstring lines over the line length are rewrapped.

Introduced findings from the second push, answered

The third push fixes the four the second push listed, each with a test:

  • A code span's line breaks now read as spaces, so a second shell wrapped across them is read.
  • A placeholder the first shell reported is blanked from any word ssh joins, 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.

Its own passes found four more. Each is fixed here with a test:

  • command -v, sudo -l, and sudo -e run nothing, so the command after them is not read.
  • The command ssh joins stays one line: a source line break between its words becomes a line continuation.
  • A no-run option is matched only among a cluster's own letters, so sudo -upostgres is not read as sudo -e.
  • An alternation inside a handed string keeps the "space a real pipe" remedy.

Introduced findings from the third push, answered

The fourth push fixes the four the third push listed, each with a constructed test:

  • The ssh join reads each word from the flattened text, so a span's line break inside a quoted word is the space it renders as.
  • A command substitution in an ssh argument is blanked before the join, since the first shell runs it.
  • xargs --replace and --max-lines take a value only after =.
  • handed_strings reads a value or rest shell's option cluster through cluster and takes_value.

Its pass found no regression and no crash. Its round fixed two more:

  • The new shell and launcher names no longer open a command span alone, so commands.names is unchanged from develop. The widened list read a device console's time <...> in a fleet repository as a command. 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.

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:

  • In a wrapped span, a quoted line break in an earlier ssh word shifts a later placeholder's reported line up by one.
  • find -exec sh -c '...' and wsl bash -c '...' do not read the shell they launch, nor do docker exec and busybox sh.
  • A span opening with a shell or launcher name outside commands.names, such as dash or nice, is not read as a command. A fence is.
  • One placeholder that appears both unquoted and quoted on one ssh line is reported once.
  • An unquoted angle placeholder in an operand position, as in ssh <host> 'ls <dir>' or timeout <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 on ssh'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

Design findings declined

  • One option walker shared by launcher_span and handed_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 after su -c, which no fleet document uses.
  • Trimming the launcher table and the no_run option to the launchers fleet documents use today, which are exec, sudo, timeout, and xargs: each entry is one line of data. no_run answers a hosted review finding that command -v runs nothing. Removing entries would turn their commands into misses the day a document uses one.
  • Reusing 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.
  • Deriving shell_literals from 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.
  • Walking handed_words and opens_command with one helper: opens_command decides 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.
  • Replacing the word splitter with the bashlex package: 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

ptr727 and others added 5 commits November 23, 2026 15:51
…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]>
Copilot AI lite review requested due to automatic review settings November 24, 2026 00:57
@coderabbitai

coderabbitai Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You'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.

Check out review usage here.

View limit details

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

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 9f6d1a1 and 17995c2.

Files ignored due to path filters: 3

  • .claude-plugin/fleet-skills/.source-digests/comment-and-doc-style is excluded by !.claude-plugin/fleet-skills/**
  • .claude-plugin/fleet-skills/skills/comment-and-doc-style/SKILL.md is excluded by !.claude-plugin/fleet-skills/**
  • .github/skills/comment-and-doc-style/SKILL.md is excluded by !.github/skills/**
Files selected for processing: 6

  • .agents/skills/comment-and-doc-style/SKILL.md
  • .github/actions/prose-gate/prose-gate.json
  • .github/actions/prose-gate/prose_lint.py
  • GOVERNANCE.md
  • host-setup/agent-safety/README.md
  • tests/test_prose_lint.py
  • 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

@ptr727

ptr727 commented Nov 24, 2026

Copy link
Copy Markdown
Owner Author

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

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

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

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

codecov Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.35%. Comparing base (b38e084) to head (17995c2).
⚠️ Report is 315 commits behind head on develop.

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     
Flag Coverage Δ
python-3.13 79.35% <ø> (-2.26%) ⬇️

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.

ptr727 and others added 2 commits November 23, 2026 17:10
- 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]>
@ptr727

ptr727 commented Nov 24, 2026

Copy link
Copy Markdown
Owner Author

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

ptr727 and others added 2 commits November 23, 2026 17:37
…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]>
@ptr727

ptr727 commented Nov 24, 2026

Copy link
Copy Markdown
Owner Author

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

ptr727 and others added 2 commits November 23, 2026 17:58
…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]>
@ptr727

ptr727 commented Nov 24, 2026

Copy link
Copy Markdown
Owner Author

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

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

Two active moderate findings show that attached shell command arguments are not recursively scanned, allowing forbidden placeholders to bypass the prose gate.

2 open issues
5 resolved since last review

Review effort: Lite

@ptr727

ptr727 commented Nov 24, 2026

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@ptr727

ptr727 commented Nov 24, 2026

Copy link
Copy Markdown
Owner Author

/review

@coderabbitai

coderabbitai Bot commented Nov 24, 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.

@ptr727
ptr727 merged commit b80a68d into develop Nov 24, 2026
15 checks passed
@ptr727
ptr727 deleted the burndown/paste-safe-second-shell branch November 24, 2026 02:45
ptr727 added a commit that referenced this pull request Nov 24, 2026
…, 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)
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