Repository navigation
fix(security): refuse a mint whose verb comes from a quoted substitution - #37077
jeeshofone wants to merge 1 commit into
Conversation
Code change approver recommendation: A person should decideWhy: the decider thinks the change is probably fine but estimates a 14% chance that this change introduces a defect, above the 12% limit for approving on its own. I'm approving this PR. It only adds refusals, and the path main uses is unchanged byte for byte. Resolver ( Payload walk. It now adds extra frames, but only in one case: some substitution on the line, read with its quotes, has an
Floor ( 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 |
29667d7 to
32d18e4
Compare
First Principles Review (Opus 5.5, fork) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Nothing blocks. The fix works by adding a second resolver next to main's dequoted body readers instead of fixing them, so the security floor now carries two resolutions for good. Notes
What this change shipsInventory (8 items) — 4 justifiedIntent: stop an agent from getting
[FIRST-PRINCIPLES-REVIEWED] a3e3871 Description read[DESCRIPTION-READ] c90d4baf8c85801fd17234f7d261c20670747e965b8e140a156850d4998cd500 That sha256 names the PR description this verdict read. Recompute it with |
UX Review (Opus 5.5, fork) — ⏭️ skippedRevision |
Design Review (Opus 5.5, fork) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks: the bypass is real, the second resolution can only add refusals, and every reader of the moved wrapper table and program-index helper was updated in this patch. Notes
[DESIGN-REVIEWED] a3e3871 Description read[DESCRIPTION-READ] 5c07f91c148d3d652141f8c34ae9671d751682845fd8a7cba690410396c39c19 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 |
Opus 5.5 Review (fork) — ✅ no blocking findingsReviewed |
GPT 6.1 Review (fork) — ✅ no blocking findingsReviewed Review detailsNo findings. |
32d18e4 to
8d0de57
Compare
|
Both GPT 6.1 blockers on 32d18e4 are fixed in 8d0de57. Unsuccessful verb scans bypass the reading cap ( Message operands classified as mint verbs ( |
Security Scope Review (fork) — ✅ PASSWhich legitimate operations does adjudicated, zero confirmed regressions Scope-Verdict: PASS Reason: No regression is script-confirmed yet: the harness had not handed back any verdict for the 22 candidates when this review was written. The tightening is narrow. It fires only when the product CLI is the command's argv[0] and a quoted substitution naming the verb sits before the first operand, or when a top-level assignment's substitution body names the verb or a protected program. The ssh-to-self cased-twin pairing change is probed only through neighbours. TIGHTENING: credential-mint argv floor ( ADJUDICATED: 22 candidates, 0 confirmed newly-refused (no verdicts had been handed back when this review was written) PLATFORM COVERAGE: posix (17 rows) covers what the diff assumes about bash: UNADJUDICATED: Two boundaries are argued in prose only, with no verdict. (1) [SCOPE-REVIEWED] 3d406deSecurity scope review -- adjudicated candidates
No candidate flipped from allowed to refused. |
|
The Opus 5.5, GPT 6.1 and Security Scope blockers on 8d0de57 are fixed in e6dd2cc. Nine read-only captures refused as a mint (Opus Chat message read as the verb (GPT The |
8d0de57 to
e6dd2cc
Compare
6b10ef7 to
ee3f14b
Compare
|
Round-16 review reply — how each lane's concern was resolved on the current head ( First Principles — no emulator. The reverted approach modelled what a substitution would print (a bash-output emulator), and that machinery produced repeated real-mint regressions. It is gone. What ships is a single bounded rule in Opus — redirect depth. The redirect-skip GPT r18 — benign over-refusal. When the body named neither a program nor the verb, the empty binding used to fall through to GPT r19 — lettered-glob gap. The body scan matched only the literal product name, so a glob that bash expands to the product ( Review harness. The local lanes were extracted from the base commit's CI review workflows by |
ee3f14b to
2467648
Compare
|
Round 18 on head DesignThe new branch is no longer patched. Its old pieces are deleted:
Monotonicity proof, in the PR:
Opus finding on ee3f14b (comment 6877448080): backtick body with a later apostrophe (
|
|
Round 19 on head Opus (comment 6877448080): a bare glob word in the body bound as the productFixed at the cause. Pins, measured on main and on this head:
GPT F1 (comment 6877469524): alternative bindings escaped their shell scopeFixed at the cause, with no new regex guard. The alternative no longer rescans the raw source for assignments. Main's The alternative now walks the tokens main produced. It reads a raw substitution body only for an assignment that sets a variable in this shell:
The raw word offsets come from one walk of the shared quote state machine ( The scope check fails closed, toward leaving an assignment unpaired:
An unpaired assignment keeps main's binding, so the alternative frame differs from main's only in how it reads a body, never in which assignments it binds. Pins, measured on main and on this head:
The last row stays refused because main refuses it. Main's resolver binds the argument token MonotonicityThe alternative frame is only ever appended. The per-line repo sweep checked 3,214 real lines against Layout
Checks on
Local GPT lane on d72fa5a726: an uncalled function body whose
|
|
Round 20: one commit on F1 (
|
Sensitive change reviewHead: dd58135
|
|
Round 22 on head F1 (fork GPT lane): a rebinding kept an earlier program-only flag -- fixedUnchanged from round 21. Fork GPT lane:
|
Sensitive change reviewHead: 844e1ca
|
|
Round 23 on head Security Scope Review on
|
|
Round 24 — structural change on head What changed (one change, not two patches) Dropped, as both lanes asked:
A Redirect / program-position bypasses (found by the GPT and Opus lanes, fixed here). Two pre-existing spellings let a redirect defeat the program-position gate the mint check relies on, both present on the round-23 head and allowed on main — neither introduced by the r24 subtraction:
Both fixes live only in the alternative pass / the PR's own program-position gate ( Wrapper / keyword class (found by the GPT and Opus lanes, fixed here). @FIRST Principles — adopted your subtraction. The @Opus — the quadratic path is deleted, not merely bounded: there is no Row table (verified by a three-tree probe: main / round-21-no-
Every row that returns to allowed is allowed on main, so the vs-main oracle stays at 0 refused-on-main → allowed (8524 allowed → refused unchanged). The grammar suite's pins for those rows moved from Gates on this head: pre-push gate green, prove.py PROVEN, semgrep 0, deny_diff 0 regressions, oracle 0 refused-on-main→allowed, full grammar + denied-command suites green, budget row GPT. The local lane ran on |
|
Round 25 on head @Opus (security regression, ssh self-protection) — fixed. A cased product name in a substitution body ( @GPT (fenced, over-refusal) — fixed in code. An append that RETAINS or extends its binding cleared the variable's program-only provenance ( Differential vs Checks on this head: pre-push gate green, prove.py PROVEN, semgrep 0, deny_diff 0 regressions, full grammar + denied-command + ssh-self suites green. Observation, not part of this PR: |
|
Round 27 on head @Opus @Opus @GPT @GPT @Opus r26i (the Residuals (same verdict as Differential. vs Checks on this head: pre-push gate 26/26, prove.py PROVEN, semgrep 0, deny_diff 0 regressions, full grammar + denied-command + ssh-self + case-frames + capture-oracle suites green. |
|
Round 28 on head @Opus By measurement, the cubic is not the alternative pass — main's baseline reader is equally cubic on the same input.
main has no alternative pass yet is as slow. A cProfile puts the cost in main's We tried the cost fix you suggested — return Root cause: the reader folds a real newline to So r28 ships: the alternative keeps a460e18's whole-remainder read (no verdict change — the corpus differential is verdict-identical to a460e18), plus the No overclaim: the gate is still slow on this input — it is main's baseline cost; this PR neither adds nor removes that, and regresses no verdict. Checks on |
|
Round 29 on head @GPT Fix in Pinned by One fail-closed over-refusal, recorded as a documented residual. The binding-carry refuses a non-executable command where the nested @Design — ssh-floor cased-twin behaviour named. Added a body subsection ("ssh self-connection floor: cased-twin judging") naming the @FIRST Principles — item 1 (the dequoted body scan as a second reader). Noted; it stays as-is in this PR for the union oracle and is deferred, no code change. Checks on |
|
Round 30 on head @Opus Fix in Pinned by Differential over the 20,736-command corpus: 0 refused→allowed vs Checks on |
The assignment resolver reads dequoted tokens, so a ' that bash reads inside double quotes (T=$(: "'"; echo token)) opened a quote there, the program-name scan ran into the use site, and $T was bound to the program instead of the verb. When the substitution may produce both, keep the program reading and add the verb after a bare use. The mint floor also reads a quoted substitution argument (kirocrew "$(printf token)") through the shared substitution reader. Only refusals are added. test-only (r31): test_the_floor_binds_on_the_verbs_presence is sharded into 8 (sharing _MONOTONIC_SHARDS with the monotonicity sweep) after it hit the 120s CI per-test timeout on shard 4 of head 3d406de -- the fail-closed rule raised the gate's cost on the never-closing corpus. Each shard pins its own slice's here-string residual via a structural _is_herestring_body predicate, and the 120-body total is pinned by test_the_here_string_residual_total_is_pinned. Per-shard call seconds on this host: s0 1.46, s1 1.38, s2 1.62, s3 1.44, s4 1.51, s5 1.40, s6 1.59, s7 1.43 (max 1.62s, from ~12s unsharded). The proof the test runs is unchanged. Fixes kirodotdev#36961 Signed-off-by: Will Laws <will.laws@me.com>
Problem / Motivation
Goal: The credential-mint guard refuses
kirocrew tokenwhen the subcommand comes from a command substitution whose body holds a'inside double quotes.is_denied("T=$(: \"'\"; echo token); kirocrew $T")returns None on main, and so does the${T}variant. Bash reads that'as a plain character, so the substitution printstokenandkirocrew tokenruns. Main's resolver reads dequoted tokens and treats the lone'as an open quote. Its program scan then runs past the substitution's real close into the use site and binds$Ttokirocrew, so the use resolves tokirocrew kirocrew. That has no verb, so the mint is allowed.Why it matters
The mint prints a signed dashboard access URL. An agent that gets one past the guard escalates out of its own session.
Not a goal
printf %s%s tok en,echo tokem | tr m n) stays allowed, as on main.sudo --edit/sudo -efromsudo -E.sudo --edit/-ewith a mint-shaped operand is refused, because the floor lowercases before the walk and cannot tell-e(sudoedit, runs no program) from-E(--preserve-env, which does run the command); refusing is the safe side, and threading original-case text through the lowercasing layer is a change to the floor's input contract that does not belong here.Not covered (same verdict as main)
The subcommand-from-substitution reading applies only when the command's program token (argv[0], after resolution) is the product CLI (the Security Scope Review / F3 rule). A product name carried as another program's argument keeps main's verdict. The computed-verb and here-string residuals (see "Not a goal" and the residual table) stay allowed, identical to
origin/main.An assignment inside a
casearm or a{ …; }command group —case x in x) T=$(: "'"; echo token);; esac; kirocrew $T,{ T=$(: "'"; echo token); }; kirocrew $T— is allowed onorigin/mainand here. The raw word walk treats a{/(group as a non-current scope (main's resolver has no scope notion), so a substitution-valued assignment inside one is not read; the same holds for an uncalled function body (f(){ T=$(...); },function f { ...; }). Catching these needs per-construct scope tracking that repeatedly mis-read exotic shell grammar in review, so the r26 scope tracking is reverted to the r25 depth-based reading and these are left exactly asorigin/main(see the follow-up issue).A leading clobber redirect —
2>| /dev/null kirocrew "$(printf token)"— is allowed onorigin/mainand here._program_positionsreads dequoted tokens, where the clobber operator's>|is byte-identical to a quoted>beside a pipe, so it cannot tell them apart without the raw text's quote state;>|behaviour is therefore left unchanged fromorigin/main. A quote-aware fix belongs in its own PR (follow-up issue filed with the trigger, the dequoted-walk limitation, and the fix shape).A wrapper or command keyword in front of the CLI (
env kirocrew "$(printf token)",sudo,command,exec,nohup,time,timeout 5,!,if …; then) is now COVERED, not a residual. An earlier round declared it out of scope on the rationale that "the floor has no shared wrapper-unwrapping resolver to reuse"; that was wrong —argv_rules._program_indexalready steps over the same_WRAPPERStable and command keywords. The wrapper table and that skip now live inshell_normalizer_walk(_WRAPPERS,_program_index), and_program_positionsreuses them (one definition, no second copy), sokirocrewbehind a wrapper takes program position and the quoted-substitution mint is refused. The widening is only the mint shape: a wrapper running a harmless subcommand (env kirocrew status,sudo kirocrew doctor) still keeps main's allow, and the plain-verb form (env kirocrew token) was already refused on both main and head by the position-agnostic bare-verb reading.A command built of never-closing command substitutions —
a=$(: #); a=$(: #); …; kirocrew doctor, where each#swallows the)so the substitution never closes — makes the BASELINE reader (_resolve_local_assignments→_mint_verb_in_substitution→_substitution_bodies) hand each of N frames the whole remainder and rescan it per assignment: O(n³) in the command length. This is PRE-EXISTING onorigin/main:is_deniedtakesmain10.7s at a ~2 KiB command (reps=200). This head is slower only because r30's fail-closed reading (below) pairs every never-closing assignment, so the gate is 15.3s at 2 KiB; bothmainand this head still exceed 180s at ~8 KiB because of main's reader. The line is also syntactically incomplete in bash (an unterminated substitution never runs). This PR does not change main's reader; the alternative pass it adds is NOT the dominant cost — its share of the gate is flat across sizes (gate 2.3s / 15.3s / 112.7s and alt-pass share 29% / 31% / 31% at 1 / 2 / 4 KiB), the same order as the baseline, with main's reader still dominating (pinned bytest_the_alternative_pass_is_a_small_share_of_the_gate, bound< 50%). A cost shortcut that skipped the remainder read for unproven bodies was tried and reverted — it dropped refusals bash closes (a folded-newline literalF=$(: # )⏎printf …); $F token, and the lettered-glob self-program spellingskirocre[w]/k*that only the alternative reads, with no baseline backstop), now pinned refused bytest_a_bash_closable_unprovable_body_mint_stays_refused. The baseline cubic is tracked as a main-side DoS in #39617.Residual (over-refusal, fail-closed).
F=$(: "'"; printf %s ./kirocre[w]; bash -c "$F token"); trueis REFUSED here, allowed onorigin/mainand on the pushed head571d9e9e07f4:origin/main571d9e9e07f4Mechanism: the pre-existing lone-quote tokenizer defect mis-surfaces the initializer's own nested
bash -cas a top-level carrier, so the program-only carry seeds the binding into its own initializer — where$Fis in fact unset while that RHS runs, so bash never mints. This is fail-closed (a refusal of a non-executable command, the direction the repo's floors err), and a clean exclusion needs the quote boundary the defect obscures; it is left as a residual and pinned REFUSED bytest_the_self_initializer_carry_is_a_documented_over_refusalso a later flip is visible.What changed (motivation → approach → change)
Root cause: a lone dequoted quote stops main's quote-aware close walk from finding the substitution's real close. The program scan then over-reads into the use site and binds the use-site program.
Approach: keep main's resolution untouched and add a second resolution. The command is refused if EITHER resolution refuses.
_resolve_local_assignmentsis main's code, unchanged. Its binding and verdict stand.shell_normalizer._alternative_mint_overrides,_raw_substitution_mint_name; the raw word walk_raw_word_scopeslives inshell_normalizer_walk): for the assignments the baseline itself binds, read each one's own substitution body from the folded raw source, where its quotes still close. Only an assignment that sets a variable in this shell is read. That means one at a command's prefix position (no program yet in its argv) and at top level in the raw text: not inside a subshell, a substitution, a brace group or a function body (gluedf(){ ... }included), and not an argument such asecho T=$(...). Main's resolver has no notion of scope, so this check is what keeps the alternative's binding in the right frame. Anything the check cannot classify is left unpaired and keeps main's binding. The body comes from the same quote-aware readers the baseline uses (_matching_close_paren,_matching_close_backtick), and is tokenized as a command, so a quoted"it's token"stays one operand. A protected program named anywhere in it wins (product name, by-name kill program, or a glob whose basename has a letter, such askirocre[w]orkiro*; a bare*ortest/*is a filename pattern), else the verb, else nothing. Each assignment takes its own reading, so a laterT=$(echo doctor)does not inherit an earlierT's verb. A name in a${...}prefix or in a later command is never read as the body's own._shell_payload_walk): when the alternative binds anything, the walk appends a second frame resolved with those bindings and descends that frame's nested payloads too, CARRYING the frame's bindings (the values and the program-only set) into the inner walk and resolving each program-only name at the INNER payload's program positions. So a program-only binding reaches a mint nested in abash -c/sh -cor wrapper payload:F=$(: "'"; printf %s ./kirocre[w]); bash -c "$F token"(alsosh -c, and behindenv/sudo/timeout 5) is refused, because$Fis at the-cscript's own program position though it was a-coperand in the parent; a data operand (bash -c "echo $F") stays unexpanded (the fork GPT lane's r28 F1). The baseline frame is never dropped or rewritten, so the floor refuses a superset of what main refuses. A command with no substitution-valued assignment builds no second frame and pays nothing. The alternative reads one body per assignment, so many substitution assignments cost what main already pays (test_the_alternative_reads_each_body_once).Dead code from earlier rounds is gone:
_substitution_body_span,_substitution_quote_unbalanced,_unbalanced_substitution_bindingand the quote-blind paren walk.Program-position scope (Security Scope Review / F3). The subcommand-from-substitution reading fires only when the self name is the command's program word (argv[0], after resolution), so a product name carried as another program's argument keeps main's verdict: a repo slug (
gh ... --repo kirodotdev/KiroCrew --body "$(gh auth token)"), a secret/service/container name (kubectl ... --from-literal=X="$(...)",security ... -s kirocrew ... -w "$(...)",docker run --name kirocrew ... -e X="$(...)"), or a glob-bound variable used as an operand (TESTS=$(git ls-files 'test/*crew*'); pytest $TESTS -k token). A new_program_positions(inshell_normalizer_walk, re-exported) marks argv[0] with the same command-boundary walk as_argv_programs, skipping a leading redirection (which the shell strips from argv, so>/dev/null kirocrew "$(printf token)"still reads the CLI as the program). The alternative's own prefix test — whether a substitution-valued assignment precedes any program in its command — walks that same redirect-aware walk rather than_argv_programs, which reads a leading fd-prefixed redirect (2>,1>&2,&>,{fd}>) as a program named2/1/&/{fd}; so2>/dev/null T=$(: "'"; echo token); kirocrew $Tkeeps the assignment at prefix and is refused, as the plain>/dev/nullform already was. That prefix test runs only in the alternative pass, so the baseline is unchanged from main._program_positionsrecognises a redirection only when the token BEGINS with one (_push_token_redirection: an fd number /&/{name}prefix then the operator), so a program with a redirect GLUED ON (kirocrew>/dev/null "$(printf token)",kirocrew>&2 ...) keeps program position and its basename resolves to the CLI, and the mint is refused; a digit glued to the word (kirocrew2>/dev/null) is part of the program name, so bash runskirocrew2and it stays allowed, as on main._program_positionsfinds the program through the shared_program_indexwalk (relocated toshell_normalizer_walkwith the_WRAPPERStable), so it also steps over wrappers and command keywords (env,sudo,exec,nohup,timeout,!,if): akirocrewbehind one of them takes program position and the quoted-substitution mint is refused, while a harmless wrapped subcommand keeps main's allow. The alternative resolution honours a program-name binding only at a program-position use, through one gate applied to all three reference forms (plain$VAR, transform${V:0}, indirect${!V}) at both the use site and the alias site, with the program-only provenance re-derived from each variable's CURRENT binding alone and never inherited from an earlier one: a shared_set_program_onlyadds the program-only flag for a program-name binding and discards it for anything else, called at every binding site (override, append, computed program/verb, literal), so a variable bound to the program name and then rebound to the mint verb loses the flag and the operand gate resolves it (the fork GPT lane's F1). The transform/indirect resolution added at the alias site runs only in the alternative pass, so the baseline stays unchanged from main._program_basenameand_argv_programswere moved whole intoshell_normalizer_walk(re-exported) to keepshell_normalizerunder its 2,000-line cap; both are pure relocations.Appends and empty assignments (
+=). A+=append and an empty assignment read the same in the baseline and the alternative pass:+=concatenates from the variable's current binding and an empty assignment records nothing, exactly asorigin/main. A+=that assembles the verb from known literals is refused by that concatenation on both main and head (P=tok; P+=en; kirocrew $P,P+=token,P=; P+=token,P=kiro; P+=crew; $P token). A+=whose base or tail is unknown — an unset name, or an opaque substitution such asP+=$($Q)— has no literal to concatenate, so neither pass isolates the verb and the command keeps main's verdict: allowed. The guard's target is a mint whose subcommand comes from a substitution, not one assembled across an opaque append. An earlier round modelled the opaque append (a fail-closed verb binding) and a hand-copied CLI subcommand tree to refuse these spellings; that machinery is removed here, because it refused rowsorigin/mainallows and made the mint-name read quadratic. The mint-name read is now linear: one lookup per$-use into the precomputed program positions, with no rescan of the resolved prefix.Why five security modules change
_program_basenameis defined inshell_normalizer_walk, but_EXPORTSnamedshell_normalizeras its home. So a patch ofsecurity._program_basenamewrote the reader's re-export, whileshell_normalizer_walk._argv_programsread its own binding, andtest_security_split_patch_reachfailed (Backend Tests shard 5)._EXPORTSnow namesshell_normalizer_walk, and every read goes there:shell_normalizer,argv_floor_self,argv_rules,rm_floorands3_direction(plusacp/batch_guard.py, the one reader outside the package). Each call site changes only the module it reads the name from. The function is the same, and the floor's verdicts are the same: deny_diff 0, and 0 flips in either direction over the 20,736-command oracle corpus against the previous head.Also in the diff (from earlier review rounds, unchanged here):
argv_floor_self._is_credential_mintreads a quoted"$(...)"or backtick argument that names the verb where it can be the subcommand. It applies behind a product-name-spelling program word, but not to a redirect target or an interpreter-flag operand, and a glob-only word like*stays allowed.argv_floor.pylists_REDIRECT_OP_PREFIXin theargv_floor_selfmirror manifest.$( )or backticks, or move the mint out of the substituted variable.docs/system-specs/modules/security.mddescribes the two resolutions.ssh self-connection floor: cased-twin judging (for the ssh floor's owner)
argv_floor_ssh._judge_ssh_to_selfnow judges a de-duplicated lowered frame under each DISTINCT cased twin and refuses if any twin refuses — sosudo -E/-eand-H/-h, which lowercase to one frame, are each judged — replacing the earlier "ambiguous frame → None" reading that was fail-open where the lowercase option takes a value; this is a behaviour change in the ssh floor flagged here for its owner (Design lane note).Backwards compatibility
This change only adds refusals. Each row below was measured with
is_deniedon the parent commit and on this head.Newly refused (main allows; bash runs the mint in each):
T=$(: "'"; echo token); kirocrew $T(also${T}, a trailing: "'", andbash -c "kirocrew $T")P=$(echo kirocrew); P=$(: "'"; echo token); kirocrew $P(a var bound to the program name then rebound to the verb; also the three-rebinding chain)2>/dev/null T=$(: "'"; echo token); kirocrew $T(a leading redirection stripped from argv; also1>&2,&>,{fd}>forms — the plain>/dev/nullform was already refused)kirocrew>/dev/null "$(printf token)"(a redirection glued onto the program word; also>&2and a file target)env kirocrew "$(printf token)"(a wrapper/keyword in front of the CLI; alsosudo,command,exec,nohup,time,timeout 5,!,if …; then)T=${U:+"'"}$(printf token); kirocrew $T,T=${U-"'"}$(printf token); kirocrew $TT=$(: "'"; echo 'kirocre[w]'); $T token,T=$(: "'"; echo k*); $T tokenT=$(: ")"; printf token); kirocrew $T(quoted)in the body)T=`: "'"; echo token`; kirocrew $T(backtick body)python -m kiro_crew "$(printf token)"Refused on main and still refused here (the review triggers):
T=`printf %s token`; kirocrew $T; echo "it's done"T=$(: "')"; echo kirocrew); $T tokenT=$(: "')"; echo pkill); $T -f kirocrewT=$(: "'"; : token; echo kirocrew); $T token(decoy) and its>/dev/nullsiblingkirocrew "$(printf token)"and its backtick formResiduals, with the same verdict as main:
T=${KIROCREW:+"'"}$(printf doctor); $T tokenkirocrewfrom the${...}prefix name. The alternative reads only the body (printf doctor), so it binds nothing and adds no refusal. The refusal is main's, kept as is.echo T=$(echo token); kirocrew $Tt=$(echo token)although bash never assigns it, sokirocrew $Treads askirocrew token. The alternative pairs nothing for an argument, so the refusal is main's.T=$(: "'"; echo token; : kirocrew); kirocrew $T$Tbindskirocrew, while bash printstoken. A text-reader limit, covered by the Not-a-goal follow-up.python -m kiro_crew "$(cat <<<token)"and the here-string corpusT=$(echo "it's token"); kirocrew chat -m "$T"kirocrew chat.T=$(echo "it's ok"); grep token f; kirocrew $T,T=$(git log --format="%an's"); git grep token; kirocrew chat -m "$T",T=`echo done`; kirocrew $T; echo "it's"T=doctor; (true; T=$(: "'"; echo token)); kirocrew $T,echo T=$(: "'"; echo token); kirocrew $T,X=$(T=$(: "'"; echo token)); kirocrew $T,f() { T=$(: "'"; echo token); }; kirocrew $T,T=doctor; f(){ T=$(: "'"; echo token); }; kirocrew $Tkirocrew doctoror an unset$T.F=$(ls test/*); pytest $F -k tokenkirocrew2>/dev/null "$(printf token)"kirocrew2, not the CLI — so it is not a mint.coproc worker kirocrew "$(printf token)"coprocas the program (a coproc name needs a compound command, verified on bash 5.2), soworkerruns, not the CLI. The no-namecoproc kirocrew "$(…)"runs the CLI and is refused.P=$(echo kirocrew); P=; P+=token; kirocrew $P,P=; P+=$(: "'"; echo token); kirocrew $P,X=$(echo kirocrew); P=; P+=$($Q); kirocrew $P,P+=$(true),OPTS+=x; kirocrew $OPTS+=has no literal to concatenate, so neither the baseline nor the alternative pass isolates the verb. These return to main's verdict; the round-22/23 machinery (a fail-closed verb binding plus a hand-copied CLI subcommand tree) that refused them is removed.X=$(echo kirocrew); P=; P+=$($Q); kirocrew pod exec w $P,… env kirocrew $P,… kirocrew --json $P,… bash -c "kirocrew $P"+=; allowed in every position (wrapper, redirect, flag,pod/pod exec, module, nested shell, alias), matching main.U=; U+=$(: "'"; echo token); kirocrew $URepo sweep: 3,215 real (non-test) lines that put the verb inside
$( )or backticks were each evaluated in a fresh process under the parent commit and this head. There were zero stable flips in either direction. Two lines,docs/system-specs/modules/memory-skills-hooks.md:4361andsrc/kiro_crew/sandbox_aliases.py:109, read refused-to-allowed in one run. In ten isolated trials per tree, both changed from run to run in main and in this head, because their verdict comes from the exfil host probe, which this diff does not touch.Oracle corpus, both directions: 20,736 commands (each of the 6,912 bodies as
python -m kiro_crew "$(BODY)",T=$(: "'"; BODY); kirocrew $TandT=$(BODY); kirocrew $T), run throughis_deniedon the parent commit and this head: 8,524 allowed-to-refused (the refusals this PR adds) and 0 refused-to-allowed.Generated-corpus trade (unchanged): of 6,912 bodies, 4,577 name the verb while bash captures nothing (
FAIL_CLOSED_DELTA). 86 are allowed although bash captures the verb, because the body computes it without naming it (COMPUTED_VERB_RESIDUAL). 120 name the verb only inside a here-string the static floor cannot read (FLOOR_HERESTRING_RESIDUAL, allowed as on main).Tests
test/test_security_shell_grammar.py::TestMintVerbFromAQuotedSubstitution:test_the_mint_is_refusedcovers every row in the newly-refused table, the six review triggers, the decoy and its siblings, and the quoted-substitution-at-subcommand rows.test_main_residuals_stay_allowedcovers the allowed residuals above.test_an_opaque_append_rides_along_as_main_allowscovers the opaque / unknown-base+=rows (empty-reset, opaque tails,OPTS+=x, and the wrapper /pod exec/ module / alias family) that keep main's allow.test_a_wrapper_with_a_harmless_operand_stays_allowedcovers a wrapper / keyword in front of the CLI running a non-mint subcommand (env kirocrew status,sudo kirocrew doctor,! kirocrew status,if kirocrew status; then …), so the wrapper widening is only the mint shape. The wrapper-mint rows themselves (env kirocrew "$(printf token)"…) are intest_the_mint_is_refused.test_the_operand_resolution_is_linear_per_usepins the per-$-use resolution as linear (interpreter-work counts, not a clock) at sizes whose command text runs past the 8 KiB classified cap, so no per-token rescan of the resolved prefix can return.test_an_argument_shaped_assignment_keeps_mains_refusalpins the balancedecho T=$(echo token)row: the alternative builds no frame, and the verdict stays main's (refused).test_the_alternative_reads_the_body_not_the_value_prefixpins two facts: the alternative binds nothing from${KIROCREW:+...}, and the verdict stays main's (refused).test_the_union_only_adds_frames(curated corpus) andtest_the_union_adds_frames_on_every_repo_substitution_line(everygit grepsubstitution line in the repo) run each command with the alternative switched off and on. Switched off, the walk is main's resolver unchanged. Both tests assert that the frames with it off are a subset of the frames with it on.test/test_security_capture_oracle.py::test_every_command_main_refuses_this_head_refusestakes every oracle body in both assignment forms. For each, it asserts that if the floor refuses with the alternative off, it also refuses with it on.Two tests previously hit CI's 120s per-test timeout on
f9e9a73f07(shard 4 and shard 5); both are now bounded so each instance stays well under it.test_the_union_adds_frames_on_every_repo_substitution_lineis14.79sonf9e9a73f07and14.65shere — this PR's logic does not change its per-line cost, and the lines are pure in-process frame walks with no subprocess to batch — so it is sharded into 8 parametrized instances,max 3.97seach locally.test_every_command_main_refuses_this_head_refusesis41.75sas a single test and is likewise sharded into 8,max 6.22seach. Every shard keeps the identical assertion and per-line/per-command attribution, and the shards partition the corpus. The shard-4 oracle trade testtest_the_trade_against_bash_is_countedwas separately batched (39.14s→7.05s).test_the_floor_binds_on_the_verbs_presenceis likewise sharded into 8 (max 1.6seach locally, from ~12s unsharded) because the fail-closed rule raised the gate's cost on the pathological corpus and it timed out on shard 4 of head3d406deee885; the proof it runs is unchanged, and each shard pins its own slice's here-string residual via a structural_is_herestring_bodypredicate, with the 120-body total pinned bytest_the_here_string_residual_total_is_pinned.With the alternative changed to replace the baseline frame instead of appending one, these property tests fail: 6 of 13, including the oracle corpus test.
The grammar module pins the floor's network seams (
_own_address_probe_stays_localand_resolved_host_verdict), as the denied-command suites do. Both changed test modules pass underKIROCREW_NET_STRICT=1with no off-loopback call.Proof: prove.py PROVEN on head a460e18, via
test/test_security_capture_oracle.py::test_the_floor_binds_on_the_verbs_presenceand the quoted-substitution mint pins intest/test_security_shell_grammar.py::TestMintVerbFromAQuotedSubstitution::test_the_mint_is_refused(including the F1 rebinding trigger), among others.Checks: black, isort, flake8 and mypy are clean on the diff. The 87 security, deny, argv, shell and floor test files pass, and the full facade/bindings suite (
test/*facade*.py test/*_bindings.py test/test_harness_parity.py) passes, with the split-patch, batch-guard and security suites. The budget row is+480, this diff's own net undersrc/kiro_crew/security/*.py(merge-base diff).pre_push_gate --base mainran 26 checks with 0 failures. The nesting test from #37964 passes unchanged on this base.ENV_ASSIGNMENT_REis re-imported at theshell_normalizerfacade. Round 20 carried its only in-module use intoshell_normalizer_walkwith the argv walk and dropped the now-unused import; but it is a frozen public name of that facade's inventory, so the re-export is restored for importers (test_campaign_facades_base_public_names).Whole-corpus monotonicity sweep (main vs head over the 20,736 synthetic mint-shaped probes the oracle generates — each body wrapped in the
kirocrew $T/python -m kiro_crew "$(...)"templates): 8,524 go allowed-to-refused, which are smuggled mints this change now catches, not benign commands that stopped working; 0 go refused-to-allowed, which is the monotonicity guarantee that head refuses a superset of what main refuses.The per-frame cost invariant (
test_denied_commands_security_cost.py::...::test_the_memo_is_declared_inside_the_frame_loop) is kept for_judge_ssh_to_self: the cased-twin pairing added for the ssh union-refuse is preprocessing that builds the judged pairs, so its loop variable islowered, nottokens— it is not a second frame loop, and the per-framedisqualifiedmemo stays inside the one frame loop.Manual verification
N/A. Unit coverage is sufficient: the guard is a pure function, exercised directly with each issue command.
Related Issues
Fixes #36961
Sibling sweep
Swept: git grep -n "_protected_name_in_substitution|_mint_verb_in_substitution|_alternative_mint_overrides|_shell_payload_walk" -- src/
Sibling: src/kiro_crew/security/shell_normalizer.py -- changed here (the alternative resolution and the union frame)
Sibling: src/kiro_crew/security/argv_floor_self.py -- changed here (reads the verb in a quoted substitution); it consumes the walk's frames, so it sees the union
Sibling: src/kiro_crew/security/argv_rules.py -- consumes the same walk; unchanged
Sibling: src/kiro_crew/security/argv_floor.py -- mirror manifest updated here
Pattern harvest
Rule candidate: to harden a static reader without risking a regression, keep the old resolution, add a second one, and refuse if either refuses. Then test monotonicity as frame inclusion with the addition switched off and on, instead of arguing it case by case.
Checklist
Contribution License Agreement
Contributed under the project's Apache-2.0 license.
Takeover
This PR touches
src/kiro_crew/security/*from a fork, and the Sensitive Change Review gate refuses fork PRs on that path by design — a fork PR cannot pass it, and nothing posted here clears it (the same hold as #35356 and #36072). The route to green is a maintainer takeover: a branch on this repository that keeps the author withCo-authored-byand writesSupersedes #37077, runs the real sandbox, and drives that PR green. Every other check and lane on this head is green (local gate 26/0, prove PROVEN, semgrep 0, deny_diff 0, oracle 0 refused-on-main→allowed; both pre-push review lanes APPROVE), so the takeover is a cherry-pick.