Repository navigation
fix(security): fold runtime-synthesized targets in bare-kill bodies - #18849
cruisercohen wants to merge 2 commits into
Conversation
Sensitive Change ReviewSensitive files changed:
|
UX Review (Opus 5.5) — ⏭️ skippedRevision |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Nothing blocks. The fix traces to issue #10279 and its tests fail on base. The open Notes
What this change shipsInventory (9 items) — 6 justifiedIntent: stop an agent shell from killing its own gateway through a PID lookup whose process name is assembled at runtime. FIX.
[FIRST-PRINCIPLES-REVIEWED] 52e8f70 Description read[DESCRIPTION-READ] a3b488f55e16c1e9f8e12939602a0a92951a63190f300ead19f7e3dae8c433c2 That sha256 names the PR description this verdict read. Recompute it with |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks: the change only adds denials inside the bare-kill window, the moved brace helpers are still re-exported through Notes
[DESIGN-REVIEWED] 52e8f70 Description read[DESCRIPTION-READ] c2f8517e0ae662a644dadf1c90122a2bc3b0ab02657b89d6ac8b3c62db7033a3 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 |
Sensitive change review
|
Security Scope Review -- ✅ PASSWhich legitimate operations does Verdict basis: adjudicated, zero confirmed regressions. Security scope review -- adjudicated candidates
No candidate flipped from allowed to refused. Scope-Verdict: PASS Reason: The change folds and brace-expands the target of a bare TIGHTENING: Bare-kill window in ADJUDICATED: 23 candidates, 0 confirmed newly-refused PLATFORM COVERAGE: posix (19 rows): the bare-kill shapes maintainers actually run: lsof port kills, PID files, backticks, quoted pgrep patterns, ps|grep|awk with quoted awk braces, a nested UNADJUDICATED: (1) The fail-closed exits in [SCOPE-REVIEWED] 52e8f70 |
GPT 6.1 Review — 🔴 changes requested (blocking)GPT 6.1 found at least one blocking issue that must be resolved before merging This comment is updated in place on each push. BLOCKING -- src/kiro_crew/security/argv_floor_self.py:765 -- Deduplicate comma alternatives before applying the cap
[BLOCK-MERGE] 52e8f70 Adjudication (Opus 5.5) — is blocking on each finding proportionate?I confirmed F1 in the code. It stays blocking and I did not FLAG it, because the evasion is easy for an agent to produce and the fix is small. F1: The residual is justified at False positive or not applicable? A repository writer can comment: |
Opus 5.5 Review — 🔴 changes requested (blocking)Reviewed The bare-kill window still lets two easy forms through: an escaped BLOCKING — src/kiro_crew/security/shell_normalizer.py:1261 BLOCKING — src/kiro_crew/security/kill_synthesis.py:48 [BLOCK-MERGE] 52e8f70 Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
Sensitive change review
|
e06afc6 to
6aa3f41
Compare
Sensitive change review
|
6aa3f41 to
55994d4
Compare
Sensitive change review
|
55994d4 to
5f35904
Compare
Sensitive change review
|
5f35904 to
8f03ee0
Compare
Sensitive change review
|
Sensitive change review
|
Sensitive change review
|
Sensitive change review
|
Review dispositions — head 9ee6b6d
The fix is folded into the second commit, so the PR stays two commits and dropping the second commit remains a clean removal. The floor module stays at 4,498 lines (under the per-module cap) with or without the second commit, and the package line budget is re-pinned to the measured total for each commit. |
Sensitive change review
|
|
This PR is narrowed to its first change, as the maintainer asked: the branch is rebased onto current |
Sensitive change review
|
|
Updated to 6e14657 (still a single commit, on current
All four tests fail on ac51189 and pass on this head. The non-blocking note about a very wide brace group is the documented over-cap case and is unchanged. The line-budget pin is updated for the new base. |
Sensitive change review
|
|
Updated to ea23655 (still a single commit, rebased onto current
The rebase also picks up the main fix for the lazy-import count test that was failing on the previous head. The line-budget pin is updated for the new base. |
|
/ai-review override gpt ea23655: both findings are over-refusals that fail closed: the head refuses a harmless lookup that main allows and never allows anything main refuses; each needs a leading-space assignment or a substitution spliced into a brace endpoint next to the protected name, and is left for a follow-up. |
Human judgment recorded@cruisercohen marked the gpt AI finding as false positive, not applicable, or explicitly accepted for
This decision applies only to this commit. A new push requires a new judgment. |
Sensitive change review
|
|
Rebased onto main 5d899b0. |
Sensitive change review
|
|
On the GPT 6.1 finding for b5903af ( |
|
/ai-review override gpt 9ea08b2: the provider declined to review this head's content and posted no finding (the only GPT comment names the superseded head b5903af). This head is that head plus a fail-closed total-size cap on the assignment resolver and the pure kill_synthesis move; deny_diff vs base 5d899b0 is 0 newly refused and 0 loosenings (posix 45, windows 44). Override of a declined review, not a false allow. |
Human judgment recorded@cruisercohen marked the gpt AI finding as false positive, not applicable, or explicitly accepted for
This decision applies only to this commit. A new push requires a new judgment. |
|
@iamwhatever this is ready for another look when you have a moment: every check is green except the scope aggregator, and the one AI lane that stayed red was a provider decline the owner has overridden on this head. The change is the narrowed bare-kill runtime-synthesis fix with the resolver's total-size cap. Thanks! |
|
Rebased onto main; main split argv_floor.py and shell_normalizer.py into owner modules, so the same change now lives there; no behaviour change. The wrapper, the Sensitive change review
|
|
Rebased onto main c2cedd8 (the only conflict was the package line budget pin in Sensitive change review
|
|
Holding for human review. This PR changes the self-protection kill floor, which decides which shell commands are refused as killing the gateway, and the shared brace expander that the ssh connection-target check also uses. Under the review policy that kind of change is reserved for a maintainer, even though every lane is PASS, Security Scope found 0 newly refused commands, and every check is green at I found no definite defect. The points below are open on this head and would help the human reviewer:
Reviewed head: — crew-pr-reviewer (r117) |
|
Thanks — updated the description on this head ( Brace dedupe on the connection-target check. Declared in the description now. The shared Stale description claims. Corrected. Structural control / residual. The forms a static floor cannot compute exactly stay a documented residual (a The two unanswered notes.
This stays held for your human review. |
A bare `kill` whose PID comes from a substitution could hide the protected name from every static search by assembling it at runtime: a single-literal `printf`/`echo` substitution, a brace expansion, or a same-line variable concatenation. The bare-kill window now folds constant `printf`/`echo` output (reusing the existing static-substitution resolver, guarded to one plain literal) to a bounded fixpoint and brace-expands each word before the name search, deduping identical alternatives so an identical-alternative explosion is one word rather than an over-cap residual. The quote reading that keeps a quoted substitution, brace, comment or escape inert comes from `_iter_shell_chars` -- the module's one quote/escape state machine -- not a second copy. `name=value` is masked as an assignment only in command position, so a `pgrep` argument's braces still expand. The synthesis budget sizes the resolver's own de-quoted, continuation-folded, operator-split tokens, so a chain split across a `\<newline>`, a quoted space or held inside one quoted word is bounded before the eager resolver builds it, and a resolver failure is a deny rather than an empty word list. A body nested deeper than a small substitution depth fails closed before the first fold pass, so the fold stays linear in the body. Brace fan-out is capped before materializing. A parameter word nested in a brace group is masked before expansion (only when its substitution span proves closed) so the enclosing group still expands, matching bash's brace-before-parameter order. Posture: an unresolvable operand and a brace product past the fan-out cap are documented residuals, not failed closed; a nesting or chain that would exceed the fold/character budget fails closed. The reported forms all fit within the cap, and a wider product names no one live process. Fixes #10279
…ize bound The bare-kill synthesis size bound now covers every parameter reference form the resolver expands, so a body is sized in full before anything is built. Fold only a real substitution span the quote mask recorded, ending at that span's own end, so a closing backtick is never read as the opener of the next substitution; and fail the fold closed when the quote mask cannot prove a span, so a body nested past the mask's own cap is refused rather than searched unfolded.
|
Thanks for this PR. It now conflicts with main. Could you rebase onto the latest main and resolve the conflicts? We will review it again once it is rebased and CI is green. |
Problem / Motivation
Goal: A bare
killwhose PID lookup builds the protected process name at runtime is denied by the self-protection floor, while an ordinary variable process pattern stays allowed.The bare-kill window searches each substitution body raw, with parameter defaults resolved, and per word of its tokenized view. All three are static, so a
pgrep/pidoftarget assembled at runtime inside the body, from constantprintf/echosubstitution output or from a brace expansion, matched none of them and the kill was allowed. The same held aftercase … esacin the body. Same-line variable concatenation was already denied through the tokenized view, but nothing pinned it.Why it matters
The floor is what stops an agent shell from terminating its own gateway. Two of the three reported synthesis forms reach that kill today with ordinary shell syntax.
Not a goal
$(cat f),$(rev <<<…)): outside a static floor, documented as the residual.pkill/killallleg, whose operand view is a separate change.What changed (motivation → approach → change)
Symptom: a bare kill whose lookup target is built from constant substitution output or a brace expansion is allowed. Root cause: no member of the bare-kill window evaluates constant substitution output or brace expansion. Change (one commit):
shell_normalizer._fold_const_output_substitutionsreplaces each innermost single-literal$(printf …)/$(echo …)/ backtick substitution with its output, innermost-first to a bounded fixpoint. The output comes from the existingargv_floor._static_substitution_outputresolver, so there is one resolver and no newprintfmodel.shell_normalizer._single_literal_outputguards it to one plain-literal operand (no%conversion, no backslash escape) whose output carries no shell syntax, so a format, multiple operands, an escape, or any other command stays unfolded.argv_floor._kill_body_synthesizes_selffolds each raw bare-kill body BEFORE tokenizing, so the existing local-assignment resolver carries a folded value to a later reference. It then brace-expands every word with the existing_brace_expansions(identical comma alternatives deduplicated) and searches each alternative bare and through_resolved_word_view._iter_shell_chars, the module's one quote/escape state machine, not a second copy:_quote_maskclassifies each position from it and spans substitutions with the shared paren reader. Quoted braces and quoted substitutions stay literal, as in bash; a real comment is inert through its newline; an escaped\$(…)is never folded; a parameter expansion's own word is not brace-expanded; and an assignment's value keeps its braces literal. The shared span walk (_matching_close_paren) reads a$(inside double quotes as its own scope, so a quoted)inside it does not end the kill's window early._BRACE_CHAR_CAP), and a same-line assignment chain whose words together would resolve past it is refused on their lengths alone, before anything is built. Brace fan-out is capped before materializing. The budget belongs to this window only; the connection-target brace check keeps its existing word cap. That check now shares this window's_brace_expansions, so identical comma alternatives are deduplicated for it too. This only removes an over-refusal: every distinct word is still checked and a wide distinct fan-out still fails closed, so no connection target that was refused before is allowed now (a before/after classification over the ssh rows shows 0 newly allowed).main(the line parser and digest inhosts_file, the per-platform resolution inargv_floor_hosts); this PR does not move or change them._kill_body_synthesizes_selfmoves unchanged into a new sibling module,kill_synthesis, behind a one-call wrapper inargv_floor_self(re-exported throughargv_floor) with the same name and signature; the floor's resolver, brace expander and character cap are passed in. The move is mechanical, only to keepargv_floor_selfunder the package's per-file line limit; no reading changes.test_security_gate_liveness.pyis re-pinned to the measured total, with its reason beside it.Posture decision (the issue's fork). Chosen: deny the forms the floor can compute exactly, and do NOT fail closed on an unresolvable operand. Rejected alternative: fail closed on any unresolvable expansion in the
pgrep/pidoftarget position. A process pattern held in a variable is an ordinary benign shape, so that rule would refuse legitimate scripting broadly to close a residual a static floor cannot read anyway. Also considered and left out of this PR: a broader second change that resolved assignment dataflow across control-flow joins; this PR ships the runtime-synthesis fold only.Residual, documented in the spec bullet. Output the fold cannot compute exactly stays outside the floor: a
printfformat, an escaped or multi-word operand,echo -e, any command other than a single-literalprintf/echo, and a brace product past the fan-out cap.Backwards compatibility
Compatible: the change only adds deny verdicts, never removes one. It adds them for bare kills whose lookup target folds or expands to the protected name. Within the bare-kill window it also now fails closed — refuses — when a body exceeds the character budget, the brace fan-out or depth cap, or the resolver bound. A benign unresolvable process pattern is still allowed, as before (the posture decision above), and every command outside the bare-kill window is judged exactly as before.
Removes nothing: the window's existing searches are unchanged and this adds a further member to them; the moved helper keeps its name where callers import it.
Tests
test/test_bare_kill_runtime_synthesis_10279.pydrives the floor andis_denieddirectly; each synthesis row runs both in a plain list and aftercase … esac:printf/echo -n/backtick substitutions, nested and to a nine-deep fixpoint; a folded value carried through a same-line assignment;{,}and{c..c}braces, includingpidof; an argument shaped likename=value(bash does not assign in argument position, so its braces expand); a brace after a leading command-position assignment; a parameter word nested in a brace group; identical alternatives that collapse rather than overflow the cap; quoting edge cases (a quote inside a comment, a quoted/escaped/unterminated${, an ANSI-C escaped quote, a double-quoted)inside a substitution, a subshell's orcasepattern's),$$); and the same-line variable concatenation row (pin).printfformat or escape (not modelled), over-cap numeric and letter ranges, a 300-way replica alternation, an over-cap brace product (a residual), quoting that makes braces or a substitution literal, an assignment value's braces, and the name built in a different command than the kill._single_literal_outputdeclines formats and multiple operands while resolving a single literal.Red without the fix: 56 rows of that file fail with
main's security sources and all pass on this head. The security, denied-command (security, governance, hooks), argv-floor scope, inline-payload, process-lookup and gate-liveness suites pass locally (4,294 passed); ten hook and own-host-read tests fail identically onmainin the local environment only.Manual verification
N/A — the floor is a pure function of the command string, and the unit tests call it directly.
Related Issues
Part of #10279 — this PR closes the three reported synthesis forms (substitution output, brace expansion, same-line variable concatenation); the broader runtime command-output class stays a documented residual, so #10279 remains open to track a structural control as its own design drive.
Pattern harvest
Rule candidate: review-prompt
Pattern: a deny gate whose searches are all static should list, per operand position it guards, which runtime-synthesis forms it resolves and which it pins as residuals.
Checklist
Contribution License Agreement
Contributions are accepted under the project's Apache-2.0 license.