Skip to content

fix(security): judge every command of a substitution list for ssh-to-self - #37616

Merged
buluoray merged 1 commit into
mainfrom
crew/slack/ssh-self-subst-list
Nov 17, 2026
Merged

buluoray merged 1 commit into
mainfrom
crew/slack/ssh-self-subst-list

Conversation

@buluoray

@buluoray buluoray commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: An agent can no longer ssh back into its own host, outside the sandbox, by putting the ssh after ;, &&, ||, | or a newline inside an echo/printf command substitution, or after a second backtick span.

On main, the ssh-to-self floor allows all of these, although bash runs the ssh:

  • echo $(echo hi; ssh -p 22 localhost id) and the &&, ||, | and newline forms
  • echo `echo hi; ssh -p 22 localhost id`
  • echo `date` `ssh -p 22 localhost id`
  • echo "$(echo hi; ssh -p 22 localhost id)"
  • the same after a # comment line, or inside an unquoted heredoc body

This PR ports #37037 by @CrysisDeu onto current main. #37037 conflicts with main since #37443 changed argv_floor_ssh.py, and it had no new commit since 2026-11-14 19:46Z. The author is credited as co-author on the commit.

Why it matters

An ssh to this host leaves the sandbox: sshd is not sandboxed, so the remote command runs with the user's full rights. The ssh-to-self floor is the guard against that, and these spellings walk past it.

Not a goal

