Repository navigation
fix(security): read a multi-line script a shell runs in the ssh-to-self floor - #35359
jeeshofone wants to merge 1 commit into
Conversation
GPT 6.1 Review (fork) — 🔴 changes requested (blocking)Reviewed 1 of 2 blocking finding(s) are security-class and were withheld from adjudication, so the blocking verdict stands. BLOCKING -- src/kiro_crew/security/argv_floor_ssh_bodies.py:466 -- The literal exemption discards a script executed by a later command BLOCKING -- src/kiro_crew/security/argv_floor_ssh_bodies.py:526 -- Descended frames mistake quoted heredoc data for executable commands [BLOCK-MERGE] f9d443d Adjudication (Opus 5.5) — is blocking on each finding proportionate?F2 is a false denial that the PR records on purpose. F1 is a real bypass that can happen in ordinary use, so it keeps blocking. F2 — harm LOW. The failure needs a quoted heredoc body that is only printed, nested under a The real fix would mean carrying execution-sink context through every level of descent. The PR's own notes say five versions of a cut inside descended frames each leaked a body a shell runs, and pin those spellings as DENY (patch :2154-2228). That is a security-path mechanism whose cost is far above a loud, recoverable false denial. F1 (fenced) — the top-level cut does apply here. |
Code change approver recommendation: A person should decideWhy: the decider raised 1 possible problem and estimates a 62% chance that this change introduces a defect; a person should check it. I'm requesting changes. The new walk fixes the multi-line Things to check (possible problems the decider raised; at this confidence many turn out to be fine):
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 |
Opus 5.5 Review (fork) — 🔴 changes requested (blocking)Reviewed BLOCKING: two cost ratchets were loosened so the added second ssh-self leg would fit. Each was rewritten so the extra work it used to refuse now passes. BLOCKING — test/test_ssh_self_descent_cost.py:95 BLOCKING — test/test_deny_gate_call_sharing.py:172 |
Security Scope Review (fork) — ✅ PASSWhich legitimate operations does adjudicated, zero confirmed regressions Scope-Verdict: PASS Reason: The tightening sits entirely inside the shell-command deny composite (the TIGHTENING: The ssh-to-self floor gains a second leg, ADJUDICATED: 23 candidates, 0 confirmed newly-refused PLATFORM COVERAGE: posix and windows. No row is
I wrote no row for cmd.exe UNADJUDICATED: These are not separate guards; each sits inside the adjudicated floor. They are things the rows could not carry or that I chose not to submit:
[SCOPE-REVIEWED] f9d443dSecurity scope review -- adjudicated candidates
No candidate flipped from allowed to refused. |
ee416cf to
387b32b
Compare
Design Review (Opus 5.5, fork) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks: the subject is a real shell command line, the scanner only adds refusals beside the base reading it leaves unchanged, and a crash fails closed. Notes
[DESIGN-REVIEWED] f9d443d Description read[DESCRIPTION-READ] 2979a7943280f45328b273e581be56a9bf95b260d827cf0cb40d25ffe37aab24 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, fork) — 🔴 BLOCKPremise-level review of First-Principles-Verdict: BLOCK The diff adds a third nested-payload descent for the ssh-self floor, with its own continuation fold, its own process-substitution reader and a new tokenizer mode. Not checked: whether Notes
What this change shipsInventory (9 items) — 3 justifiedIntent: refuse a self-ssh on any line of a script a shell runs, not only the first. FIX.
BlockersThird payload descent beside the shared walker — duplicate of shell_normalizer.py [FIRST-PRINCIPLES-REVIEWED] f9d443d Description read[DESCRIPTION-READ] 607ccfd4c55ed424083fdbc4e3643f858773481c2b38757cf58adb2377618423 That sha256 names the PR description this verdict read. Recompute it with |
UX Review (Opus 5.5, fork) — ⏭️ skippedRevision |
387b32b to
803d5ef
Compare
|
Replies to the review lanes on 387b32b. New head: 803d5ef. GPT 6.1, F2 (single-quoted backticks that a printer only prints): fixed. The new walk no longer looks for command substitutions inside single-quoted text, since bash runs none there. It reads quoting through the shared GPT 6.1, F1 ( Opus 5.5 (a Security Scope Review ( |
803d5ef to
021d131
Compare
|
Replies to the GPT 6.1 findings on 803d5ef. New head: 021d131. F1 (a F2 (backticks inside ANSI-C This head also adds the three new |
|
Re-integrated onto current Local review lanes, rounds 22 through 25, all closed:
Final verdicts on the pushed tree: both review lanes no findings; the full targeted security suite green; the bug-reproduction proof holds (the pins fail with the production hunks reverted); the dependency scanner clean. |
|
Updated the empty-quote handling to split by caller, not grammar, which closes the
Evidence on the current head:
|
Update — head
|
Update — head
|
Fork GPT 6.1 lane — the
|
Update — head
|
|
Addressed by construction, one point at a time:
The subtraction exposed a cost the separate module had hidden from the counters: the two legs tokenize the same text in two modes that cannot share a read, so per-check work is about 2x a single leg's and the two scan-linearity bounds move from 3x to 5x, while a new flatness pin holds the order (≤ 2.2x work per input doubling, reddened by a re-read-per-frame quadratic) independently of that constant — the PR body's "Cost" section carries the main-vs-head table. |
|
The three
Pinned by |
|
Replying to the First Principles Review lane (comment 6811514064). We ran your subtraction (judge the base loop's nested payloads, drop the
The single loop has no fold, so it misses the process-substitution and comment-continuation rows and reads a commented-out Items 3 and 5 by your subtraction rule: the |
|
Replying to the Security Scope Review lane (comment 6801476463). The ubuntu row
Base and head give the same top-level verdict; head's nested REFUSE equals its own top-level REFUSE (a later line is judged as the first line). The over-refusal of a non-local IP literal while the kernel address list is unpublished is main's own fail-closed posture; the main-side issue #39797 covers it. Pinned by |
|
Replying to the GPT 6.1 Review lane (comment 6801159807). Fixed. The scanner leg's pre-fold verb prefilter is removed in
The unnested top-level spelling is main's own whole-line path (it folds nothing there); left untouched and recorded in "Not covered", with the main-side issue #39797. Pins: |
|
Replying to the SAST (Semgrep) check finding Fixed. In |
|
The scanner-leg verb prefilter is restored, in widened form: it short-circuits only a line that names no ssh verb and carries no |
|
Replying to the GPT 6.1 Review lane (comment 6801159807), now on head f132752. Fixed. A here-document or here-string a shell only hands to a NON-shell consumer — The exemption fires only when, after the fold, the whole line is a plain command list: every command head is an ordinary word — not a compound keyword ( Allowed now (printed data, 6 ALLOW pins —
Still refused — a shell runs the body, or the consumer's output can still reach a shell (7 shell-consumer REFUSE pins + 10 grouped/piped/compound/process-sub REFUSE pins): Differential vs the merge-base is unchanged at 0 new ALLOW / +117 new DENY; against the prior pushed head this revision un-refuses exactly these six literal-data rows and adds no refusal. Pins: |
|
Replying to the Opus 5.5 Review lane ( This bound is a maintainer decision, and we ask for no override — here is the measured ground so you can make it. origin/main bounds its single descent leg at We did not loosen main's bound to the combined work. Each leg is bounded on its own: main's We also measured the alternative your rule implies — one whole-floor counter over the gate-level That is the tension, stated plainly for you:
The two readings point opposite ways; both are laid out in the PR body under "Cost", with the 4.00× / 6.94× / per-leg / flatness numbers and the branch that measured each. We have taken the path that keeps every leg at main's own 3× and keeps the second leg First Principles requires; whether that reads as a ratchet loosening or as required duplication is yours to call. Pins: |
|
Replying to the Security Scope Review lane (comment 6801476463), now on head f132752. The rows that flip base ALLOW → head REFUSE on a runner are branch A: a later line judged exactly as the first line, at main's own host posture — not a new rule. The
The crontab row In both rows base and head give the same top-level verdict, and head's nested REFUSE equals its own top-level REFUSE: a later line is judged as the first line. The over-refusal of a non-local IP literal / unresolved host while the kernel address list is unpublished is main's own fail-closed posture; the main-side issue #39797 covers it. Pins: |
|
Replying to the First Principles Review lane (comment 6811514064), now on head f132752. We ran your subtraction (judge the base loop's nested payloads, drop the
The single loop has no fold, so it misses the process-substitution and comment-continuation rows and reads a commented-out On the two consumers your subtraction rule asks about: the |
|
Replying to the First Principles Review lane (comment 6811514064) on head f132752. We ran your subtraction and measured it, rather than argue it. On a scratch branch off Half of the premise is true, half is not. The subtraction loses no
Rows r36 refuses and the subtraction does not (main=ALLOW · r36=DENY · subtraction=ALLOW)A self-ssh the fold scanner reaches but
(15 rows from the pin suite; the corpus, which samples these adversarial shapes only partly, independently shows 3 such losses — a comment-fold row, a Rows r36 allows and the subtraction refuses (main=ALLOW · r36=ALLOW · subtraction=DENY)Printed data read as a script — a new over-refusal, below both main and r36:
(4 rows from the pin suite; over the corpus this class is 54 over-refusals vs r36, including a benign commented-out Why
|
The ssh-to-self floor now descends into the payload of a shell that runs a
script and judges each line as its own command, so a self-ssh on any line but
the first of a bare or nested multi-line `bash -c '...'` / `sh -c` / `$SHELL -c`
/ `env -S` body -- or on a line a `;` `&` `|` separator hid from the whole-line
read -- is refused, not just the first command. The descent folds each frame's
own line continuations first, reads nested `-c` operands through exec wrappers
and value-taking options, reads single-quoted eval bodies and heredoc /
here-string / process-substitution payloads (including a `<(` opener reached past
a `\`-newline), and is bounded by the pre-existing per-frame `seen` set.
To reach a self-ssh three or more `bash -c` levels deep, the descent needs the
tokenizer to keep a nested script's structural quotes; every other floor needs
the opposite -- the canonical command SHAPE with inert empty-quote pairs dropped,
or a `rm -rf /` respelt `rm ''-rf /` slips the `rm -rf /.*` rule. Rather than a
second tokenizer or a raw-operand reader, `_shell_tokens` takes one mode flag:
* DEFAULT (`preserve_structure=False`) drops every empty-quote pair from each
dequoted token unconditionally (`_EMPTY_QUOTE_RE`), byte-identical to the base
ref. Every existing caller keeps this, so the deny view, the rm floor and the
git floor are unchanged (a 32k-row full-verdict differential against base loses
zero denials; the only changes are the intended ssh-self tightenings).
* `preserve_structure=True` runs an escape-aware collapse
(`_drop_empty_quote_pairs` before tokenizing, `_drop_token_empty_pairs` on each
dequoted token): it still folds a respelt verb (`s\"\"sh` -> ssh, `rm\"\"` ->
rm, `rm'""'` -> rm) but leaves a nested script's structural closing quotes (an
escaped pair beside another quote) intact. Both passes match each maximal run of
pairs once with no trailing look-around, so the scan is linear, not the O(n^2)
a greedy `(?:"")+(?=\w)` would cost on a long pair run through the deny gate.
Exactly one caller passes the flag: the ssh-self fold scanner
(`argv_floor_ssh_bodies._folded_scanner_reaches_self`), through `_self_tokens` and
`normalize_shell_command`, which forward it. `_shell_tokens` keys its own per-call
memo on the `(cmd, preserve_structure)` pair, so the two modes cache apart while
`once_per_call` stays the single-argument base reader every other floor marks --
no change to the shared memo helper and no per-read signature bind on the deny-gate
hot path.
## Backwards compatibility
Reader: every caller of `_shell_tokens` keeps base's unconditional empty-pair
elision (DEFAULT mode); only the ssh-self descent opts into structure-preserving
mode, and it is the only behaviour change. By caller:
- deny_gate `_deny_segment_views` (deny-matching views): DEFAULT -- needs the
canonical command shape so a respelt verb still matches its rule.
- rm_floor (rm -rf floors): DEFAULT -- matches command shape; unchanged from base.
- argv_rules `_commands` / shell_commands / s3_direction / inline_payload
(git-publish, s3, nested-command readers): DEFAULT -- unchanged from base.
- acp.batch_guard, dashboard.usage_outcome (tool-prefix readers): DEFAULT --
unchanged from base.
- normalize_shell_command: forwards the flag; DEFAULT for its own callers (the
git-publish floor), structure-preserving only when `_self_tokens` passes it.
- argv_floor_ssh_bodies ssh-self descent: preserve_structure=True -- reads a
self-ssh buried in a deep `bash -c "..."` without truncating the payload.
Because the ssh-self descent tokenizes in preserve_structure mode, a command
reached by both it and the default floors is split once in EACH mode within a
gate call; the per-call memo serves every repeat, so no text is tokenized twice
in one mode, pinned by test_deny_gate_call_sharing.py.
The descent folds line continuations in one heredoc-aware pass
(`_fold_outside_quoted_heredocs`): bash folds a backslash-newline while lexing --
so a split `<<` / `<<-`, or a command word split before one, is seen whole -- and
only then delimits a heredoc body, which for a quoted tag (`<<'EOF'`) it keeps
literal. Folding a quoted body would merge its trailing backslash into the
terminator and blank a substitution the shell runs after it, hiding a self-ssh;
recognising the operator on the folded stream closes that for a split operator
too. A context stack tracks where a `<<` is a heredoc -- at top level, in a
`$( )` / backtick substitution or `( )` subshell, including one reopened inside
double quotes -- and where it is not: in single quotes, directly in double quotes,
after a `#` comment, or in `$(( ))` / `${ }`. The delimiter is read as its own
word, so the scan stays linear in the number of operators. And the descent admits
each distinct executed-script payload once, updating the seen set as each is
admitted, so a run of identical payloads (`bash bash ... -c '...'`) is read once
rather than re-tokenized per copy.
## Fail-closed belt (by construction)
The fold above changes the command SHAPE the scanner reads, and a fold bug can
only ever LOSE a refusal origin/main already makes (a spelling main refuses on
the unfolded stream, folded into one the scanner then clears). To make that class
of bug non-exploitable rather than chase each spelling, the floor keeps
origin/main's own substitution reading (`_substitution_reaches_self`) byte-for-byte
unedited and runs it as one leg of `_reaches_self_over_ssh`, beside the new
folding, script-descending scanner (`_folded_scanner_reaches_self`). `git diff
origin/main` shows no hunk in `_substitution_reaches_self`, and a drift pin asserts
its source stays identical to the base ref. The gate refuses if EITHER leg refuses,
so the scanner adds refusals the base reading cannot make (a self-ssh on a later
line of a `bash -c` script, the feature main lacks) while the base reading
guarantees no spelling main refuses is lost to what a fold does to the shape.
There is no separate snapshot module: the belt is the base function left un-forked,
so nothing new joins the facade-owner family or any MCP server's startup import
graph. The cost is one extra linear descent over the same text, in a second
tokenizer mode. A shared-tokenizer memo keyed by `(text, mode)` with a construct
pre-check (`_modes_may_diverge`) lets the scanner reuse the default-mode tokens
whenever a command carries no empty-quote pair (the only construct on which the
modes differ), so the two legs split such a command once, not twice; an identity
pin proves the shared tokens equal the unshared over the 32k corpus in both modes,
with a mutant that shares a divergent command reddening it. The remaining second
leg still reads its own frames, so the floor's total work is up to about twice
origin/main's single-leg cost. Rather than loosen main's `chars <= 3x` ratchet to
the combined work, each leg is bounded on its own: origin/main's 3x is kept VERBATIM
on its own leg (the substitution reading) and the same 3x is applied to the fold
scanner leg; a flatness pin holds the ORDER at most 2.2x work per input doubling,
independent of the constant, and per-leg counters show the ~2.0x-each split. (The
`a-ratchet-may-only-tighten` lane would block loosening the one bound to 5x of the
combined work; First Principles' clears-when demands the separate leg, which is the
~2x total. The two readings are laid out in the PR body for the maintainers.) A
32k-row full-verdict differential against origin/main adds zero ALLOW (head refuses
a strict superset: +117 self-ssh rows) and drops none. Two mutant pins hold the
design: forcing the scanner leg off lets a later-line `bash -c` self-ssh through,
and forcing the base leg off lets a split-heredoc glued terminator through.
## Fail closed when the reader raises (S1)
The ssh-self reading hand-folds and descends a script. Its deny-gate call is
wrapped exactly as the rm floor wraps its own reader right below it: catch
Exception (incl. RecursionError), log once, and DENY a command that could name an
ssh verb (guarded by `_cannot_name_ssh_verb`). An exception in the fold or the
descent denies, never propagates out of `is_denied` and skips the floor.
## Comments do not hide a later-line self-ssh (G1/G2)
`_fold_outside_quoted_heredocs` drops a live comment's text (keeping its newline)
instead of copying it, and treats `#` after a word-ending `)` (a subshell close or
a `case` pattern, but not a `$( )` close, which is a glued word) as a comment. So a
`\`-newline inside a comment can no longer fold a self-ssh on the next line into
the comment and hide it (`bash -c '# x\`+newline+`ssh <self> id'`, and the same
after `(true)#c\`). origin/main allows these too, so no refusal is lost.
## Continuation-split verb on a later line
A verb split across a `\`-newline on a later line of a shell-run script
(`bash -c 'true`+newline+`/usr/bin/s?\`+newline+`h localhost id'`) folds to `s?h`
and must be refused. The scanner leg's old verb prefilter ran on the UNFOLDED line
and short-circuited before the fold rejoined the verb; running the prefilter on the
fold's output does not help, because the quote-aware fold does not fold inside the
outer `bash -c '...'`. So the prefilter is WIDENED, not dropped: it short-circuits
only a line that names no ssh verb AND carries no `\`-newline continuation -- a
backslash-newline being the one way bash splits a word across lines, so any line
that could fold into a verb is admitted to the descent, while a verb-free,
continuation-free data-consumer argv is not descended. Dropping the prefilter
entirely (an earlier revision of this change) descended every command, so a
payload-heavy argv re-ran the per-frame descent once per nested payload and the
argv sweep went quadratic in the payload count; the widened prefilter restores that
linearity (the data-consumer sweep pin in test_denied_commands_security_cost.py)
without reopening the split-verb hole -- held by a counter pin that a verb-free,
continuation-free argv is not descended while a mutant widening the prefilter to
always-descend reddens it. The verb gate sees through quote and backslash splices
(`ss""h`, `s\sh`), so a quote-split verb is admitted to the descent too. The base
leg keeps its own prefilter. The per-call memo bounds each (text, mode) to one
split -- the preserve_structure descent runs only on a command that can name an ssh
verb after folding, corrected in test_deny_gate_call_sharing.py -- and the flatness
and per-leg cost pins hold. The unnested top-level split verb is main's own
whole-line path, which folds nothing, and is left untouched (recorded here).
## A non-shell consumer's literal body is not a script
The fold scanner descends every executed-script payload, but a here-document or
here-string a shell only hands to a NON-shell consumer is DATA, not a script: `cat`
/ `tee` / `echo` / `printf`, or `git commit` reading its message from stdin
(`-F -` / `--file=-`), print or write it and run nothing. `_scanner_cut_nonshell_literals`
(scanner leg only, never the belt or the shared `_without_quoted_heredoc_text`) drops
such a body -- a QUOTED-tag here-document (`<<'EOF'` / `<<"EOF"` / `<<\EOF`, in which a
shell expands nothing) or a SINGLE-QUOTED here-string (`<<<'...'`) -- before payload
discovery, but only under a POSITIVE plain-command-list rule, so a consumer whose output
could still reach a shell keeps its body.
The exemption fires only when, after the fold, the whole line is a plain command list:
every command head is an ordinary word -- not a compound keyword (`{` `}` `if` `then`
`elif` `else` `fi` `for` `while` `until` `do` `done` `case` `esac` `coproc` `function`
`select` `time` `!`) and not a function definition (no `argv[0]` ending in `()`) -- no
separator is a pipe (`|` / `|&`), and no `>(` / `<(` process substitution appears on the
line. The head-check reads `argv[0]` only, so a compound word as a mere ARGUMENT
(`echo done`) still allows the line. Within such a line it cuts only a TERMINAL consumer
(its own separator ends the command: end-of-line / `;` / `&&` / `||`) at frame depth 0,
never inside a `( )` subshell or a `$( )` / backtick substitution. It reads top-level
commands only (`read_commands(nested=False)`), so a `cat` inside a `$( )` that feeds a
shell is left to the substitution reader. Everything the rule excludes keeps its body and
stays refused exactly as the pre-exclusion head refused it: a body a shell runs
(`bash <<'EOF'`, `cat <<'EOF' | bash`, `bash <<<'...'`, `$(cat <<EOF)` into a shell), an
UNQUOTED here-document whose `$(...)` runs, a grouped or piped consumer, a `{ }` group or
`if`/`while`/`for`/`case` compound or function body or `coproc`, and a `tee >(bash)` /
`cat > >(bash)` writing to a process substitution.
Six printed-data shapes are ALLOW pins and seven shell-consumer shapes REFUSE pins; a
further ten grouped / piped / compound / process-sub shapes are REFUSE pins asserting the
positive rule loses no head-added refusal. A strip-all mutant (cut every body, shell-consumer
ones included) reddens the REFUSE pins, a strip-none mutant reddens the ALLOW pins, and a
cut-even-inside-groups mutant (the loose pre-tightening shape, no plain-command-list guard)
reddens the grouped/piped REFUSE pins. Because the rule only REMOVES text the scanner would
otherwise descend, it lowers only head-added refusals and never takes the floor below
origin/main's belt reading.
## A later line reaches origin/main's own host posture
A crontab schedule written through an unquoted `cat <<EOF | crontab -` heredoc
(`bash -c 'cat <<EOF | crontab -\n0 3 * * 0 /usr/local/bin/backup.sh\nEOF'`) names no
ssh verb, yet `_is_ssh_to_self` refuses it: origin/main reads the `*` as a glob that
could name an ssh verb and `backup.sh` as a dotted host whose DNS is unresolved, and
fails closed. origin/main refuses the SAME line at top level
(`0 3 * * 0 /usr/local/bin/backup.sh`); the descent only reaches it on a later line.
A pin asserts the nested verdict equals the top-level one, so this is main's own
posture reaching a nested line, not a refusal this change introduces.
## Single loop vs two legs
First Principles asked whether the two legs could collapse into one (judge the base
loop's nested payloads and drop its `if live` guard, deleting the fold scanner). The
subtraction was run on a scratch branch and measured over the 32,576-row corpus and
the r19-r33 pins: the single loop cannot refuse 7 rows this head refuses (six
process-substitution self-ssh, one comment-fold) and over-refuses one benign
commented-out ssh. The fold scanner is a distinct leg that does real work, so it is
kept.
The literal cut is top-level only: it runs on the top-level line and never in a frame the
descent reaches, so a cat/tee/git commit -F - whose quoted literal body is reached by
descent (inside a bash -c) is read as a script, and a nested printed self-ssh is
refused where main allows it. This is a deliberate safe false-deny: five versions of a
by-descent cut each leaked under independent review (piped or redirected carrier, an
enclosing runner, glued/fd/quoted/./ path spellings, an earlier exec, & or trap sibling).
Each leak spelling is pinned DENY, and the over-refused rows are pinned as documented.
The ssh-bodies owner's forwarded names (_COMPOUND_HEADS, _NONSHELL_CONSUMER_HEADS,
_is_nonshell_consumer, _scanner_cut_nonshell_literals, _steps_expand_nothing) are listed in
the argv_floor TYPE_CHECKING manifest, and the descent-cost pin patches the shared
_is_ssh_to_self through the facade, as the facade mirror guards require.
Fixes kirodotdev#35314
Re-homed onto dcc3121.
|
Re GPT lane (comment 6801159807), F2 (nested printed literal over-refused): retained as a safe false-deny on r37 (f9d443d). Five versions of a by-descent literal cut were built to clear this, and each one leaked under independent Opus review: a piped or redirected carrier ( The over-refused rows (base ALLOW, this head REFUSE), pinned as
These are the lane's clears-when: they clear when a nested cut is proposed that also refuses every leak-spelling row. They are false denies inside the 0-new-ALLOW bar (differential vs base: 0 newly allowed). No override is requested. The local GPT lane last ran on 4d3a82a (before the top-level-only change); the fresh fork lane on this push reviews the final shape. |
|
Replying to the First Principles lane (comment 6811514064), head f9d443d. The lane's clears-when is "the floor judges the frames of
The subtraction becomes right if |
|
Replying to the GPT 6.1 lane (comment 6801159807), head f9d443d.
No override is requested. |
|
Replying to the Opus 5.5 lane ( These are the same two cost-bound findings raised on r36, answered in reply 7039229442. The PR body's "Cost" section gives the measured ground: each leg is held at main's own 3× bound, the combined work is about 2× main's, and the lane's suggested whole-floor memo-deduped counter measures 6.94× the input. Whether that reads as a ratchet loosening or as the second leg First Principles required is for the maintainers to decide between the two lanes' readings. No override is requested. |
Problem / Motivation
Goal: The ssh-to-self floor refuses a self connection on a later line of a script that
bash -c,sh -c,$SHELL -c,env -Sorevalruns, as it already does on the first line.On main,
bash -c 'true+ newline +s?h localhost id'is allowed whiles?h localhost idalone is refused: a self-ssh hidden on line 2+ of a shell-run script, or on a line a;&|separator hides from the whole-line read, slips the floor.Why it matters
A script that
bash -cruns is a common shape for agents. A self connection on any of its lines reaches the unsandboxed sshd on this host — a sandbox escape.Not a goal
s?h local*glob shapes in ssh-to-self floor misses a glob verb in a heredoc that a group, subshell or substitution runs #35314: allowed on main by design and changed by fix(security): keep self-host detection when the ssh verb is a glob #34056; untouched here.eval'd and a nominally remote host can be a self alias.What changed (motivation → approach → change)
-cbody and the whole-line view, so a self-ssh on a later line, or behind a;&|separator, was never read.argv_floor_ssh_bodies.py— a new folding, script-descending scanner (_folded_scanner_reaches_self) judges every executed-script payload, at the floor's own fail-closed DNS posture, so a self-ssh on a later line of a bare or nestedbash -c/sh -c/$SHELL -c/env -Sbody — or after a;&|— is refused. It also reads<( )/>( )process-substitution bodies, including a<+\-newline+(spelling, and folds each frame's line continuations first. Before it descends,_scanner_cut_nonshell_literalsdrops the literal body a NON-shell consumer only prints or writes (a quoted-tag here-document or single-quoted here-string ofcat/tee/echo/printforgit commit -F -), under a positive plain-command-list rule, so printed DATA is not mistaken for a script (see "A non-shell consumer's literal body is not a script"). origin/main's own substitution reading (_substitution_reaches_self) is left byte-for-byte unedited and runs beside it as the fail-closed belt (see below).shell_normalizer.py—_shell_tokenstakes one mode flag,preserve_structure, and keys its own per-call memo on the(cmd, preserve_structure)pair (so the two modes cache apart whileonce_per_callstays the single-argument base reader every other floor marks). DEFAULT drops every empty-quote pair unconditionally (_EMPTY_QUOTE_RE), byte-identical to the base ref, so every existing caller is unchanged.preserve_structure=Trueruns an escape-aware collapse, used by exactly one caller — the ssh-self fold scanner — to reach a self-ssh buried three or morebash -clevels deep without the default elision truncating the payload. A construct pre-check (_modes_may_diverge) lets the scanner reuse the default-mode tokens whenever a command carries no quote (the only construct on which the two modes differ). Both collapse passes are linear.deny_gate.py— the ssh-self reading's call is wrapped fail-closed (_SSH_SELF_UNREAD_NOTE), exactly as thermfloor wraps its own reader right below it: a crash in the fold, the literal cut, or the descent logs once and DENIES a command that could name an ssh verb (guarded by_cannot_name_ssh_verb), never propagating out ofis_denied(S1).argv_floor.pyre-exports the two leg names and the descent entry (TYPE_CHECKINGmanifest only).Why two readings (fail-closed belt, by construction)
The scanner folds line continuations before it scans, which changes the command shape it reads. A bug in that fold, or in the literal cut, can only ever lose a refusal origin/main already makes (a spelling main refuses on the unfolded stream, folded or cut into one the scanner then clears). Rather than chase each such spelling, the floor keeps origin/main's own reading as a second, independent leg:
_substitution_reaches_self's own source is left byte-for-byte unedited —git diff origin/mainshows no hunk in that function and a drift pin asserts it stays identical to the base ref — so it does no line-continuation fold and takes no literal cut ahead of its scan. One shared helper it calls,_live_substitutions, does gain<(/>(recognition (the process-substitution reading the "Rows the single loop cannot refuse" rows need); that change is additive — every refusal the base reading made it still makes, and the 32k-row differential loses none. "Byte-for-byte" therefore names the function's own body, not the whole call graph: the belt leg reads uncut, unfolded text, which is what makes it a belt. There is no separate snapshot module; the belt is the base function un-forked, so nothing new joins the facade-owner family or any MCP server's startup import graph._reaches_self_over_sshrefuses if either the folding, script-descending scanner (_folded_scanner_reaches_self) or this base reading refuses.So the scanner adds the refusals origin/main lacks (a self-ssh on a later line of a
bash -cscript), and the base reading guarantees no spelling origin/main already refuses can be lost to what a fold or a cut does to the shape. Two mutant pins hold the design: forcing the scanner leg off lets a later-linebash -cself-ssh through, and forcing the base leg off lets a split-heredoc glued terminator through. A full-verdict differential over 32,576 rows shows head refuses a strict superset of origin/main: 0 new ALLOW, +117 rows refused (head ⊇ base; later-line / process-substitution / continuation-split-verb self-ssh; an 18-row self-host DNS flaky set excluded).A non-shell consumer's literal body is not a script
The fold scanner descends every executed-script payload, but a here-document or here-string a shell only hands to a NON-shell consumer is DATA, not a script:
cat/tee/echo/printf, orgit commitreading its message from stdin (-F -/--file=-), print or write it and run nothing. An earlier revision descended such a body too and over-refused a self-ssh quoted inside printed data — the GPT pre-push lane flagged it._scanner_cut_nonshell_literals(scanner leg only, never the belt) now drops that body before payload discovery, under a positive plain-command-list rule:The exemption fires only when, after the fold, the whole line is a plain command list: every command head is an ordinary word — not a compound keyword (
{}ifthenelifelsefiforwhileuntildodonecaseesaccoprocfunctionselecttime!) and not a function definition (noargv[0]ending in()) — no separator is a pipe (|/|&), and no>(/<(process substitution appears on the line. The head-check readsargv[0]only, so a compound word as a mere ARGUMENT (echo done) still allows the line. Within such a line it cuts only a TERMINAL consumer (its own separator ends the command: end-of-line /;/&&/||) at frame depth 0, never inside a( )subshell or a$( )/ backtick substitution, and reads top-level commands only (read_commands(nested=False)), so acatinside a$( )that feeds a shell is left to the substitution reader.Everything the rule excludes keeps its body and stays refused exactly as the pre-exclusion head refused it: a body a shell runs (
bash <<'EOF',cat <<'EOF' | bash,bash <<<'...',$(cat <<EOF)into a shell), an UNQUOTED here-document whose$(...)runs, a grouped or piped consumer, a{ }group orif/while/for/casecompound or function body orcoproc, and atee >(bash)/cat > >(bash)writing to a process substitution.Pins: six printed-data shapes are ALLOW pins and seven shell-consumer shapes REFUSE pins; a further ten grouped / piped / compound / process-sub shapes are REFUSE pins asserting the positive rule loses no head-added refusal. A strip-all mutant (cut every body, shell-consumer ones included) reddens the REFUSE pins, a strip-none mutant reddens the ALLOW pins, and a cut-even-inside-groups mutant (the loose pre-tightening shape, no plain-command-list guard) reddens the grouped/piped REFUSE pins. Because the rule only REMOVES text the scanner would otherwise descend — and the belt leg reads the uncut text — it lowers only head-added refusals and never takes the floor below origin/main's belt reading; a crash inside it denies via the S1 wrap. The cut is top-level only: it runs on the top-level line and never in a frame the descent reaches (on r36 it ran in every frame, so each leak spelling reopened one level down;
_ONE_LEVEL_DOWN_REFUSE, 19 rows, and a cut-every-frame mutant pin this). A literal consumer body reached by DESCENT (acat/tee/git commit -F -here-doc inside abash -c) is read as a script, so a nested printed self-ssh is refused wheremainallows it: a deliberate safe false-deny, listed under "Over-refused by design" below. Five versions of a by-descent cut each leaked under independent review (piped or redirected carrier, an enclosing runner, glued/fd/quoted/./path spellings, an earlierexec,&ortrapsibling); every leak spelling is a DENY pin (_NESTED_LEAK_SPELLINGS_REFUSE, 19 rows, base ALLOW / head DENY).Cost
The belt is two linear legs in two tokenizer modes. A shared-tokenizer memo keyed by
(text, mode)with a construct pre-check (_modes_may_diverge) lets the scanner reuse the default-mode tokens whenever a command carries no quote — the only construct on which the two modes differ — so a command both legs reach is split once, not twice (an identity pin proves the shared tokens equal the unshared over the 32k corpus in both modes, with a mutant that shares a quote-bearing, mode-divergent command reddening it). The remaining second leg still reads its own frames, so the floor's total per-check work is about twice origin/main's single-leg cost.origin/main bounds its single leg at
chars ≤ 3×the input. This PR does not loosen that bound to the combined two-leg work: each leg is bounded on its own. origin/main's 3× is kept verbatim on its own leg (the substitution reading), and the same 3× is applied independently to the fold-scanner leg (test_each_leg_tokenizes_linearly_in_the_input,test_each_leg_judges_nested_substitutions_linearly). A flatness pin holds the ORDER at ≤ 2.2× work per input doubling, independent of the constant; per-leg counters show the ~2.0×-each split (about 2027 vs 2043_self_tokenschars at eval count 200)._self_tokenscharacters for the repeated-eval shape (eval × n; echo $(echo ssh)), origin/main (one leg) vs this head (two legs):Two readings of this bound point opposite ways; we lay both out for the maintainers rather than pick (a maintainer-decision red, below):
a-ratchet-may-only-tightenlane reads one whole-floor counter and sees a bound that was 3× of a single leg now standing per-leg — the combined work reaching ~2× main's — as a loosening. We measured the alternative it implies (one whole-floor counter over the gate-levelshlex.splitcharacters, memo-deduped, the lane's own suggested shape): it reports 6.94× the input, worse than the 4.00× a plain two-leg character sum reports and far past any single 3× whole-floor bound — so one 3× whole-floor bound is unmeetable without deleting the second leg.So each leg is held at main's own 3×, the combined work is ~2× main's, and whether that reads as a ratchet loosening or as the duplication First Principles required is for the maintainers. Measurements: 4.00× (plain two-leg sum vs input), 6.94× (the lane's suggested whole-floor memo-deduped counter vs input), ~2.0× per leg, flatness 1.98×/doubling. Net
src/kiro_crew/security/*.pyline delta vs base: +635 (the budget row).r36 omitted five forwarded names from the
argv_floormanifest, red on CI shard 6; fixed in r37 (the manifest now names all forwardedargv_floor_ssh_bodiesnames, and the one shared-name test patch —_is_ssh_to_self— is routed through the facade).Rows the single loop cannot refuse (First Principles clears-when)
First Principles asked whether the two legs could collapse into one — queue nested payloads with
judge=Trueand drop theif live:guard on origin/main's_substitution_reaches_self, then delete the fold scanner. We ran exactly that subtraction on a scratch branch and measured the single loop against this head over the 32,576-row corpus (double-run, 18-row self-host flaky set excluded) and the r19–r33 pins. The single loop cannot refuse 7 corpus rows this head refuses, and over-refuses 1 benign row this head and main both allow (\n= newline):cat <(bash -c 'true\nssh localhost id')tee >(bash -c 'true\nssh localhost id')echo <(bash -c 'true\nssh localhost id')cat < <(bash -c 'true\nssh localhost id')diff <(bash -c 'true\nssh localhost id') xgrep x <(bash -c 'true\nssh localhost id')bash -c 'true\n# "\necho " #"\nssh localhost id'bash -c '# x\+nl+ssh …',(true)#c\+nl+ssh …)bash -c 'set -e\n# debug: ssh … localhost\nnpm test'(benign)The single loop has no fold, so it misses the process-substitution and comment-continuation rows, and it reads a commented-out
sshin a single quote as live and over-refuses it. The fold scanner is a distinct leg doing real work; it is kept, not collapsed.And not by reusing
shell_normalizer._shell_payload_walk(First Principles clears-when, measured)A later review asked whether the fold scanner duplicates the existing
_shell_payload_walkand could be deleted in favour of judging its frames (_shell_payload_sources(text)[1:]) with_is_ssh_to_self, separators left live. We applied exactly that subtraction on a scratch branch off this head and measured it with the same 32,576-row corpus (double-run) and the r19–r36 pins. It loses noorigin/mainrefusal (0 new-ALLOW vs main) — but it does not serve what the fold scanner adds: vs this head it loses 3 corpus refusals / 15 pin refusals and over-refuses 54 corpus rows / 4 literal pins, because_shell_payload_walktokenizes withoutpreserve_structure(so it never reaches a self-ssh 2+bash -clevels deep), folds with_fold_line_continuations(not comment/heredoc-aware, so it misses the comment-continuation and split-verb rows), and has no literal cut (so it reads printed here-document data as a script). Representative rows (main / this head / subtraction):\n= newline)bash -c 'true\nbash -c "true\nbash -c \"true\ns?h localhost id\""'(3-level)bash -c '# x\<nl>s?h localhost id'(comment-continuation)bash -c 'true\n/usr/bin/s?\<nl>h localhost id'(split verb)cat <<'EOF'\nbash -c 'true\ns?h localhost id'\nEOF(printed data)Each of the fold scanner's parts (
preserve_structuretokens, the comment/heredoc-aware fold, the literal cut, the<(/>(reading) is the sole decider of a named row, so none is duplicative. The subtraction would only become right if_shell_payload_walkitself gained structure-preserving tokens and a comment-aware fold — a change to main's shared walker, out of this PR's scope.Continuation-split verb on a later line (GPT clears-when)
A verb split across a
\-newline on a later line of a shell-run script (bash -c 'true\n/usr/bin/s?+\+ nl +h localhost id') must fold tos?h/sshand be refused. The scanner leg carried a verb prefilter (_line_may_name_ssh_verb) that ran on the UNFOLDED line and short-circuited before the fold could rejoin the verb, so the self-ssh slipped.Running the prefilter on the fold's output does not fix it:
_fold_outside_quoted_heredocsis quote-aware and does not fold inside the outerbash -c '…', so the split verb stays hidden on the top-level folded line. So the prefilter is widened, not removed: it short-circuits only a line that names no ssh verb and carries no\-newline continuation — a backslash-newline being the one way bash splits a word across lines — so any line that could fold into a verb reaches the descent, while a verb-free, continuation-free data-consumer argv short-circuits and is not descended (removing the prefilter entirely made that argv sweep quadratic in the payload count; the widened form keeps it linear without reopening the slip). The verb gate sees through quote/backslash splices (ss""h,s\sh), so a quote-split verb is admitted too. The base leg keeps its own prefilter.bash -c 'true\n/usr/bin/s?\+nl+h localhost id'(later line)bash -c '# c\+nl+s\+nl+sh localhost id'(split after comment)/usr/bin/s?\+nl+h localhost id(unnested top level)The unnested top-level spelling is main's own whole-line path (it folds nothing there); this PR does not touch it — see "Not covered" and the main-side issue #39797. Pins:
test_a_continuation_split_verb_on_a_later_line_is_refused,test_the_unnested_top_level_split_verb_stays_mains_allow, andtest_restoring_the_scanner_verb_prefilter_reddens_the_split_verb(restoring the prefilter re-opens the slip).A later line reaches origin/main's own host posture
A crontab schedule written through an unquoted
cat <<EOF | crontab -heredoc names no ssh verb, yet the descent refuses it:bash -c 'cat <<EOF | crontab -\n0 3 * * 0 /usr/local/bin/backup.sh\nEOF'origin/main reads the
*as a glob that could name an ssh verb andbackup.shas a dotted host whose DNS is unresolved, and fails closed — and it refuses the same line at top level (0 3 * * 0 /usr/local/bin/backup.sh). The descent only reaches that line on line 2+.test_crontab_data_heredoc_nested_verdict_equals_top_levelpins the nested verdict equal to the top-level one, so this is main's own posture reaching a nested line, not a refusal this PR introduces (the same class as the branch-Arsyncrow below).Backwards compatibility
Compatible: every existing caller of
_shell_tokenskeeps the base ref's default empty-pair elision (the deny view, the rm and git floors, and argv_rules are byte-identical to base); the only behaviour change is the ssh-self descent, which refuses more. A full-verdict differential over 32,576 rows against the base ref loses no denial.Removes nothing: no command the base ref accepts is renamed or removed, and no path, record, key or public function is deleted; the diff only adds refusals of a self-ssh on a later line of a shell-run script, which is the Goal.
Tests
Proof: PROVEN —
prove.py --base origin/mainreverts the production hunks and the changed tests fail (head 78b7f13cc45a); among them test/test_deny_gate_call_sharing.py::test_one_gate_call_tokenizes_each_text_once and test/test_ssh_self_executed_scripts.py::test_a_self_ssh_on_a_later_line_of_a_run_script_is_refused and ::test_a_continuation_split_verb_on_a_later_line_is_refused.Added or updated:
test_ssh_self_executed_scripts.py— a self-ssh on a later line of a run script (bare, nestedbash -c, process substitution) is refused; a non-shell consumer's literal body (quoted heredoc / single-quoted here-string ofcat/tee/echo/printf/git commit -F -) is NOT read as a script (6 ALLOW pins) while a shell-consumer body still is (7 REFUSE pins) and a grouped / piped / compound / process-sub consumer stays refused (10 escape REFUSE pins), with strip-all, strip-none and cut-even-inside-groups mutants; a crontab schedule on a later line is judged exactly as the top-level line; a comment-continuation does not hide a later-line self-ssh (G1/G2); a continuation-split verb on a later line is refused, the unnested top-level split verb stays main's ALLOW, and restoring the scanner's pre-fold prefilter re-opens the slip; a crash in the fold fails closed and logs once (S1); the base leg reads a self-ssh as its own substitution reading, a drift pin asserts it stays byte-identical to origin/main, and two mutant pins (scanner leg off / base leg off) each drop a refusal; a benign remote host and a local-only payload stay allowed.test_deny_gate_call_sharing.py— one deny judgement tokenizes each(text, mode)once; preserve-structure tokenization runs only on a command that can name an ssh verb after folding (a verb present, or a\-newline continuation), not on a verb-free data consumer; the shared tokenizer matches the unshared over the corpus, and a mutant that shares a mode-divergent command corrupts the preserve tokens.test_ssh_self_descent_cost.py— the two scan-linearity bounds bind EACH leg at main's own 3× (main's leg kept verbatim, the scanner leg bounded the same, with a shared memo), not one 5×-of-combined bound; a flatness pin holds the ORDER at ≤ 2.2× per doubling independently of the constant (a re-read-per-frame quadratic reddens it); a per-leg pin shows the ~2027 vs ~2043 split; a counter pin holds that a payload-heavy verb-free, continuation-free argv is not descended at all, with a mutant that widens the prefilter to always-descend reddening it.security_line_budget/ssh-self-executed-scripts.txt— the+635budget row, this diff's net line change undersrc/kiro_crew/security/.Security-package invariant tests (these guard the facade and budgets the pre-push gate does not run, and all pass on this head):
test_argv_floor_facade.py— the owners are everyargv_floor_*module in layer order, and every name served from outside the family is in theTYPE_CHECKINGmanifest.test_facade_mirror_guards.py::test_every_mirrored_facade_manifest_names_what_it_forwards— every name the facade forwards is named in its manifest.test_facade_shared_checks.py::test_every_scanned_name_reaches_every_module_reading_it— no module reads a shared name it does not bind.test_mcp_listing_import_budget.py— the per-server module ceilings hold without being raised (belt-by-construction adds no new module to any covered server's startup import graph).test_security_gate_liveness.py::test_the_package_stays_within_its_line_budget— thesrc/kiro_crew/securityline count stays within its budget.Manual verification
Local pre-push gate 26/0 (black, isort, flake8, mypy, comment-history, vendor and brand checks) on head f132752 (
Gate proof: tree 3f0a491963bf; ran 26; skipped none). The full denied-commands test family plus the ssh-self / deny-gate / host-verdict / descent-cost / gate-liveness files pass (2,615 passed, 1 skipped), includingtest_security_gate_liveness.py::test_the_package_stays_within_its_line_budget. A full-verdict differential over 32,576 rows (head vs base) shows 0 lost refusals and +117 added; the 18 remaining rows are a pre-existing self-host DNS-timing flaky set, identical on both trees.Two local pre-push review lanes (the CI fork lanes' own contracts, extracted from the base ref and run locally) reported no findings on this head. Both carry a served-model caveat, stated here plainly rather than left implicit: the Opus lane was served
claude-opus-4.8becauseclaude-opus-5.5was unavailable at run time, and the GPT lane's served model was not reported back by the backend — so to that extent local lane-green is weaker than a server run. What bounds whatever either lane could have missed is the structural guarantee, not the lanes: the differential is 0 new ALLOW vs base, and the literal cut is confined to the scanner leg while origin/main's legs read the uncut text, so nothing origin/main refuses can pass regardless.Newly refused on a CI runner (branch A: a later line judged as the first line)
The Security Scope harness reports rows that flip base ALLOW → head REFUSE on a runner whose address list or DNS is not available at test time. Each is a remote host on a later line of a
bash -cscript, judged exactly as the first line would be — not a new rule. The representative row is the ubuntursyncdeploy one-liner (\n= newline):bash -c 'set -e\ncd /srv/app\nrsync -az dist/ deploy@203.0.113.10:/srv/app/'203.0.113.10is a non-local documentation IP. On a runner whose kernel address list has not published, a non-loopback IP is refused fail-closed until the list loads — main's own host posture, unchanged here:git diff origin/mainis empty onargv_floor_hosts.py,host_addresses.py,hosts_file.py, and the host-resolution path ofargv_floor_ssh.py. This PR adds only the descent, which carries that first-line posture to a later line. Measured with the floor at BASE and HEAD, for the top-levelrsync …203.0.113.10…and the nested row, in both address-list states:Base and head give the same top-level verdict; head's nested REFUSE equals its own top-level REFUSE (a later line is judged as the first line). The over-refusal of a non-local IP literal while the address list is unpublished is main's own posture; the main-side issue #39797 covers it.
test_a_later_line_dotted_host_is_judged_as_the_top_level_line_ispins the equality. The r33 macOSdeploy.example.comrows and the crontabbackup.shrow above are the same class (an unresolved name/glob on a runner with no DNS).Not covered (matches main)
These self-ssh spellings stay allowed on this head, allowed on
mainand the merge-base alike — pre-existing gaps this PR does not touch, not regressions it introduces:/usr/bin/s?+\+ newline +h localhost idtyped directly, not inside a shell-run script. 3-tree verdict: base ALLOW · main ALLOW · this head ALLOW. This is main's own whole-line path, which folds nothing; this PR folds only inside the descent (shell-run payloads). Pinned bytest_the_unnested_top_level_split_verb_stays_mains_allow; the main-side issue A non-local IP literal is refused as "self" while the kernel address list is unpublished #39797 covers it.x=(s sh); ${x[0]}${x[1]} localhost id. 3-tree verdict: base ALLOW · main ALLOW · this head ALLOW.cat >/tmp/p) that a separately backgrounded shell reads (bash </tmp/p &). Statically intractable: the write target is indistinguishable from a regular file a non-shell consumer writes (tee), so the literal cut cannot tell the two apart without tracking the fifo across commands. 3-tree verdict: base ALLOW · main ALLOW · this head ALLOW — left in the belt's and main's hands, not newly refused here.shopt -s expand_aliases; alias cat=bashthencat <<'EOF'\n… ssh …\nEOF, or agitshell alias. The literal cut keys on the written head (cat), so it cuts a body the aliasedcat=bashwould run. 3-tree verdict: base ALLOW · main ALLOW · this head ALLOW — main allows it too, so it is a pre-existing gap this PR does not widen (0 new-ALLOW vs base), not a refusal introduced or lost here. A static exclusion is unsound: analias/eval/sourcecan redefine any head and a static check cannot track it. Control row (all three ALLOW):shopt -s expand_aliases; alias cat=bash; cat <<'EOF'\ns?h localhost id\nEOF.cat/teewrites a quoted literal body holding a multi-linebash -cself-ssh to a file, and a top-level sibling runs it: write-then-bash FILE, write-then-source FILE, an earliertrap 'bash FILE' EXIT, an earlierexec >FILE, or an earlier backgroundedbash FILE &. The top-level cut drops the body, so this head allows them, and so doesmain: equal to main, no fix. 3-tree verdict: base ALLOW · r36 ALLOW · r37 ALLOW, for all five. Control row (all three ALLOW), one line each:cat > /tmp/x <<'E'/bash -c "true/s?h localhost id"/E/bash /tmp/x. The piped formcat <<'E' | bashis refused on r36 and r37 (the plain-command-list rule).bash <<<'s?h -p 22 localhost id'(and thexargs -I{} bash -c {}form). 3-tree verdict: base ALLOW · r36 ALLOW · r37 ALLOW; equal to main, no fix (Opus lane, r37).bash -c "$(cat <<'EOF'/ssh -p 22 $(hostname) id/EOF/)". 3-tree verdict: base ALLOW · r36 ALLOW · r37 ALLOW; equal to main, no fix (Opus lane, r37). The literal-host spelling of the same shape is refused on all three.Over-refused by design (GPT lane F2 clears-when)
A lone
cat <<'EOF',tee FILE <<'EOF'orgit commit -F - <<'EOF'whose quoted literal body holds a self-ssh, nested in 1-3 levels ofbash -c, is refused on this head and allowed onmain. The over-refusal is kept as a safe false-deny inside the 0-new-ALLOW bar; no override is asked. 3-tree verdict: base ALLOW · r36 REFUSE · this head REFUSE. Pinned as_NESTED_LITERAL_OVER_REFUSED(9 rows) intest/test_ssh_self_executed_scripts.py. It clears when a nested cut is proposed that also refuses every_NESTED_LEAK_SPELLINGS_REFUSErow.Changes r36 -> r37
argv_floor.py: the TYPE_CHECKING manifest names the five forwarded ssh-bodies names (facade mirror guard, CI Backend Tests shard 6 red on f132752).test_ssh_self_descent_cost.py: patches the shared_is_ssh_to_selfthrough the facade.test_ssh_self_executed_scripts.py: 19 nested leak-spelling DENY pins, the same 19 one level down plus a cut-every-frame mutant, 9 documented over-refusal pins, nested executed-form DENY pins at depth 2 and 3.argv_floor_ssh_bodies.py: the literal cut runs on the top-level line only (judgeFalse), not in descended frames.Real-machine verification
N/A — unit coverage plus
prove.pyis sufficient and the change runs no network operation.prove.pyreverts the production hunks and confirms the changed tests fail without them (head 78b7f13cc45a); run on the Linux dev host (aarch64).Screenshots / video
N/A — the diff touches no user-visible frontend surface (no
website/changes and no committed screenshots).Related Issues
Fixes #35314
Sibling sweep
Swept:
git grep -nE "_nested_shell_payloads|_substitution_reaches_self" -- src/kiro_crew/security/for other paths that read a shell-run payload without descending into its later lines.Sibling: none — the descent is the single entry the floor uses to read executed-script payloads; the first-line and whole-line self-ssh readers already in place are the only other paths and are unchanged.
Pattern harvest
Not generalizable: the defect is specific to the ssh-self floor reading only the first command of a multi-line
-cbody; it is a one-off in this floor, not a class across the codebase.Checklist
fix: ...)Contribution License Agreement
Contributions are accepted under the project's Apache-2.0 license; see the Licensing section of CONTRIBUTING.md.
Takeover
This PR touches
src/kiro_crew/security/*from a fork. Three reds on it are maintainer decisions, not defects this branch can clear:src/kiro_crew/security/*by design — nothing posted here clears it (the same hold as fix(security): refuse a mint whose verb comes from a quoted substitution #37077). The route to green is a maintainer takeover: a branch on this repository that keeps the author withCo-authored-byand writesSupersedes #35359, runs the real sandbox, and drives the PR green.a-ratchet-may-only-tightenlane) — the lane reads the combined ~2× work as a loosening; First Principles reads a single bound as a demand to delete the second leg it requires. Both readings are laid out under "Cost" with the 4.00× / 6.94× measurements; the maintainers choose. We ask for no override.Every other check and lane on this head is green locally — gate 26/0, prove PROVEN, the full-verdict 32k differential against base loses no denial (only the intended ssh-self tightenings), and both local pre-push lanes report no findings (with the served-model caveats stated under "Manual verification": Opus served 4.8, GPT served-model unverified). We ask for no override on any of the three reds above.