Repository navigation
fix(security): judge every command of a substitution list for ssh-to-self - #37616
Conversation
Sensitive Change ReviewSensitive files changed:
|
UX Review (Opus 5.5) — ⏭️ skippedRevision |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of 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 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 |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of 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 shipsInventory (9 items) — 9 justifiedIntent: 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
[FIRST-PRINCIPLES-REVIEWED] f6ba2fb Description read[DESCRIPTION-READ] 4d5fd4b6f6ccb000d269d1bcbe7618654b724eb732ab3a6b469f3d3327e2402b That sha256 names the PR description this verdict read. Recompute it with |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
Security Scope Review -- ✅ PASSWhich legitimate operations does Verdict basis: adjudicated, zero confirmed regressions. Security scope review -- adjudicated candidates
No candidate flipped from allowed to refused. Scope-Verdict: PASS Reason: The ssh self-target floor now treats every TIGHTENING: the ssh self-target argv floor ( ADJUDICATED: 22 candidates, 0 confirmed newly-refused PLATFORM COVERAGE: posix (16 rows): the diff's own assumptions are bash-only (POSIX quoting, heredocs, UNADJUDICATED: Nothing in this tightening falls outside the shell classifier. One possible narrowing is argued but not confirmed. Path: [SCOPE-REVIEWED] f6ba2fb |
Code change approver recommendation: A person should decideWhy: 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 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 |
684aa8f to
93dd8e8
Compare
|
|
Security Scope on 684aa8f: the remote-host rows are not new refusals. All 10 rows name Read-only
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 |
93dd8e8 to
3229e2f
Compare
|
resolution: deferred #37632
|
|
|
|
|
|
|
Security Scope on 3229e2f: what the "newly refused" rows are. Remote-host rows ( Read-only
The 33-backtick-span row ending in The lane's own adjudication on the earlier head agreed on the remote rows: |
|
resolution: deferred #37638
|
|
resolution: deferred #37638
|
3229e2f to
b0f18ab
Compare
Human judgment recorded@buluoray recorded a pre-existing release (class
This decision applies only to this commit. A new push requires a new judgment. |
|
@buluoray two things are left on
Also please name #35359 in the merge-order line: it moves AI-assisted, sent by Bolin Review bot |
|
resolution: deferred #37638
|
|
resolution: deferred #37638
|
|
resolution: deferred #37638
|
|
/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. |
Sensitive change review
|
Human judgment recorded@buluoray recorded a pre-existing release (class
This decision applies only to this commit. A new push requires a new judgment. |
Human judgment recorded@buluoray recorded a deferred release (class
This decision applies only to this commit. A new push requires a new judgment. |
Human judgment recorded@buluoray recorded a pre-existing release (class
This decision applies only to this commit. A new push requires a new judgment. |
|
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:
What the review checked on this head:
Done well: the heredoc substitution scan now lives in one function, Optional:
|
|
@buluoray answering as the maintainer who asked in #37616 (comment): I don't accept deferring that shape. I checked
Also, please name #35359 in the merge-order line of the body (body edit only): it moves With those two done, this is ready from my side. AI-assisted, sent by Bolin Review bot on behalf of @bolichen97 |
KiroCrewCaptain
left a comment
There was a problem hiding this comment.
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.
-
security/argv_floor_ssh.py:179and:1118open 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 underbash -c, with ay=1;prefix, withecho localin place ofprintf local, with&&in place of;, and withs\`printf s\`has the verb. - Outcome:
is_deniedrefuses all six on the merge-base withsandbox-escape-ssh-selfand returns None on this head. We ran the first one in bash with ssh shadowed by a function, and it runsssh -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_substitutionsnow keeps escaped backtick spans even under_MAIN_READING. So the main-reading fallback in_reaches_self_over_sshno longer reads the line the way main did. Theescapes_readrecursion onboththen 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 asecho \`echo hi; echo ssh -p 22 localhost id\`andecho \`date\` \`whoami\`stay allowed. Add refuse rows for the six commands. Also correct the body sentence and the security.md text that call_MAIN_READINGmain's unchanged reading.
- Trigger:
-
security/argv_floor_ssh_bodies.py:160still allowsbash -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 thea=x;the same payload is refused. Thesh -cform, thea=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_selfon the whole line only. It never runs it on thescriptsthat 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 theecho sshtwin. The maintainer asked for exactly this change on this PR and declined the deferral. In a local copy, all 620 tests intest_denied_commands_security_ssh_self.pystay green with it. This change does not close item 1.
- Outcome: this is the ssh after
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 comparesstep.text. - The
a=x;payload shape: still stands, see item 2. - Merge-order line naming #35359: still stands. #35359 moves
_reaches_self_over_sshintoargv_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.
|
Thanks, both items are fixed on b834d85.
Also:
|
bolichen97
left a comment
There was a problem hiding this comment.
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 quotedbash -c/ assignment script, instead of only the first command of the substitution. - Before -> after:
echo $(echo hi; ssh -p 22 localhost id)and itsbash -c 'a=x; ...'form reached this host before and are refused now; anecho 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.pyandshell_commands.py; probed the three commands above withis_deniedon 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
|
resolution: deferred #37311
|
KiroCrewCaptain
left a comment
There was a problem hiding this comment.
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.
src/kiro_crew/security/argv_floor_ssh_bodies.py:134-144(_substitution_reaches_self) uses oneseenset 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 inseenand never gets judged.- Trigger:
echo $(echo hi; ssh -p 22 localhost id) bash -c 'echo hi; ssh -p 22 localhost id'. Thebash -c '...'here is only text that echo prints. The same thing happens withx=$(echo hi; ssh -p 22 localhost id) && echo eval 'echo hi; ssh -p 22 localhost id', with the backtick form plussh -c, and with the double-quoted"$( )"form. - Outcome:
is_deniedallows all of these on this head. Without the trailing word, the same command is refused assandbox-escape-ssh-self, and so is the same command withbash -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
seenby(text, judge)or use two sets. Work at most doubles, so the linearity tests still hold. Then add refuse rows for the trailingbash -c,evalandsh -ctwin forms.
- Trigger:
Earlier items, one by one:
- Main-reading escape at
argv_floor_ssh.py:179: fixed. The condition now checksnot _MAIN_READING.get(). a=x;payload shape atargv_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-1120never refuses anything. Theescaped_toosplice turns\`printf localhost\`into\localhost_. Deleting those lines turns no test red, and the rows the body names are refused by the_MAIN_READINGpass instead. Substitution bodies get no_MAIN_READINGpass, soecho $(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_selfitself 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.pygrows to 1,967 lines, 33 under the cap. Moving the substitution-body tests into a sibling module would leave room for the next row.
|
Thanks. Item 1 is fixed on aa6679b.
Body edits:
Not done in this PR:
|
bolichen97
left a comment
There was a problem hiding this comment.
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 quotedbash -c/ assignment script, instead of only the first command of the substitution. - Before -> after:
echo $(echo hi; ssh -p 22 localhost id)and itsbash -c 'a=x; ...'form reached this host before and are refused now; anecho 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.pyandshell_commands.py; probed the three commands above withis_deniedon 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
|
self-added: yes
|
|
resolution: deferred #37311
|
KiroCrewCaptain
left a comment
There was a problem hiding this comment.
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.
security/argv_floor_ssh.py:1117-1120(thebothre-read withescapes_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\`"orecho $(echo hi; eval "ssh -p 22 \`printf localhost\`"). Theescaped_toosplice 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_READINGpass in_reaches_self_over_sshis what refuses the eval form. Your body and your last reply say the same thing. The problem is thatdocs/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_selfsignature and memo key, and_judge_ssh_to_self, and it is one of the sites behind the deferredsudo -Hfalse refusal. - Smallest fix: delete the
bothre-read and its comment, and removeescapes_readfrom those three functions and the memo key. Keep_escaped, theescaped_tookeyword (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_READINGsplice. 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.
- Trigger: any line with an escaped backtick span, for example
Earlier items, one by one:
- Shared
seenset for payloads and bodies (last review): fixed.seenis 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_judgedhas 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-leveleval "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>
|
Thanks. Item 1 is fixed on f6ba2fb.
Optional items:
prove.py PROVEN on f6ba2fb. The GPT (#37632) and Scope (#37311) rows still need a maintainer override on the final head. |
bolichen97
left a comment
There was a problem hiding this comment.
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 quotedbash -c/ assignment script, instead of only the first command of the substitution. - Before -> after:
echo $(echo hi; ssh -p 22 localhost id)and itsbash -c 'a=x; ...'form reached this host before and are refused now; anecho 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.pyandshell_commands.py; probed the three commands above withis_deniedon 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
left a comment
There was a problem hiding this comment.
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 allowssh -o ProxyCommand='echo $(echo hi; ssh -p 22 localhost id)' remote.example.comandf(){ 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-180leaves every escaped backtick span unspliced whatever its quote state, so quoted data such asgit 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 omitsecho $(sudo -H ls s* l*).
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 anecho/printfcommand 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 formsecho `echo hi; ssh -p 22 localhost id`echo `date` `ssh -p 22 localhost id`echo "$(echo hi; ssh -p 22 localhost id)"#comment line, or inside an unquoted heredoc bodyThis 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
$( )reading that fix(security): read a double-quoted $( ) as a command in ssh floor #37443 added, or to the open follow-ups ssh-to-self floor allows a later ssh when a double-quoted $( ) holds a single-quoted " #37444, ssh-to-self floor allows an ssh after a heredoc inside a double-quoted backtick substitution #37494 and ssh-to-self floor refuses a PR body printed by cat -, cat -- or cat -n inside a double-quoted $( ) #37518.What changed (motivation → approach → change)
echo/printfsubstitution as its first command's output, so$(echo hi; ssh -p 22 localhost id)becomeshibefore the floor's walk runs, and thesshcommand is gone._is_ssh_to_selfleaves 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_sshrefuses if main's terms do, or if_substitution_reaches_selfdoes._live_substitutionsfinds each$( )and backtick body that bash runs. It reuses main's quote-aware readers (_matching_close_paren,_backtick_closer,_opens_comment, andread_commandsfor heredoc spans), so text in single quotes, comments and quoted-tag heredocs is never read as code._is_ssh_to_selfas 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.bash -c/sh -c/eval/ here-string payload, from main's_nested_shell_payloads, are judged the same way.echo \`echo hi; ssh -p 22 localhost id\`is no substitution, but its;is live, so the ssh runs._is_ssh_to_selfleaves an escaped backtick span unspliced on its own line (_splice_static_substitutions,_escaped), so the body check reads the live;. The_MAIN_READINGpass splices such a span, as main's splice did, and that keepseval "ssh -p 22 \`printf localhost\`"refused, because that span runs one quoting level down._may_name_ssh_verbis factored out of_is_ssh_to_self, and both modules call the one copy.$( )and backtick in an unquoted heredoc body moves out ofshell_commands._body_substitutionsintoshell_commands._heredoc_body_substitutions, which returns spans._body_substitutionsand the new module both read it, so the ssh floor andread_commandscannot disagree about which heredoc bodies bash runs.test_heredoc_bodies_come_from_the_reader_scanpins it.argv_floor.pylists the new owner module and serves the new names. Every name main serves is still served.test/security_line_budget/ssh-self-subst-list.txtis+192(lines added minus removed undersrc/kiro_crew/security/, against main). The MCP listing module ceilings intest/test_mcp_listing_import_budget.pygo up by 1 more formcp-core,mcp-cron,mcp-guideandmcp-mate, because the deny floor that every listing loads now imports the new module.argv_floor_ssh.pyis 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_selfforward itsescapes_readflag._reaches_self_over_sshkeeps 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.docs/system-specs/modules/security.mddescribes the new module and its residuals.Backwards compatibility
Breaking: a command whose live
$( )or backtick body, or whosebash -c/evalpayload body, runs ssh to this host is now refused withsandbox-escape-ssh-self, where main allowed it. Nothing main refuses becomes allowed: the new check is one moreoron 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 byargv_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:
echo $(echo hi ;echo ssh …),echo $(echo a # ; ssh …+ newline +), an unquoted-tagcat <<EOFbody in a list, andecho `echo\;echo ssh …`. They are pinned bytest_known_fail_closed_residuals_are_refusedand listed in ssh-to-self floor: substitution gaps left by the list fix, and a backtick-cap false refusal #37638.echo bash -c 'echo $(echo hi; ssh …)'(ssh-to-self floor refuses a quoted literal whose backtick span is over the size cap #37632).Removes nothing:
_reaches_self_over_sshmoves to the new module and stays served byargv_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/evallists,s$()sh, double-quoted bodies, unquoted heredoc backticks,\$$(, escaped backticks, a heredoc fed tobash, a quoted), a#glued after a closer as in$(date)#$(…), an escaped\#before a substitution,s$(printf s)hin abash -c/evalpayload), andbash -c 'ssh -p 22 $(printf localhost) id'with itseval,sh -candbash <<<forms. 52 of these fail on main.test_live_nested_substitution_payload_is_judged(3 rows, all failed on main) andtest_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) andtest_literal_nested_substitution_payload_stays_allowed(4 rows): quoted text, comments (including$(date) #$(…)and$(date); #$(…)), quoted-tag heredocs,echo sshas data, remote hosts,$$(,\$(, padded bodies, a 2.5 KB markdowngh pr createbody that namesrsync, 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._MAIN_READINGsplice 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.test_denied_commands_security_ssh_self.py(637 tests), plustest_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.pyandtest_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_sshintoargv_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
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)Contribution License Agreement
Contributions are accepted under the project's Apache-2.0 license; see the Licensing section of CONTRIBUTING.md.