What changed (motivation → approach → change)

  • Root cause: main's static splice reads an echo/printf substitution as its first command's output, so $(echo hi; ssh -p 22 localhost id) becomes hi before the floor's walk runs, and the ssh command is gone.
  • Approach: main's floor keeps every verdict it gives; _is_ssh_to_self leaves an escaped backtick span unspliced on its own line, and main's splice reading (_MAIN_READING) splices such a span as main did. A new module, src/kiro_crew/security/argv_floor_ssh_bodies.py, adds one check, which can only add refusals. _reaches_self_over_ssh refuses if main's terms do, or if _substitution_reaches_self does.
    • _live_substitutions finds each $( ) and backtick body that bash runs. It reuses main's quote-aware readers (_matching_close_paren, _backtick_closer, _opens_comment, and read_commands for heredoc spans), so text in single quotes, comments and quoted-tag heredocs is never read as code.
    • Each body is judged with main's _is_ssh_to_self as a command line of its own, one nesting level at a time. A deeper body is replaced by _ and judged on its own turn, so the work grows linearly with nesting.
    • The bodies inside each bash -c / sh -c / eval / here-string payload, from main's _nested_shell_payloads, are judged the same way.
  • Escaped backticks: echo \`echo hi; ssh -p 22 localhost id\` is no substitution, but its ; is live, so the ssh runs. _is_ssh_to_self leaves an escaped backtick span unspliced on its own line (_splice_static_substitutions, _escaped), so the body check reads the live ;. The _MAIN_READING pass splices such a span, as main's splice did, and that keeps eval "ssh -p 22 \`printf localhost\`" refused, because that span runs one quoting level down.
  • Verb gate: _may_name_ssh_verb is factored out of _is_ssh_to_self, and both modules call the one copy.
  • One heredoc scan: the loop that finds each $( ) and backtick in an unquoted heredoc body moves out of shell_commands._body_substitutions into shell_commands._heredoc_body_substitutions, which returns spans. _body_substitutions and the new module both read it, so the ssh floor and read_commands cannot disagree about which heredoc bodies bash runs. test_heredoc_bodies_come_from_the_reader_scan pins it.
  • Facade: argv_floor.py lists the new owner module and serves the new names. Every name main serves is still served.
  • Budget: row test/security_line_budget/ssh-self-subst-list.txt is +192 (lines added minus removed under src/kiro_crew/security/, against main). The MCP listing module ceilings in test/test_mcp_listing_import_budget.py go up by 1 more for mcp-core, mcp-cron, mcp-guide and mcp-mate, because the deny floor that every listing loads now imports the new module. argv_floor_ssh.py is 1,600 lines; main's reading-depth bound (fix(security): bound how deep the ssh floor nests its readings #37820) and memo wrapper (fix(security): keep a quote in a $( ) from hiding a later ssh #37558) around _is_ssh_to_self forward its escapes_read flag. _reaches_self_over_ssh keeps fix(security): keep a quote in a $( ) from hiding a later ssh #37558's two readings (quote-aware, then main's old one) and adds the body check to both.
  • Spec: docs/system-specs/modules/security.md describes the new module and its residuals.

Backwards compatibility

Breaking: a command whose live $( ) or backtick body, or whose bash -c / eval payload body, runs ssh to this host is now refused with sandbox-escape-ssh-self, where main allowed it. Nothing main refuses becomes allowed: the new check is one more or on main's verdict. An ssh to a remote host inside a substitution list is now judged too, so like a plain ssh line it is refused on its first call while its DNS lookup is pending (#37311). Writer sweep on origin/main @ 8a485ab (git grep -n "_reaches_self_over_ssh\|_is_ssh_to_self(" -- src/):

  • src/kiro_crew/security/deny_gate.py:783 -- the only caller; it reads the verdict as before, and the rule moved under the same name, served by argv_floor.
  • src/kiro_crew/security/argv_floor.py:250 -- the facade; it still serves _reaches_self_over_ssh.

Known fail-closed false refusals, each visible and tracked, with nothing run that should not be:

Removes nothing: _reaches_self_over_ssh moves to the new module and stays served by argv_floor, and every name main serves is still served.

Tests

  • test_every_command_of_a_substitution_list_is_judged (81 rows, 61 of them allowed on main): the 12 sandbox-escape-ssh-self misses an ssh-to-self call after ; or && inside a command substitution #36949 shapes, every shape the review rounds found (bash -c / eval lists, s$()sh, double-quoted bodies, unquoted heredoc backticks, \$$(, escaped backticks, a heredoc fed to bash, a quoted ), a # glued after a closer as in $(date)#$(…), an escaped \# before a substitution, s$(printf s)h in a bash -c / eval payload), and bash -c 'ssh -p 22 $(printf localhost) id' with its eval, sh -c and bash <<< forms. 52 of these fail on main.
  • test_live_nested_substitution_payload_is_judged (3 rows, all failed on main) and test_known_fail_closed_residuals_are_refused (5 rows, each asserting the command and its body as a plain line are refused).
  • test_a_substitution_list_that_reaches_no_self_host_stays_allowed (44 rows) and test_literal_nested_substitution_payload_stays_allowed (4 rows): quoted text, comments (including $(date) #$(…) and $(date); #$(…)), quoted-tag heredocs, echo ssh as data, remote hosts, $$(, \$(, padded bodies, a 2.5 KB markdown gh pr create body that names rsync, and a 32-level nest (main's depth gate from fix(security): refuse a command nested past 32 substitutions before the floors walk it #37875 refuses a deeper one before any floor reads it).
  • test_nested_substitution_work_grows_linearly: counts the characters the floor judges for an N-level $( nest. At depth 40 the rule judges 259 characters; judging whole bodies instead judges 3,736 and fails the test.
  • test_repeated_eval_substitution_work_grows_linearly: counts the characters tokenized for "eval " * N + "echo $(echo ssh)". A frame produced by a join is never joined again, so 400 evals tokenize 4,027 characters instead of 407,416. 2,560 evals went from about 33.6 s to 0.43 s on one run.
  • Mutation: each piece turned off on its own turns its rows red. The substitution term covers 49 rows, the payload term 7, the unspliced escaped reading 2, the _MAIN_READING splice of escaped spans 6, the assignment-script bodies 5, keeping payloads and bodies apart in the dedup 4, and whole-body judging fails the linearity test.
  • Runs: test_denied_commands_security_ssh_self.py (637 tests), plus test_denied_commands_security.py, test_security_gate_liveness.py, test_facade_mirror_guards.py, test_argv_floor_facade.py, test_mcp_listing_import_budget.py, test_campaign_facades_base_public_names.py, test_blocked_commands_disclosure.py and test_denied_commands_security_cost.py: 1,403 passed. black, isort, flake8, mypy, line cap, comment history, brand and the flake ratchet all pass.

Proof: PROVEN test/test_denied_commands_security_ssh_self.py::TestSandboxEscapeSshSelf::test_every_command_of_a_substitution_list_is_judged[echo $(echo hi; ssh -p 22 localhost id)], test/test_denied_commands_security_ssh_self.py::TestSandboxEscapeSshSelf::test_every_command_of_a_substitution_list_is_judged[echo $(echo hi && ssh -p 22 localhost id)], test/test_denied_commands_security_ssh_self.py::TestSandboxEscapeSshSelf::test_every_command_of_a_substitution_list_is_judged[echo $(echo hi || ssh -p 22 localhost id)], test/test_denied_commands_security_ssh_self.py::TestSandboxEscapeSshSelf::test_every_command_of_a_substitution_list_is_judged[echo $(echo hi | ssh -p 22 localhost id)], test/test_denied_commands_security_ssh_self.py::TestSandboxEscapeSshSelf::test_every_command_of_a_substitution_list_is_judged[echo $(echo hi\nssh -p 22 localhost id)] (head f6ba2fb)

Manual verification

A read-only probe that only calls is_denied, on this head and on main, for every review trigger: each one refused on main stays refused here, and the list shapes main allows are refused. With no DNS on the probe host, remote-host rows are refused at top level too (ssh -p 22 remote.example.com id); that is #37311, not this diff. The tests pin them as allowed with DNS stubbed.

Related Issues

Closes #36949
Supersedes #37037 (based on its fix; credit to @CrysisDeu).
Residuals: #37632, #37638.
Merge order: rebased onto #37558 and #34056, which landed first. #35359 moves _reaches_self_over_ssh into argv_floor_ssh_walk.py, so it conflicts with this PR: whichever lands second rebases onto the other.

Sibling sweep

Swept: git grep -n "_static_substitution_output(" -- src/
Sibling: src/kiro_crew/security/argv_floor_self.py:680 -- not affected -- the self-kill walk passes every body to record_body and judges it as its own segment
Sibling: src/kiro_crew/security/argv_floor_ssh.py -- changed here

Pattern harvest

Rule candidate: review-prompt
Pattern: "a floor that stands a substitution's first word in for its output must also judge the substitution body as a command line of its own"

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

Contribution License Agreement

Contributions are accepted under the project's Apache-2.0 license; see the Licensing section of CONTRIBUTING.md.

@buluoray
buluoray requested review from a team and KiroCrewCaptain as code owners November 15, 2026 13:49
@buluoray
buluoray requested a review from CrysisDeu November 15, 2026 13:49
@buluoray
buluoray enabled auto-merge (squash) November 15, 2026 13:49
@github-actions

github-actions Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Sensitive Change Review

Sensitive files changed:

  • src/kiro_crew/security/argv_floor.py

  • src/kiro_crew/security/argv_floor_ssh.py

  • src/kiro_crew/security/argv_floor_ssh_bodies.py

  • src/kiro_crew/security/shell_commands.py

  • @bolichen97 approved f6ba2fb with a complete reasoning template.

@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Nov 15, 2026
@github-actions

github-actions Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision f6ba2fb89921b5da895e53607f76bcc7673e27dc touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Does not block merge.

@github-actions

github-actions Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of f6ba2fb89921b5da895e53607f76bcc7673e27dc — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

Nothing blocks: judging each substitution body as its own command line fixes the root cause, it only adds refusals, and every reader still reaches _reaches_self_over_ssh through the argv_floor facade.

Notes

[DESIGN-REVIEWED] f6ba2fb

Description read

[DESCRIPTION-READ] 86fd431b52024b8f7809077665bac1d145666436a47e365ff31fbe8942531a45

That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of f6ba2fb89921b5da895e53607f76bcc7673e27dc — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

First-Principles-Verdict: PASS

Nothing blocks. Each item closes a bypass that a test shows failing on main (52 rows), or is something the shared reader or a repo gate requires.

What this change ships

Inventory (9 items) — 9 justified

Intent: stop an agent from using ssh to get back into its own host, outside the sandbox, by placing the ssh after a list operator inside a $( ) or backtick body. FIX.

  1. An ssh to this host after ;, &&, ||, | or a newline inside a $( ) or backtick body, including a quoted body, a commented line or an unquoted heredoc, is now refused. — justified
  2. The same refusal applies to substitution bodies inside a bash -c, sh -c, eval or here-string payload. — justified
  3. An escaped backtick span is now read unspliced on its own line and spliced one quoting level down. — justified
  4. An ssh to a remote host inside a substitution list is now refused on its first call while the DNS lookup is pending, as a plain ssh line already is. — justified
  5. Four shapes that run no ssh are now refused (fail-closed); they are pinned and tracked in ssh-to-self floor: substitution gaps left by the list fix, and a backtick-cap false refusal #37638. — justified
  6. The verb gate (_may_name_ssh_verb) is factored out so the floor and the body check share one copy. — justified
  7. The heredoc substitution scan moves into _heredoc_body_substitutions, which read_commands and the floor now both read. — justified
  8. argv_floor serves the new module's names, and four MCP listings' module ceilings go up by 1. — justified
  9. A security line-budget row is added and security.md gains a section on the new module. — justified

[FIRST-PRINCIPLES-REVIEWED] f6ba2fb

Description read

[DESCRIPTION-READ] 4d5fd4b6f6ccb000d269d1bcbe7618654b724eb732ab3a6b469f3d3327e2402b

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions

github-actions Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed f6ba2fb89921b5da895e53607f76bcc7673e27dc — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] f6ba2fb

Verdict parsed from the review's SHA-scoped output markers for commit f6ba2fb89921b5da895e53607f76bcc7673e27dc.

False positive or not applicable? A repository writer can comment:
/ai-review override fable f6ba2fb89921b5da895e53607f76bcc7673e27dc false-positive: <reason, 20 to 500 characters>

@github-actions

github-actions Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of f6ba2fb89921b5da895e53607f76bcc7673e27dc and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] f6ba2fb

False positive or not applicable? A repository writer can comment:
/ai-review override gpt f6ba2fb89921b5da895e53607f76bcc7673e27dc false-positive: <reason, 20 to 500 characters>

@github-actions

github-actions Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Security Scope Review -- ✅ PASS

Which legitimate operations does f6ba2fb89921b5da895e53607f76bcc7673e27dc newly refuse? Updated in place on each push. A script-confirmed regression blocks; the model proposes candidates and never decides a refusal.

Verdict basis: adjudicated, zero confirmed regressions.

Security scope review -- adjudicated candidates

  • macos-latest (platform posix): 17 classified, 0 newly refused, 11 still allowed.
  • ubuntu-latest (platform posix): 17 classified, 0 newly refused, 11 still allowed.
  • windows-latest (platform windows): 6 classified, 0 newly refused, 3 still allowed.

No candidate flipped from allowed to refused.

Scope-Verdict: PASS

Reason: The ssh self-target floor now treats every $( ) or backtick body that bash runs as a command line of its own, and the deny composite can classify all of that. No script-confirmed regression was handed to this review. One part of the change refuses things on purpose even though bash runs no ssh: an unquoted-tag heredoc printed by cat inside a substitution, a glued ;echo, a # comment and an escaped \;. That reaches the common git commit -m "$(cat <<EOF … EOF)" / gh pr create --body "$(cat <<EOF …)" messages that mention ssh and a self host. I wrote candidates to probe it, but I could not confirm it.

TIGHTENING: the ssh self-target argv floor (sandbox-escape-ssh-self, _reaches_self_over_ssh in deny_gate.py) now also refuses any line where _substitution_reaches_self(text_lower) holds -- the threat is a later command in a substitution list reaching this host over ssh, which the old first-command static splice hid: "$(echo hi; ssh -p 22 <this host> id) would splice to hi. Each body that bash runs (unquoted, in double quotes, in an unquoted heredoc, nested, or inside a bash -c, sh -c, eval or here-string payload) is judged here as a command line of its own."

ADJUDICATED: 22 candidates, 0 confirmed newly-refused

PLATFORM COVERAGE: posix (16 rows): the diff's own assumptions are bash-only (POSIX quoting, heredocs, $( ) and backticks, bash -c/sh -c/eval). The posix rows probe each body context the new scan reads: an unquoted heredoc in a substitution, a quoted heredoc, double-quoted and unquoted lists, bash -c payloads, a remote ssh/scp/rsync next to a list, and localhost/hostname named in a list with no ssh verb. windows (5 rows): the same substitution shapes as a Windows host submits them — a Git Bash heredoc commit, ssh.exe/scp.exe/where.exe names, \ separators, C:/ remote paths and %USERPROFILE%/%TEMP% variables. The verb gate does a substring match on ssh/scp, so the .exe spellings still hit it. any (1 row): one platform-neutral echo of the attack text, which the diff's tests themselves hold allowed. The diff assumes no platform I could not write a candidate for.

UNADJUDICATED: Nothing in this tightening falls outside the shell classifier. One possible narrowing is argued but not confirmed. Path: deny_gate → _reaches_self_over_ssh → _substitution_reaches_self → _live_substitutions → _heredoc_body_substitutions / read_commands. Each body is then judged by _is_ssh_to_self, which reads the text a cat prints from an unquoted-tag heredoc as commands (test_known_fail_closed_residuals_are_refused). So a commit or PR body built from "$(cat <<EOF … ssh … localhost … EOF)" may be newly refused even though bash runs no ssh. If the harness confirms the heredoc rows, the narrowest fix is in _substitution_reaches_self: before judging a body, take out the heredoc text that a non-shell reader consumes (cat, tee), the way _without_quoted_heredoc_text already does for quoted heredocs. Bodies fed to bash/sh stay judged.

[SCOPE-REVIEWED] f6ba2fb

@KiroCrewCaptain

KiroCrewCaptain commented Nov 15, 2026 •

Copy link
Copy Markdown
Collaborator

Code change approver recommendation: A person should decide

Why: the decider thinks the change is probably fine but estimates a 15% chance that this change introduces a defect, above the 12% limit for approving on its own.

I'm approving: the PR closes a real escape from the ssh-to-self floor. On main, an ssh placed after a list separator inside an echo/printf $( ) or backtick body runs on this host but isn't refused. The fix adds one more or to main's verdict: each live body is judged as a command line of its own, one nesting level at a time. So it can only add refusals, and I found no path where something main refuses becomes allowed. The facade wiring, the memo key (now including escapes_read), the depth wrapper and the shared heredoc scan are all consistent. There are many tests, including ones on main's failing shapes, allowed cases and linear work growth, and CI test jobs pass. The one remaining failure is the security-scope adjudication, which reports newly refused but benign commands. They fail closed, a human released them as pre-existing, and the PR pins and tracks them. I put them in the notes rather than blocking on them.

Tier: 2, held for a person: the automated review did not clear it.

An automated recommendation, not a review: a maintainer still decides. It approves on its own only when the estimated chance of a defect is at most 12% and the change has at most 400 changed lines. Decider v3c (217fe607) · commit 2c97dbeecf · 644 changed lines. If this recommendation is wrong, reply here: replies are how the approver is evaluated.

@buluoray
buluoray force-pushed the crew/slack/ssh-self-subst-list branch from 684aa8f to 93dd8e8 Compare November 15, 2026 14:28
@buluoray

Copy link
Copy Markdown
Contributor Author
  • Padding past the list caps fails open span=f6d47cc1a063

fixed in 93dd8e8: _spliced_command_lists no longer drops a body or list silently. A body over _SPLICED_LIST_CHAR_CAP, or a list that does not fit the budget, refuses the line when that text names an ssh-family verb (the floor's existing gate, moved unchanged into _may_name_ssh_verb). Otherwise the walk skips it with continue, not break, so later lists are still judged. The same rule now covers the backtick cap and a reader RecursionError.
Rows, red first on 684aa8f: your echo $(echo <2020 x>; true) $(echo hi; ssh -p 22 localhost id), a 2,050-char body, two 1,010-char lists, and a 1,500/1,000 pair that tells continue from break. Padded bodies with no ssh word stay allowed. Each padded row runs under 0.05 s.

@buluoray

Copy link
Copy Markdown
Contributor Author

Security Scope on 684aa8f: the remote-host rows are not new refusals.

All 10 rows name build.example.com. On a host where that name does not resolve (CI has no DNS for it), main already refuses the same ssh/scp when it is written as its own command or as a bare $( ). This PR only makes the command after ; inside an echo/printf list read the way the plain command already reads.

Read-only is_denied probe on this no-DNS host, main bdff21a134e8 vs this PR's head 93dd8e872ff2:

Command main PR
echo checking; ssh -p 22 deploy@build.example.com uptime refused refused
x=$(ssh -p 22 deploy@build.example.com uptime) refused refused
echo fetching; scp deploy@build.example.com:/var/log/app.log ./app.log refused refused
echo $(echo checking; ssh -p 22 deploy@build.example.com uptime) allowed refused
echo $(echo fetching; scp deploy@build.example.com:/var/log/app.log ./app.log) allowed refused

So the "newly refused" rows come from main's handling of a host it cannot resolve, which is tracked in #37311. With DNS working (stubbed in the tests), the remote-host rows in test_a_substitution_list_that_reaches_no_self_host_stays_allowed stay allowed. The lane's own adjudication agrees: ADJUDICATED: 19 candidates, 0 confirmed newly-refused.

@buluoray
buluoray force-pushed the crew/slack/ssh-self-subst-list branch from 93dd8e8 to 3229e2f Compare November 15, 2026 14:50
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Nov 15, 2026
@buluoray

Copy link
Copy Markdown
Contributor Author

resolution: deferred #37632

  • Size-cap refusal bypasses the literal-message exemption span=8512aebfda4d

Rebutted as a fail-closed false refusal, not a bypass. It needs a quoted literal holding a backtick span over 2,048 characters that also contains a list operator and an ssh verb. The refusal is visible as sandbox-escape-ssh-self, nothing runs that should not, and --body-file avoids it. The adjudicator flagged it the same way.
Moving the literal check ahead of the cap would add an allow path to the padding refusal that round 1 closed. The false refusal is tracked in #37632, with the fix idea of asking the reader whether the span is live before the cap refusal.

@buluoray

Copy link
Copy Markdown
Contributor Author
  • Substitution limits allow padding to bypass the SSH floor span=8512aebfda4d

fixed in 93dd8e8: at every cap (body size, list budget, _PAIRED_BACKTICK_CAP, reader recursion), the skipped text refuses the line when it names an ssh-family verb, and the walk otherwise goes on to later lists. Rows, red first: the 2,050-char body, two 1,010-char lists before a final ssh list, and 32 `date` spans before `date` `ssh -p 22 localhost id`.

@buluoray

Copy link
Copy Markdown
Contributor Author
  • Quoted executable payloads lose their substitution lists before inspection span=8512aebfda4d

fixed in 93dd8e8: every bash -c / eval payload source from the existing argv_floor_self._shell_payload_sources walk gets the same list and paired readings, before any splice. No new payload parser. Rows, red first: bash -c 'echo $(echo hi; ssh -p 22 localhost id)' and the eval form. bash -c 'echo $(echo hi; echo ssh -p 22 localhost id)' stays allowed.

@buluoray

Copy link
Copy Markdown
Contributor Author
  • Expanding heredocs conceal live backtick delimiters span=8512aebfda4d

fixed in 93dd8e8: _live_backticks reads HereDoc.quoted from the shared reader. In an unquoted-tag body, a backtick that no backslash escapes is live; a quoted-tag body stays literal. Row, red first: cat <<EOF + `date` `ssh -p 22 localhost id` + EOF. The <<'EOF' form stays allowed.

@buluoray

Copy link
Copy Markdown
Contributor Author
  • Payload readings skipped when the verb is spelled with an empty splice span=49f9306ff16b

fixed in 3229e2f: _may_name_ssh_verb now checks the text both as given and with empty $() / backtick pairs removed. That one change covers every caller: the payload gate, the backtick-cap refusal and the size-cap refusals. Rows, red first on 93dd8e8: bash -c 'echo $(echo hi; s$()sh -p 22 localhost id)', the eval form, the sshform, andecho "$(echo date s$()sh -p 22 localhost id)"``. With the gate reading only the raw text, exactly those 4 rows go red.

@buluoray

Copy link
Copy Markdown
Contributor Author
  • Backticks inside a double-quoted "$(...)" are never read as live span=f6d47cc1a063

Rebutted: 93dd8e8 already refuses this trigger at is_denied. echo "$(echo `date` `ssh -p 22 localhost id`)" and its newline-joined form were both refused on a clean checkout of that head (main allows both). _live_backticks does see no live backticks in the line's own reading. But argv_floor_self._shell_payload_sources hands the double-quoted body to _substitution_readings_reach_self as a payload source, and in that body the backticks are unquoted, so the paired reading keeps the spans apart. Turning off the payload sources turns these rows red. All three forms are now pinned as rows.

@buluoray

Copy link
Copy Markdown
Contributor Author

Security Scope on 3229e2f: what the "newly refused" rows are.

Remote-host rows (build.example.com, artifacts.example.com, prod.example.com, git@github.com, ssh -G build.example.com, sftp ... artifacts.example.com). These are not new refusals of a reachable remote host. On a host where the name does not resolve (CI has none of these names), main already refuses the same ssh/scp/sftp written as a plain command or as a bare $( ). This PR only makes the command after ;, && or a newline inside an echo/printf list read the way the plain command already reads. Main's handling of an unresolvable host is #37311. With DNS working (stubbed in the tests), the remote-host rows of test_a_substitution_list_that_reaches_no_self_host_stays_allowed stay allowed.

Read-only is_denied probe on a no-DNS host, main bdff21a134e8 vs this PR:

Command main PR
echo checking; ssh -p 22 deploy@build.example.com uptime refused refused
x=$(ssh -p 22 deploy@build.example.com uptime) refused refused
echo $(echo checking; ssh -p 22 deploy@build.example.com uptime) allowed refused

The 33-backtick-span row ending in rsync -a ./dist/ ./backup/. This one is a real false refusal that this PR adds. Past _PAIRED_BACKTICK_CAP (64 backticks), the floor refuses a line whose text names an ssh-family verb, so the padding bypass that review round 1 found stays closed. rsync counts as such a verb even with local paths. It fails closed and is visible, and a line of 33 substitutions is rare. It is tracked in #37638 with a fix idea.

The lane's own adjudication on the earlier head agreed on the remote rows: ADJUDICATED: 19 candidates, 0 confirmed newly-refused.

@buluoray

Copy link
Copy Markdown
Contributor Author

resolution: deferred #37638

  • Quoted backticks inside heredoc substitutions corrupt pairing span=ce787e01ed3e

Rebutted: not a defect this PR adds or widens. On main 8dd2f58c391e, cat <<EOF + $(echo '')+ ``date ssh -p 22 localhost id`` +EOFis allowed, and it is allowed on this head too: the verdict is the same. The PR closes the 12 #36949 shapes and the 7 round-1 shapes, and none of them goes back to allowed. Taking backtick liveness inside an expanding heredoc from the reader's nested quote state is tracked in #37638. Read-onlyis_deniedprobe, main vs head: shape allowed / allowed; the same heredoc without the$(echo '') line allowed / refused.

@buluoray

Copy link
Copy Markdown
Contributor Author

resolution: deferred #37638

  • Independent command checks discard SSH executable bindings span=ee01d057cd1a

Rebutted: not a defect this PR adds or widens. echo $(echo hi; cp /usr/bin/ssh /tmp/client; /tmp/client -p 22 localhost id) is allowed on main 8dd2f58c391e and on this head. Main never judged the commands inside an echo list at all, so the copied-client case gets through there too. The PR judges more of the list than main does and drops no refusal. Keeping bindings across the commands of one list is tracked in #37638.
Read-only is_denied probe, main vs head: list form allowed / allowed; echo hi; cp ...; /tmp/client ... without $( ) refused / refused.

@buluoray
buluoray force-pushed the crew/slack/ssh-self-subst-list branch from 3229e2f to b0f18ab Compare November 15, 2026 17:15
@github-actions

Copy link
Copy Markdown
Contributor

Human judgment recorded

@buluoray recorded a pre-existing release (class pre-existing) for the gpt AI finding on d2732df94c51fea9b7d29ba7876e0d6faec1ad62.

agent: security findings main also has. A substitution list inside an assignment-prefixed bash -c payload, and one inside a function body that takes its host from $1, are allowed on main 3d020c4 and on this head; the no-list forms are refused on both. Not added or widened here; tracked in #37638 item 10.

This decision applies only to this commit. A new push requires a new judgment.

@bolichen97

Copy link
Copy Markdown
Contributor

@buluoray two things are left on d2732df94c before a maintainer can approve:

  1. Sensitive Change Review: the template names 428246e. Please post it again for d2732df94c, with the escaped \# change under "What rule changed".
  2. GPT's open shape: bash -c 'a=x; echo $(echo hi; ssh -p 22 localhost id)' is still allowed. It is not a regression (main allows it too), but it is the ;-inside-an-echo-substitution shape this PR's Goal names. The Captain found a one-term fix in _reaches_self_over_ssh (or any(map(_substitution_reaches_self, scripts))) that refused it locally and changed no row of the PR's tables. I'd take that fix here, with a refuse row, rather than defer it. The function-argument shape (f(){ ... ssh -p 22 "$1" id; }; f localhost) can stay deferred to ssh-to-self floor: substitution gaps left by the list fix, and a backtick-cap false refusal #37638 with a pinning row that names it.

Also please name #35359 in the merge-order line: it moves _reaches_self_over_ssh too, so the two PRs conflict.

AI-assisted, sent by Bolin Review bot

@buluoray

Copy link
Copy Markdown
Contributor Author

resolution: deferred #37638

  • Payload extraction reopens inert heredoc and comment text span=f922f61d1e93

Deferred as a fail-closed false refusal, tracked as #37638 item 11 (comment 6936225223). Nothing runs that should not. Main c30bfba already refuses the no-list form, cat > f <<'EOF'⏎bash -c 'ssh -p 22 <this host> id'⏎EOF, for the same reason: its payload reader reads the whole text.
The fix (extract payloads from text with quoted heredoc bodies blanked) belongs in both readers at once, in the #37638 follow-up.

@buluoray

Copy link
Copy Markdown
Contributor Author

resolution: deferred #37638

  • _live_substitutions returns overlapping spans, so the reverse splice cuts the wrong characters span=ada014317939

Rebutted as a security gap that main also has; this PR neither adds nor widens it. Tracked as #37638 item 11 (comment 6936225223). is_denied on main c30bfba and on this head allows bash -c 'echo $(echo $(cat <<EOF⏎$(echo $(true))⏎EOF⏎); ssh -p 22 <this host> id)' and its eval form on both.
Main misses every list inside a payload's substitution, so no reading added here opens it. The fix (drop spans nested in an earlier one before splicing) goes in the #37638 follow-up.

@buluoray

Copy link
Copy Markdown
Contributor Author

resolution: deferred #37638

  • Newly refused: echo "$(echo 'To connect:';echo ssh -p 2222 <this host>)"

Deferred: this is the known glued ;echo residual (#37638, pinned in test_known_fail_closed_residuals_are_refused). Its body as a plain line, echo 'To connect:';echo ssh -p 2222 <this host>, is refused on main c30bfba; the body check judges the body as that line, so it inherits the refusal. With a space after ; it is allowed on main and on this head. Recorded as #37638 item 11 (comment 6936225223).

@buluoray

Copy link
Copy Markdown
Contributor Author

/ai-review override fable 2c97dbe pre-existing #37638: agent: security finding main also has. A heredoc inside a nested $( ) in a bash -c/eval payload hides a later ssh; main c30bfba allows the same command and this head gives the same verdict. Not added or widened here; tracked in #37638 item 11.

@buluoray

Copy link
Copy Markdown
Contributor Author

/ai-review override gpt 2c97dbe deferred #37638: agent: security-class finding, a false refusal that fails closed. A bash -c list inside a quoted-tag heredoc is refused here though nothing runs; main refuses the no-list form for the same reason. Fix both payload readers together in #37638 item 11.

@buluoray

Copy link
Copy Markdown
Contributor Author

/ai-review override scope 2c97dbe pre-existing #37638: agent: the row's substitution body, echo 'To connect:';echo ssh ..., is refused as a plain line on main c30bfba (the glued ;echo residual pinned in test_known_fail_closed_residuals_are_refused); the body check inherits it. A space after ; is allowed on both.

@buluoray

Copy link
Copy Markdown
Contributor Author

Sensitive change review

@github-actions

Copy link
Copy Markdown
Contributor

Human judgment recorded

@buluoray recorded a pre-existing release (class pre-existing) for the fable AI finding on 2c97dbeecf782040f9e0dee56f5d2c972054e833.

agent: security finding main also has. A heredoc inside a nested $( ) in a bash -c/eval payload hides a later ssh; main c30bfba allows the same command and this head gives the same verdict. Not added or widened here; tracked in #37638 item 11.

This decision applies only to this commit. A new push requires a new judgment.

@github-actions

Copy link
Copy Markdown
Contributor

Human judgment recorded

@buluoray recorded a deferred release (class deferred) for the gpt AI finding on 2c97dbeecf782040f9e0dee56f5d2c972054e833.

agent: security-class finding, a false refusal that fails closed. A bash -c list inside a quoted-tag heredoc is refused here though nothing runs; main refuses the no-list form for the same reason. Fix both payload readers together in #37638 item 11.

This decision applies only to this commit. A new push requires a new judgment.

@github-actions

Copy link
Copy Markdown
Contributor

Human judgment recorded

@buluoray recorded a pre-existing release (class pre-existing) for the scope AI finding on 2c97dbeecf782040f9e0dee56f5d2c972054e833.

agent: the row's substitution body, echo 'To connect:';echo ssh ..., is refused as a plain line on main c30bfba (the glued ;echo residual pinned in test_known_fail_closed_residuals_are_refused); the body check inherits it. A space after ; is allowed on both.

This decision applies only to this commit. A new push requires a new judgment.

@KiroCrewCaptain

Copy link
Copy Markdown
Collaborator

Thanks for the new round. I found no code defect in this head that blocks the change. One maintainer request is still open, so a maintainer needs to decide before this can merge.

Earlier items, one by one:

  1. Over-cap single-command body refused (first change request): fixed. The cap module is gone, and the long markdown gh pr create body with * bullets and rsync has a row that stays allowed.
  2. Sensitive Change Review for the current head: fixed. It was posted again for 2c97dbe, and the escaped \# change is listed under "What rule changed".
  3. bash -c 'a=x; echo $(echo hi; ssh -p 22 localhost id)': still stands. Head still allows it, and main allows it too, so it is not a regression. But it puts an ssh after ; inside an echo substitution, and that is the shape the Goal names. A maintainer asked in comment 6935161820 for the one-term fix here, with a refuse row. Head does not take it. The thread has no reply, and the only deferral to ssh-to-self floor: substitution gaps left by the list fix, and a backtick-cap false refusal #37638 item 10 comes from the author. In a local copy of head, changing src/kiro_crew/security/argv_floor_ssh_bodies.py:157 to if _substitution_reaches_self(text_lower) or any(map(_substitution_reaches_self, scripts)): refused that command. With that change all 551 tests in test_denied_commands_security_ssh_self.py still passed, and bash -c 'a=x; echo $(echo hi; echo ssh -p 22 localhost id)' stayed allowed. Please take that change and add a refuse row for the command. If you would rather defer it, reply on that comment, add a pinning row that names ssh-to-self floor: substitution gaps left by the list fix, and a backtick-cap false refusal #37638, and let the maintainer who asked accept the deferral.
  4. Merge-order line: still stands. fix(security): read a multi-line script a shell runs in the ssh-to-self floor #35359 also moves _reaches_self_over_ssh, into argv_floor_ssh_walk.py, so the two PRs conflict. Name it in the Related Issues line. That is a body edit, so no push is needed.

What the review checked on this head:

  • Read-only is_denied probes on the head and merge-base trees. Every list form the Goal names changes from allowed to refused. A 6,048-command differential found no command that reaches this host where the merge-base refuses and head allows.
  • test_denied_commands_security_ssh_self.py passes at head (551 tests). Each new term turned off on its own turns its own rows red.
  • The three lane overrides on this head are all for gaps main also has or for refusals that fail closed. None of them lets through anything main refuses.

Done well: the heredoc substitution scan now lives in one function, shell_commands._heredoc_body_substitutions, so the ssh floor and read_commands cannot disagree. The two linearity tests count characters instead of timing, so they are deterministic.

Optional:

  • A nested escaped backtick inside a backtick body is still allowed, as on main: echo `echo hi; ssh -p 22 \`printf localhost\` id`. The backtick body is judged before one backslash level is removed. ssh-to-self floor: substitution gaps left by the list fix, and a backtick-cap false refusal #37638 does not list it yet.
  • The body says the change "can only add refusals". That is not quite true. A few $( ) bodies with an escaped backtick inside, such as echo $(echo hi; s\`printf s\`h -p 22 localhost id), were refused before and are now allowed. bash runs no ssh in them, so the new verdict is correct, but the sentence should say so.

@bolichen97

Copy link
Copy Markdown
Contributor

@buluoray answering as the maintainer who asked in #37616 (comment): I don't accept deferring that shape. I checked 157438e318 with is_denied:

  • bash -c 'a=x; echo $(echo hi; ssh -p 22 localhost id)': still allowed (None).
  • echo $(echo hi; ssh -p 22 localhost id): refused, as expected.

_reaches_self_over_ssh still calls _substitution_reaches_self(text_lower) only, not on the quoted assignment scripts. The Captain's one-term change (... or any(map(_substitution_reaches_self, scripts))) refused the command and kept all 551 ssh-self tests green in a local copy, and the echo ssh ... twin stayed allowed. It's the ;-inside-an-echo-substitution shape this PR's Goal names, so it belongs here. Please take that change with a refuse row for the command and an allow row for the echo ssh twin.

Also, please name #35359 in the merge-order line of the body (body edit only): it moves _reaches_self_over_ssh too.

With those two done, this is ready from my side.

AI-assisted, sent by Bolin Review bot on behalf of @bolichen97

@KiroCrewCaptain KiroCrewCaptain left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for the new round. The list walk still closes the shapes the Goal names, and the escaped \# fix holds. But this head now allows ssh-to-self commands that main refuses. The maintainer's open request is not taken yet either. Two changes are needed before merge.

  1. security/argv_floor_ssh.py:179 and :1118 open a new escape compared with main.

    • Trigger: eval "x=\$(echo hi; ssh -p 22 \`printf local\`host id)". Five siblings behave the same way: the same payload under bash -c, with a y=1; prefix, with echo local in place of printf local, with && in place of ;, and with s\`printf s\`h as the verb.
    • Outcome: is_denied refuses all six on the merge-base with sandbox-escape-ssh-self and returns None on this head. We ran the first one in bash with ssh shadowed by a function, and it runs ssh -p 22 localhost id. So the agent reaches this host outside the sandbox. This also contradicts the body's "Nothing main refuses becomes allowed".
    • Cause: _splice_static_substitutions now keeps escaped backtick spans even under _MAIN_READING. So the main-reading fallback in _reaches_self_over_ssh no longer reads the line the way main did. The escapes_read recursion on both then splices a second time. By then the $( ) is flat, and the second splice erases the ssh.
    • Smallest fix: at line 179, write if out == "\x00" or (escaped and not escaped_too and not _MAIN_READING.get()):. In a local copy this refuses all six. eval "ssh -p 22 \`printf localhost\`" stays refused, and the probed allow rows such as echo \`echo hi; echo ssh -p 22 localhost id\` and echo \`date\` \`whoami\` stay allowed. Add refuse rows for the six commands. Also correct the body sentence and the security.md text that call _MAIN_READING main's unchanged reading.
  2. security/argv_floor_ssh_bodies.py:160 still allows bash -c 'a=x; echo $(echo hi; ssh -p 22 localhost id)'.

    • Outcome: this is the ssh after ; inside an echo substitution that the Goal names, and bash runs that ssh. Without the a=x; the same payload is refused. The sh -c form, the a=x && form, the backtick form and the "$( )" form are allowed too. Main allows these as well, so this is not a regression, but the gap is in the check this PR adds.
    • Cause: line 160 runs _substitution_reaches_self on the whole line only. It never runs it on the scripts that line 155 already computes.
    • Smallest fix: if _substitution_reaches_self(text_lower) or any(map(_substitution_reaches_self, scripts)):. Add a refuse row for the command and an allow row for the echo ssh twin. The maintainer asked for exactly this change on this PR and declined the deferral. In a local copy, all 620 tests in test_denied_commands_security_ssh_self.py stay green with it. This change does not close item 1.

Earlier items, one by one:

  • Long single-command body refused (first review): fixed.
  • Static substitution in a single-quoted payload, and the 1000-level row timeout (second review): fixed.
  • Escaped \# read as a comment (third review): fixed. The check now compares step.text.
  • The a=x; payload shape: still stands, see item 2.
  • Merge-order line naming #35359: still stands. #35359 moves _reaches_self_over_ssh into argv_floor_ssh_walk.py, so the two PRs conflict. This is a body edit only.

Optional:

  • The fail-open residuals deferred to #37638, such as bash -c "echo \$(echo hi; ssh -p 22 localhost id)", have no pinning rows, but the fail-closed ones do. A strict xfail that names #37638 would make a later fix flip them on purpose.
  • echo `echo hi; ssh -p 22 \`printf localhost\` id` is still allowed, as on main. #37638 does not list it yet.
  • The latest Sensitive change review comment names 2c97dbe, not this head.

@buluoray

Copy link
Copy Markdown
Contributor Author

Thanks, both items are fixed on b834d85.

  1. Main-reading escape (regression): _splice_static_substitutions now splices an escaped backtick span under _MAIN_READING, as main's splice did (argv_floor_ssh.py:179, your suggested condition). All six triggers are new refuse rows in test_every_command_of_a_substitution_list_is_judged. Reverting the condition turns those 6 rows red. The docstring, security.md and the body no longer call _MAIN_READING main's unchanged reading; they say it also splices escaped spans, as main did.
  2. a=x; payload: _reaches_self_over_ssh now also runs _substitution_reaches_self on each quoted assignment script (argv_floor_ssh_bodies.py:160). The bash -c, sh -c, a=x &&, backtick and "$( )" forms are refuse rows, and bash -c 'a=x; echo $(echo hi; echo ssh -p 22 localhost id)' is an allow row. Reverting the change turns those 5 rows red.

Also:

test_denied_commands_security_ssh_self.py: 632 tests; 1,398 related tests pass; prove.py PROVEN on b834d85. The SCR will be re-posted for this head.

bolichen97
bolichen97 previously approved these changes Nov 17, 2026

@bolichen97 bolichen97 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.

Approving b834d85a8b. My maintainer request from #37616 (comment) is done. I checked it with is_denied on this head:

  • bash -c 'a=x; echo $(echo hi; ssh -p 22 localhost id)': refused (sandbox-escape-ssh-self), allowed before this push.
  • bash -c 'a=x; echo $(echo hi; echo ssh -p 22 localhost id)': still allowed.
  • echo $(echo hi; ssh -p 22 localhost id): refused.

The body now names #35359 in the merge order. test/test_denied_commands_security_ssh_self.py passes locally on this head (632 passed). The Captain's change request on 0967b13d7d (main-reading escape) is answered on this head, and the Captain will re-review it.

Sensitive change review

  • What rule changed: the ssh-to-self argv floor now judges every command of a ;/&&/|| list inside a $( ) or backtick substitution, including substitution bodies inside a quoted bash -c / assignment script, instead of only the first command of the substitution.
  • Before -> after: echo $(echo hi; ssh -p 22 localhost id) and its bash -c 'a=x; ...' form reached this host before and are refused now; an echo ssh ... that only prints the words stays allowed.
  • Worst case if wrong: an ordinary command whose substitution body mentions ssh to a local name is refused, which fails closed; the 6,048-command differential the Captain ran found no command that main refuses and this head allows.
  • Evidence checked: read the diff in argv_floor_ssh.py, argv_floor_ssh_bodies.py and shell_commands.py; probed the three commands above with is_denied on this head; ran the ssh-self suite (632 passed).
  • Tools still work: grep, sed and jq bodies, ssh-keygen, remote ssh and quoted-tag commit bodies stay allowed per the suite's allow rows.
  • Backward compatible: yes, the change only adds refusals for commands that reach this host; the documented known gaps stay pinned and tracked in #37638.
  • Existing tests: test_denied_commands_security_ssh_self.py, 632 passed on this head, with refuse and allow rows for each new term.
  • How to undo: revert this PR's commit; the floor goes back to judging only the first command of a substitution.

AI-assisted, sent by Bolin Review bot

@buluoray

Copy link
Copy Markdown
Contributor Author

resolution: deferred #37311

  • Newly refused row: echo $(echo starting; ssh -p 2222 git@github.com 2>&1 | head -1)

Rebutted, same cause as the earlier remote-host rows (#37311). The floor refuses an ssh target whose name it cannot resolve in time, on main as here. On a host with DNS, the same is_denied call on ssh -p 2222 git@github.com id was refused on its first call and allowed on its second, on both the merge-base d36674e and this head: the first lookup timed out.

The body typed as a plain line, ssh -p 2222 git@github.com 2>&1 | head -1, is refused on the merge-base too. This PR judges the body as that same plain line, so it inherits main's refusal. It fails closed: nothing runs that should not, and the fix belongs in the resolver (#37311), not in the body check.

@KiroCrewCaptain KiroCrewCaptain left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for the new round. Both items from my last review are fixed on this head, but the new body check still skips a body in one case, so one change is needed before merge.

  1. src/kiro_crew/security/argv_floor_ssh_bodies.py:134-144 (_substitution_reaches_self) uses one seen set for two kinds of work item. Nested payloads go in with judge=False and are never judged. Substitution bodies go in with judge=True. When a payload has the same text as a body, the body is found in seen and never gets judged.
    • Trigger: echo $(echo hi; ssh -p 22 localhost id) bash -c 'echo hi; ssh -p 22 localhost id'. The bash -c '...' here is only text that echo prints. The same thing happens with x=$(echo hi; ssh -p 22 localhost id) && echo eval 'echo hi; ssh -p 22 localhost id', with the backtick form plus sh -c, and with the double-quoted "$( )" form.
    • Outcome: is_denied allows all of these on this head. Without the trailing word, the same command is refused as sandbox-escape-ssh-self, and so is the same command with bash -c 'echo x'. Bash still runs the $( ) body, so the ssh reaches this host outside the sandbox. Main allows these too, so this is not a regression. But the check this PR adds is the one that drops the body, and the shape is the one the Goal names.
    • Smallest fix: keep payloads and bodies apart in the dedup. Key seen by (text, judge) or use two sets. Work at most doubles, so the linearity tests still hold. Then add refuse rows for the trailing bash -c, eval and sh -c twin forms.

Earlier items, one by one:

  • Main-reading escape at argv_floor_ssh.py:179: fixed. The condition now checks not _MAIN_READING.get().
  • a=x; payload shape at argv_floor_ssh_bodies.py:160: fixed. The scripts term is now judged.
  • Merge-order line naming #35359: fixed in the body.
  • Items from the three earlier reviews: still fixed.

PR Readiness is also red on the Security Scope row. That row is the DNS-pending first-contact refusal tracked in #37311, so it needs a maintainer override on the final head, not a code change.

Optional:

  • The escaped-backtick spliced reading at argv_floor_ssh.py:1118-1120 never refuses anything. The escaped_too splice turns \`printf localhost\` into \localhost_. Deleting those lines turns no test red, and the rows the body names are refused by the _MAIN_READING pass instead. Substitution bodies get no _MAIN_READING pass, so echo $(echo hi; eval "ssh -p 22 \`printf localhost\`") is allowed, but the same body typed as a plain line is refused. Either consume the escaping backslashes in that splice and add a body-level row that fails without it, or drop the reading. Also correct the mutation count in the body.
  • The Approach bullet "main's floor stays exactly as it is" no longer matches the diff, because _is_ssh_to_self itself changes for escaped backtick spans. The take-away line could also say that an ssh to a remote host inside a substitution list is refused on its first call while its DNS lookup is pending (#37311). Both are body edits only.
  • test/test_denied_commands_security_ssh_self.py grows to 1,967 lines, 33 under the cap. Moving the substitution-body tests into a sibling module would leave room for the next row.

@buluoray

Copy link
Copy Markdown
Contributor Author

Thanks. Item 1 is fixed on aa6679b.

  1. Shared seen set: _substitution_reaches_self now keys seen by (text, judge), so a nested payload with the same text no longer hides a body. The trailing bash -c, eval, sh -c (backtick) and "$( )" twin forms are new refuse rows in test_every_command_of_a_substitution_list_is_judged. Keying bodies like payloads again turns those 4 rows red. The linearity tests still pass.

Body edits:

Not done in this PR:

test_denied_commands_security_ssh_self.py: 636 tests; 1,402 related tests pass; prove.py PROVEN on aa6679b. The Security Scope row is the #37311 DNS case and gets a maintainer override on the final head.

bolichen97
bolichen97 previously approved these changes Nov 17, 2026

@bolichen97 bolichen97 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.

Re-approving aa6679b990. The range-diff against b834d85a8b (which I approved) only keys the seen set by (body, quoted), so a body seen in one reading is still judged in the other, and adds four refuse rows for the mixed $( ) + bash -c shapes. My maintainer request from #37616 (comment) is done. I checked it with is_denied on this head:

  • bash -c 'a=x; echo $(echo hi; ssh -p 22 localhost id)': refused (sandbox-escape-ssh-self), allowed before this push.
  • bash -c 'a=x; echo $(echo hi; echo ssh -p 22 localhost id)': still allowed.
  • echo $(echo hi; ssh -p 22 localhost id): refused.

The body now names #35359 in the merge order. test/test_denied_commands_security_ssh_self.py passes locally on this head (636 passed). The Captain's change request on b834d85a8b is answered on this head, and the Captain will re-review it.

Sensitive change review

  • What rule changed: the ssh-to-self argv floor now judges every command of a ;/&&/|| list inside a $( ) or backtick substitution, including substitution bodies inside a quoted bash -c / assignment script, instead of only the first command of the substitution.
  • Before -> after: echo $(echo hi; ssh -p 22 localhost id) and its bash -c 'a=x; ...' form reached this host before and are refused now; an echo ssh ... that only prints the words stays allowed.
  • Worst case if wrong: an ordinary command whose substitution body mentions ssh to a local name is refused, which fails closed; the 6,048-command differential the Captain ran found no command that main refuses and this head allows.
  • Evidence checked: read the diff in argv_floor_ssh.py, argv_floor_ssh_bodies.py and shell_commands.py; probed the three commands above with is_denied on this head; ran the ssh-self suite (636 passed).
  • Tools still work: grep, sed and jq bodies, ssh-keygen, remote ssh and quoted-tag commit bodies stay allowed per the suite's allow rows.
  • Backward compatible: yes, the change only adds refusals for commands that reach this host; the documented known gaps stay pinned and tracked in #37638.
  • Existing tests: test_denied_commands_security_ssh_self.py, 636 passed on this head, with refuse and allow rows for each new term.
  • How to undo: revert this PR's commit; the floor goes back to judging only the first command of a substitution.

AI-assisted, sent by Bolin Review bot

@buluoray

Copy link
Copy Markdown
Contributor Author

self-added: yes
resolution: deferred #37632

  • A body is judged without its cased raw_text, so echo $(sudo -H ls s* l*) is refused span=f922f61d1e93

Confirmed and deferred as a fail-closed false refusal, tracked with the other false refusals in #37632. Nothing runs that should not: the body check is one more or on main's verdict, as the adjudicator also found. It needs a substitution body, a wrapper option whose meaning depends on case (sudo -H/-E/-e), and glob words that the floor reads as an ssh verb and as this host. On this head, sudo -H ls s* l* is allowed, and echo $(sudo -H ls s* l*) is refused. The refusal is loud and names sandbox-escape-ssh-self, and lowercasing the option or moving the command out of the substitution gets past it.

The fix is to carry each body's cased text through every body reader (backticks, heredocs, bash -c / eval / here-string payloads) and the escaped-backtick re-read. That widens the reader again, so it goes in the #37632 follow-up rather than in this PR, which a maintainer has approved on this head.

@buluoray

Copy link
Copy Markdown
Contributor Author

resolution: deferred #37311

  • Newly refused row: an scp to build.example.com inside a double-quoted substitution list

Rebutted, same cause as the earlier remote-host rows (#37311). build.example.com does not resolve, and the floor refuses an ssh-family target it cannot resolve, on main as here. On this head, the row's body typed as a plain line, scp dist.tar.gz deploy@build.example.com:/tmp/, is refused too. This PR judges the body as that same plain line, so it inherits the refusal. It fails closed, and the fix belongs in the resolver (#37311), not in the body check.

@KiroCrewCaptain KiroCrewCaptain left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for the new round. The shared seen fix holds on this head, and the list walk still closes the shapes the Goal names. One change is needed before merge.

  1. security/argv_floor_ssh.py:1117-1120 (the both re-read with escapes_read=True) never refuses anything, and the spec credits it with a refusal another pass makes.
    • Trigger: any line with an escaped backtick span, for example eval "ssh -p 22 \`printf localhost\`" or echo $(echo hi; eval "ssh -p 22 \`printf localhost\`"). The escaped_too splice rewrites the output's trailing backslash as _, so \`printf localhost\` becomes \localhost_, and the re-read never names this host.
    • Outcome: we made line 1119 if False:, and every verdict stayed the same: all 132 rows of the four new tests, plus 14 more escaped-backtick probes in bodies and payloads. The _MAIN_READING pass in _reaches_self_over_ssh is what refuses the eval form. Your body and your last reply say the same thing. The problem is that docs/system-specs/modules/security.md:1056-1058, the code comment at :1115-1116 and the body's "Escaped backticks" bullet all say this reading keeps the eval form refused. Someone who later retires the main-reading pass would believe the form is still covered, and it would not be. Meanwhile the reading threads an extra parameter through _bounded_ssh_reading, the _is_ssh_to_self signature and memo key, and _judge_ssh_to_self, and it is one of the sites behind the deferred sudo -H false refusal.
    • Smallest fix: delete the both re-read and its comment, and remove escapes_read from those three functions and the memo key. Keep _escaped, the escaped_too keyword (still used by _line_may_name_ssh_verb) and the "leave escaped spans unspliced" behaviour, which two rows need. Then change the spec sentence, the comment and the body bullet to credit the _MAIN_READING splice. Every goal row stays refused. I listed this as optional last round. It is required now because the security spec this PR adds states something the code does not do.

Earlier items, one by one:

  • Shared seen set for payloads and bodies (last review): fixed. seen is keyed by (text, judge), and the four twin forms are refuse rows.
  • Main-reading escape, a=x; payload shape and the merge-order line naming #35359: still fixed.
  • Items from the three earlier reviews: still fixed.
  • Test-file split (optional): declined with a reason that holds. The file is under the cap.

PR Readiness is also red on two rows: the false refusal deferred to #37632 and the DNS-pending row tracked in #37311. Both need a maintainer override on the final head. Neither needs a code change.

Optional:

  • The Tests section counts are stale. test_every_command_of_a_substitution_list_is_judged has 81 rows, 61 of which fail on main, and the allowed test has 44 rows. This is a body edit only.
  • echo $(sudo -H ls s* l*) is newly refused (fail closed, deferred to #37632), but no residual row pins it. A row next to the other known residuals would make the #37632 fix flip it on purpose.
  • echo $(echo hi; eval "ssh -p 22 \`printf localhost\`") is allowed on main and here, but #37638 does not list it yet. The same goes for the top-level eval "ssh -p 22 \`printf localhost\` id".

The ssh-to-self floor reads a static echo/printf substitution as its
first word, so a later command of a list inside it was never judged:
`echo $(echo hi; ssh -p 22 <this host> id)` and the `&&`, `||`, `|`,
newline, backtick, double-quoted, `bash -c` / `eval` payload and
heredoc forms got past the floor, although bash runs every command of
the body.

Main's floor stays as it is. A new module, argv_floor_ssh_bodies, adds
one check that can only refuse: each live `$( )` or backtick body,
found with the shared quote-aware readers, is judged as a command line
of its own, one nesting level at a time, and so are the bodies inside
each `bash -c` / `eval` payload. An escaped backtick span is judged
both as written and spliced, since one quoting level down it runs.

Based on #37037 by CrysisDeu.

Closes #36949

Co-authored-by: Zezhen Xu <32421101+CrysisDeu@users.noreply.github.com>
@buluoray

Copy link
Copy Markdown
Contributor Author

Thanks. Item 1 is fixed on f6ba2fb.

  1. Dead both re-read: removed, with its comment. escapes_read is gone from _bounded_ssh_reading, the _is_ssh_to_self signature and memo key, and _judge_ssh_to_self; those three now match main's signatures. _escaped, the escaped_too keyword (still read by _line_may_name_ssh_verb) and the unspliced handling of escaped spans stay. security.md, the code comment and the body's "Escaped backticks" bullet now credit the _MAIN_READING splice for keeping eval "ssh -p 22 \`printf localhost\`" refused. All rows keep their verdicts (1,403 related tests pass). argv_floor_ssh.py is 1,582 lines, and the line budget drops to +192.

Optional items:

prove.py PROVEN on f6ba2fb. The GPT (#37632) and Scope (#37311) rows still need a maintainer override on the final head.

@bolichen97 bolichen97 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.

Re-approving f6ba2fb899. The range-diff against aa6679b990 (which I approved) only removes the dead escapes_read re-read the Captain flagged, so _bounded_ssh_reading, _is_ssh_to_self and _judge_ssh_to_self match main's signatures again. No verdict changes. My maintainer request from #37616 (comment) is done. I checked it with is_denied on this head:

  • bash -c 'a=x; echo $(echo hi; ssh -p 22 localhost id)': refused (sandbox-escape-ssh-self), allowed before this push.
  • bash -c 'a=x; echo $(echo hi; echo ssh -p 22 localhost id)': still allowed.
  • echo $(echo hi; ssh -p 22 localhost id): refused.

The body now names #35359 in the merge order. test/test_denied_commands_security_ssh_self.py passes locally on this head (637 passed). The Captain's item on aa6679b990 is answered on this head, and the Captain will re-review it.

Sensitive change review

  • What rule changed: the ssh-to-self argv floor now judges every command of a ;/&&/|| list inside a $( ) or backtick substitution, including substitution bodies inside a quoted bash -c / assignment script, instead of only the first command of the substitution.
  • Before -> after: echo $(echo hi; ssh -p 22 localhost id) and its bash -c 'a=x; ...' form reached this host before and are refused now; an echo ssh ... that only prints the words stays allowed.
  • Worst case if wrong: an ordinary command whose substitution body mentions ssh to a local name is refused, which fails closed; the 6,048-command differential the Captain ran found no command that main refuses and this head allows.
  • Evidence checked: read the diff in argv_floor_ssh.py, argv_floor_ssh_bodies.py and shell_commands.py; probed the three commands above with is_denied on this head; ran the ssh-self suite (637 passed).
  • Tools still work: grep, sed and jq bodies, ssh-keygen, remote ssh and quoted-tag commit bodies stay allowed per the suite's allow rows.
  • Backward compatible: yes, the change only adds refusals for commands that reach this host; the documented known gaps stay pinned and tracked in #37638.
  • Existing tests: test_denied_commands_security_ssh_self.py, 637 passed on this head, with refuse and allow rows for each new term.
  • How to undo: revert this PR's commit; the floor goes back to judging only the first command of a substitution.

AI-assisted, sent by Bolin Review bot

@KiroCrewCaptain KiroCrewCaptain left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Approving f6ba2fb. On this head the review ran is_denied on trees extracted from this head and from the merge-base. Every Goal shape is refused: the ;, &&, ||, | and newline lists, the backtick and "$( )" forms, and the heredoc, bash -c and x=$(...) forms. The review also ran the ssh-self test file (637 passed) and the head's tests against merge-base source: 61 of the 81 list rows fail there. A 21-mutation pass reds tests for every new term except the two noted below.

Earlier change request, item by item: the dead escapes_read re-read is removed, and security.md, the code comment and the "Escaped backticks" bullet now credit the _MAIN_READING splice. Fixed.

Security: the new check is one more or on main's verdict, so it can only add refusals. A 1500-command differential fuzz found no command that main refuses and this head allows. The new refusals fail closed and name sandbox-escape-ssh-self. The ones that are known are tracked in #37632 and #37638.

Done well: the heredoc substitution scan now has one owner, shell_commands._heredoc_body_substitutions, so the ssh floor and read_commands cannot disagree. Character-count tests, not timers, pin that cost grows linearly.

The design is signed off under the standing maintainer sign-off for changes by team members.

Optional:

  • Two sibling sites judge a derived command line without the new body pass: argv_floor_ssh.py:821 (ProxyCommand/LocalCommand values) and :985 (function-bound bodies). Both main and this head allow ssh -o ProxyCommand='echo $(echo hi; ssh -p 22 localhost id)' remote.example.com and f(){ echo $(echo hi; ssh -p 22 "$1" id); }; f localhost. This is not a regression, but it is worth listing in #37638 with pinning rows.
  • argv_floor_ssh.py:178-180 leaves every escaped backtick span unspliced whatever its quote state, so quoted data such as git commit -m "fix: \echo hi` then ssh localhost"is newly refused. It fails closed but is not in the residual list. Taking the quote state from the shared walker would fix it. Theescaped_too=Trueknob atargv_floor_ssh_bodies.py:101` also reds no test when ignored.
  • Body text is stale in a few places: the Budget bullet still mentions escapes_read, 1,600 lines (now 1,582) and a body check in both readings (it runs once). The Tests section says "52 of these fail on main" (61 measured). The known fail-closed list omits echo $(sudo -H ls s* l*).

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.

sandbox-escape-ssh-self misses an ssh-to-self call after ; or && inside a command substitution

3 participants