Repository navigation
feat: name program and target tokens in self-kill refusal - #16333
iamwhatever wants to merge 2 commits into
Conversation
4e45193 to
2a937ff
Compare
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Check that the hand-copied by-name walk in Suggestions
[DESIGN-REVIEWED] e1fd790 Description read[DESCRIPTION-READ] 9fcea79f65696ee02e78c34aa19f50def220724f3b3bd6c2903ea38cd6f68366 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) — 🟡 CONCERNSPremise-level review of First-Principles-Verdict: CONCERNS The span code re-derives token offsets with a second splitter and a copied walk, then adds guards that catch the two splitters disagreeing. It treats the symptom, not the cause. Not justified as shipped
What this change shipsInventory (6 items) — 4 justifiedIntent: let a reader tell a real self-kill from a false positive by seeing which two tokens tripped the floor. ADDITION.
[FIRST-PRINCIPLES-REVIEWED] e1fd790 Description read[DESCRIPTION-READ] 812197ebd0bbbb9dc79fdc014b62fb63cd147c6bae1ae9a38cc490a0f9a222cf That sha256 names the PR description this verdict read. Recompute it with |
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 TIGHTENING: Nothing gets stricter. The change only adds detail to a refusal message that was already being produced. The new token-span code runs only after the self-protection-kill floor has already said no, and any error inside it is caught ( ADJUDICATED: 15 candidates, 0 confirmed newly-refused PLATFORM COVERAGE: The diff assumes posix shell word-splitting.
The diff makes no platform assumption on the verdict path, so no platform is left unprobed. [SCOPE-REVIEWED] e1fd790 |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsFINDING -- src/kiro_crew/security/argv_spans.py:231 -- For False positive or not applicable? A repository writer can comment: |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
2a937ff to
b7513ef
Compare
buluoray
left a comment
There was a problem hiding this comment.
Summary
Adds program=/target= offset+census fields to the self-protection-kill refusal diagnostic (#14827). The refusal itself is unchanged and nothing leaks: the new code runs only after the floor has already decided to deny, and it emits offsets and character-class counts, never bytes. The problem is the feature's own output. The raw-word/token index alignment in argv_spans._self_kill_token_spans treats "equal word counts" as proof the two lists line up, and that is false for common command shapes. On a multi-line command with a redirect, the refusal names -f as the kill program and > as the target. That is the exact misdiagnosis this PR exists to prevent, and nothing tells the reader it happened.
Verified (at b7513ef)
- Refusal decision unchanged.
src/kiro_crew/security/__init__.py:1435-1454: the span computation sits insideif hit:, after_emit_deny_eventand before the unconditionalreturn _reason(...). It cannot turn a deny into an allow._is_self_kill(argv_floor.py:845) is untouched by the diff. Enforcement is fail-closed. - No new raise path seen. I fuzzed 20,000 random strings over the pkill/killall/quote/
$()/operator/İalphabet through_self_kill_token_spansandis_denied: 0 exceptions.raw_spans[i]/raw_spans[j]are guarded by the length-equality check, andrefusal_diagnosticclamps the new spans. - No secret leakage. I probed
AWS_SECRET_ACCESS_KEY=… pkill -f kirocrew,pkill -f kirocrew --token=ghp_…,pkill -f 'kirocrew.*ghp_…'andkillall kirocrew; echo ghp_…. No secret, product-name or program bytes appear on the diagnostic line. Line 1 (Blocked by security policy: <pattern>) is unchanged.- One residual: when the target is a quoted pattern that embeds a secret,
target=gives a per-token length and class census of that secret. Before, the whole-command census only had it mixed in with everything else. It is coarse and never bytes, so not blocking.
- One residual: when the target is a quoted pattern that embeds a secret,
- Mutation. I made
_self_kill_token_spansreturnNoneimmediately. 5 tests intest/test_denied_commands_security.py::TestSelfProtectionKillDiagnosticSpanswent red:test_pkill_names_program_and_target,test_killall_names_program_and_target,test_variable_resolved_command_names_the_glob_tokens,test_no_new_field_contains_a_command_characterandtest_quoted_pattern_target_brackets_the_raw_quoted_region. Unmutated, the file gives 1325 passed, 1 skipped. I restored the file andgit statusis clean. - Spec.
docs/system-specs/modules/security.mdwas updated in the same commit, as AGENTS.md requires. It names the wrong module (see follow-ups). - CI at the head SHA: 89 success, 10 skipped, 0 failure. Auto-merge is off, there are no human reviews, and the PR shows REVIEW_REQUIRED.
- Tests: I ran only
test/test_denied_commands_security.pylocally. I did not run the full suite.
Blocking
-
src/kiro_crew/security/argv_spans.py:110: equal counts are not an alignment proof, so the fields name the wrong tokens._raw_word_spansand the floor's token walk break words differently:- an active newline becomes a
;token in the walk but gets no raw span; >outand>/dev/nullare one token in the walk but two raw spans.
The differences can cancel, so the counts match while the lists are shifted. Reproduced at this head:
true\npkill -f kirocrew >outgivesprogram=-f,target=>ls -la\npkill -f kirocrew >/dev/nullgivesprogram=-f,target=>
Agent bash commands are routinely multi-line and redirected, so this is not a corner case. A reader trusting
program=is misled in exactly the way #14827 describes.Fix: make the raw splitter mirror the walk (emit a span for an active newline, and keep a redirect plus its target as one word), and check each paired slice before returning it: the raw slice must re-tokenize to its token, or at least contain the program basename and the product name. Return
Noneon any disagreement. Add the two commands above as regression tests. - an active newline becomes a
Bot claims disposition
- Opus FINDING (argv_spans.py:110, misalignment): real. Reproduced as shown above. This is the blocking item.
- GPT FINDING (argv_spans.py:110, same misalignment): real. Same defect, reproduced with its exact example.
- Opus FINDING (
__init__.py:1444, "lower-casing never changes length"): real. Forgrep İstanbul log.txt && pkill -f kirocrew, the fields bracketkillandirocrew, shifted by one, because'İ'.lower()is two code points. It only affects the diagnostic, and only for case-expanding non-ASCII input, so it is a follow-up. Fix: skip the fields whenlen(lower) != len(tool_name), or render againstlower, and correct the comment. - Opus and Fable design FINDING (spec names
argv_floor._self_kill_token_spans): real. The symbol lives inargv_spans. The same wrong module appears in the budget re-pin comment attest/test_security_gate_liveness.py:156. Docs only, so a follow-up. - GPT FINDING (lazy
from . import argv_floorat argv_spans.py:102): real but minor.argv_floordoes not importargv_spans, so there is no cycle that would force a lazy import. The docstring's reason for it (keeping the dependency one-way) holds just as well at module scope. Style only, so a follow-up. - Fable design CONCERNS (mirror drift with no pointer back from
_is_self_kill): real. The two loops are duplicated and nothing fails when they diverge. In fact they already differ in which frames they iterate:_self_token_framesin the floor versus_shell_payload_walkhere. It only affects the diagnostic, so it is a follow-up: add a comment in_is_self_killnaming the mirror, or a conformance test. - First-principles CONCERNS (
RefusalTokenSpanexported with zero consumers): real. A grep finds only its definition, the two export lists and a comment. It is a non-blocking follow-up: drop it from_EXPORTS,EXPORTED_NAMESand the TYPE_CHECKING import. - Security scope PASS: agree. No newly refused operation. The change is post-verdict.
Follow-ups (non-blocking)
- Fix the
İlength mismatch (see above). - Correct the module name in
security.mdand in the liveness re-pin comment. - Add a pointer from
_is_self_killto its mirror, or a conformance test. - Unexport
RefusalTokenSpan. - Move the
argv_floorimport to module scope. - The new span computation is not wrapped. If a future edit makes it raise, the exception escapes
is_deniedfrom inside a deny branch. That breaks the "a diagnostic must never be the thing that raises inside a gate" principle stated inrefusal_diagnostic. Consider atry/except Exception: spans = None. - The PR body says the new class has 10 tests; it has 9.
bolichen97
left a comment
There was a problem hiding this comment.
LGTM. Non-blocking: _self_kill_token_spans runs on the deny path with no guard. refusal_diagnostic promises it never raises inside a gate; this new call can. Consider wrapping it in try/except that returns None, so a parser edge case keeps the plain whole-command span instead of turning a refusal into an exception. (Recent reverts #15232 / #16072 were floors that broke on real-world input; worth the belt-and-braces here.)
Addresses buluoray's review (blocking) and bolichen97's nit on #16333. The self-kill diagnostic aligned raw word spans to the floor's resolved token walk BY INDEX and trusted equal word counts as proof the two lists lined up. They do not: the raw splitter and the walk break words by different rules -- an active newline is a ';' separator token in the walk but was no raw word, and a redirect such as '>out' is one walk token but two raw words -- and the two differences can cancel so the counts match while the slices are shifted. On 'true<newline>pkill -f kirocrew >out' the shift named '-f' the kill program and '>' the target: the exact misdiagnosis the feature exists to prevent. Fix, in two parts: - '_raw_word_spans' now emits a span for an active newline, mirroring the ';' separator token the walk produces, so the two lists no longer shift by one on a multi-line command. - '_self_kill_token_spans' re-tokenises each picked slice before returning it and keeps the pair only when both are a single shell word and the program slice is itself a by-name kill program. A residual shift fails that check and falls back to the whole-command span. The check reads the resolved word, not its bytes, so a $VAR-resolved target still gets a precise offset. Also wrap the span computation in 'is_denied' in a try/except that degrades to the whole-command span, honouring the contract that a refusal diagnostic must never be the thing that raises inside a gate (bolichen97's nit). Tests: two regression cases pin the multi-line+redirect fallback and the multi-line-without-redirect precise span. Docs: correct the module name ('argv_spans', not 'argv_floor') in the spec and the liveness re-pin comment, and re-pin the package line budget to the new measured total. Co-authored-by: iamwhatever <12429733+iamwhatever@users.noreply.github.com>
|
@buluoray thanks — the blocking misalignment is fixed in 2ded6c7. Blocking (equal counts are not alignment). You're right that
Both commands you reproduced now keep the whole-command span with no Follow-ups addressed in the same commit:
Follow-ups left for a separate change (non-blocking, as you flagged them): the dotted-capital case-expansion length mismatch (an |
|
@bolichen97 thanks for the approve and the belt-and-braces nit — done in 2ded6c7. The span computation in |
|
Rebased onto the current @buluoray this is a rebase-only update of the branch you reviewed — would you mind taking another look? Your earlier blocking point about the raw-span / token-walk alignment is addressed by the |
Sensitive Change ReviewSensitive files changed:
How to clear this check:
Only the author's comment counts this way. A reviewer can instead |
|
Self-review (crew-pr-reviewer, read-only): CHANGES NEEDED This PR adds |
Pull request was converted to draft
|
Moved to draft by crew-pr-reviewer: the self-review above is CHANGES NEEDED. GitHub refuses a self-request-changes, and the readiness check ignores human reviews, so draft is how this PR is kept from merging (it also turns auto-merge off). Once the points above are fixed, mark it ready again with |
The self-protection-kill refusal diagnostic now carries additive program and target offset fields with the same char-class census, so a reader can tell a real by-name kill from a glob-argument false positive without running the classifier. A new raw-word-span splitter aligns the resolved frame tokens to their real source offsets by index, so even a shell-variable-resolved glob token is bracketed at its true position. The span field and the first two refusal lines are byte-identical when the fields are omitted, and no field carries a byte of the command. Rebased onto main: the offset machinery moved into a new argv_spans module so argv_floor stays under its per-module line cap, and the security package line budget is re-pinned to the new measured total. Co-authored-by: SaRedfiche <113142267+SaRedfiche@users.noreply.github.com>
Addresses buluoray's review (blocking) and bolichen97's nit on #16333. The self-kill diagnostic aligned raw word spans to the floor's resolved token walk BY INDEX and trusted equal word counts as proof the two lists lined up. They do not: the raw splitter and the walk break words by different rules -- an active newline is a ';' separator token in the walk but was no raw word, and a redirect such as '>out' is one walk token but two raw words -- and the two differences can cancel so the counts match while the slices are shifted. On 'true<newline>pkill -f kirocrew >out' the shift named '-f' the kill program and '>' the target: the exact misdiagnosis the feature exists to prevent. Fix, in two parts: - '_raw_word_spans' now emits a span for an active newline, mirroring the ';' separator token the walk produces, so the two lists no longer shift by one on a multi-line command. - '_self_kill_token_spans' re-tokenises each picked slice before returning it and keeps the pair only when both are a single shell word and the program slice is itself a by-name kill program. A residual shift fails that check and falls back to the whole-command span. The check reads the resolved word, not its bytes, so a $VAR-resolved target still gets a precise offset. Also wrap the span computation in 'is_denied' in a try/except that degrades to the whole-command span, honouring the contract that a refusal diagnostic must never be the thing that raises inside a gate (bolichen97's nit). Tests: two regression cases pin the multi-line+redirect fallback and the multi-line-without-redirect precise span. Docs: correct the module name ('argv_spans', not 'argv_floor') in the spec and the liveness re-pin comment, and re-pin the package line budget to the new measured total. Co-authored-by: iamwhatever <12429733+iamwhatever@users.noreply.github.com>
ea67cdb to
15f762d
Compare
|
Fixed at @buluoray — blocking item (the target slice was never verified): done. Before returning a pair, the picked target word now runs through the same self-name predicate the loop used to pick _SELF_NAME_RE.search(_debracket(w)) or _SELF_NAME_RE.search(_normalize_operand(w))A slice whose resolved word still carries an unresolved
In every one the program slice was still correct; it was the target index that shifted onto Coverage gap: closed. All four are regression tests now, and the mutation you described (disabling the re-tokenise/target check) is killed by them — I re-ran it with Follow-ups, this round:
The verdict (allow/deny) is unchanged — only the reader-facing @buluoray re-requesting your review. |
018efe4 to
2ae900a
Compare
Addresses buluoray's review across two rounds plus bolichen97's nit on the self-kill diagnostic. The diagnostic aligns raw word spans to the floor's resolved token walk by index and must not trust equal word counts as proof the two lists line up: the raw splitter and the walk break words by different rules (an active newline is a separator token in the walk; a redirect such as a trailing `>out` is one walk token but two raw words), and two such differences can cancel so the counts match while the slices are shifted. Alignment fix (first round): - `_raw_word_spans` emits a span for an active newline, mirroring the separator token the walk produces, so the two lists stay index-aligned on a multi-line command. - Before returning a pair, `_self_kill_token_spans` re-tokenises each picked slice and keeps it only when both are a single shell word and the program slice is itself a by-name kill program. - The span computation in `is_denied` is wrapped in `try/except Exception: spans = None` so a parser edge case degrades to the whole-command span instead of raising inside the deny branch. - Spec and the liveness re-pin comment name the correct module. Target verification (second round, buluoray's remaining blocking item): the program slice was verified but the target slice was not, so a shift landing only on the target index (a redirect/here-string/NBSP/comment the raw split and the walk break differently) could still name the wrong token. The picked target word now runs through the same self-name predicate that selects it; an unresolved `$` slice (which cannot be name-matched but is still the resolved target) is accepted, and anything else falls back to the whole-command span. Also in this change: - `__init__` falls back when case-lowering changes the command's length (a dotted-capital I expands to two code points), so an offset computed on the lower-cased string cannot misindex the submitted command. - The facade no longer re-exports `RefusalTokenSpan` (no package-level consumer; the record is internal to `diagnostics`). - A MIRROR comment pins the span module's by-name walk to its twin in `_is_self_kill`; the per-frame-memo invariant keeps that walk from being factored into a shared helper. - Regression tests: buluoray's three target-shift repros plus a fuzz case assert the refusal falls back with no program/target fields; a dotted-capital case asserts the length-shift fallback; the plain case still names the real target. The target check kills a mutation that previously survived. The verdict (allow/deny) is unchanged; only the reader-facing diagnostic fields differ. Co-authored-by: cixuuz <26782336+cixuuz@users.noreply.github.com>
2ae900a to
e1fd790
Compare
|
Closing this. It never changes the allow/deny verdict -- it only adds a target name to the refusal message -- but it adds ~600 lines of command parsing to security code, and each fix has surfaced new edge cases (thanks @buluoray for the careful examples). The cost isn't worth the cosmetic gain. Thanks @chenmingwei23 for the review. Linked enhancement #14827 can stay open if someone wants a smaller approach. |
Problem / Motivation
Goal: Make the self-kill refusal say which token it read as the kill program and which as the target, so a reader can tell a real kill from a false positive without running the classifier.
When the self-protection floor blocks a command, its refusal diagnostic reports only a whole-command
span=0..N. That is enough to see the floor fired, but not why — a reader cannot tell whether the block was a genuinepkill kirocrewor a false positive where an innocent argument (a glob path whose basename is*, next to a path carrying the product name) happened to look like a by-name kill of this gateway.Why it matters
The self-protection floor is meant to stop the agent killing its own supervisor, but a false positive silently blocks ordinary work with no way to diagnose it short of reading the classifier source. Naming the two token offsets turns "this was refused, and here is exactly which two words tripped it" into something a reader can act on.
Not a goal
self-protection-killonly.What changed (motivation → approach → change)
The self-kill refusal reported only a whole-command span, so a false positive gave a reader no way to see which two words the floor keyed on. The fix adds two optional fields to the refusal diagnostic —
program=<a>..<b>andtarget=<c>..<d>— each with the same char-class census the existingspan=already carries.Locating those offsets is the work. A new
_raw_word_spans()splitter walks the shared quote/escape state machine to break the command into shell words at their real source offsets, keeping quoted separators inside their word and an abutting operator as its own span._self_kill_token_spans()then aligns those raw spans to the resolved frame's tokens by index — sound because both derive from the same word split, before per-word variable and tilde resolution — so a variable-resolved token like"$C"/gateway/*is bracketed at its true position even though the product name entered it by$Cexpansion.argv_spans._raw_word_spansargv_spans._self_kill_token_spansNoneto fall backdiagnostics.RefusalTokenSpan+refusal_diagnostic()span=and the first two refusal lines are byte-identical when they are omittedsecurity/__init__.pyself-protection-killonly and threads them throughA leg with no single-token target (bare
kill $(...)) returnsNoneand keeps the whole-command span.docs/system-specs/modules/security.mddocuments the token-level exception in the same change.Rebase note: on current
main,argv_floor.pyhad grown to the edge of its per-module line cap, so the two new offset functions were placed in a newargv_spanssibling module (reached through the existing submodule facade, which keeps the one test seam that patches_data_consumer_exemptobservable). This keepsargv_floor.pyunder its cap; the only behavioural change versus #15055 is the module the two private helpers live in. Thekiro_crew.securitypackage line budget intest_security_gate_liveness.pyis re-pinned to the new measured total with a reason entry.Backwards compatibility
Compatible: the fields are additive and omitted for every floor except
self-protection-kill; thespan=field and the first two refusal lines are byte-identical when they are absent, which the tests pin. Theargv_spanssplit is internal to thekiro_crew.securitypackage and changes no public name.Tests
A
TestSelfProtectionKillDiagnosticSpansclass (13 tests) covers all shapes:pkill -f kirocrewandkillall kirocrewbracket the program and target tokens; the variable-resolved glob command brackets its real source offsets; a quoted ERE pattern brackets its raw region;kill $(pgrep -f kirocrew)and a non-self-kill fall back with no fields; a multi-line command with a redirect (true\npkill -f kirocrew >out) keeps the whole-command span instead of naming the shifted-f/>tokens, while a multi-line command without a cancelling redirect still names the real tokens; every other floor's line stays byte-identical; and_refusal_diagnostic_idstill reads the rule id. buluoray's three target-shift repros (<in,<<<x, NBSP+redirect) plus a fuzz case now assert the refusal falls back to the whole-command span with noprogram=/target=fields, anİcase asserts the length-shift fallback, and the plain case still names the real target; the target-slice check now kills the mutation (disabling it) that previously survived. The denied-command count pin and the keystonetest_sandbox_governance_maskcontinue to hold. Run locally on this head:test_security_gate_liveness.pyandtest_denied_commands_security.pypass (1339 passed, 1 skipped), including the per-module cap and package-budget gates.Manual verification
N/A — unit coverage is sufficient; the change is a diagnostic string and its offset computation, both fully exercised by the new tests against real
is_deniedoutput.Screenshots / video
N/A — no user-visible UI change; the change is a refusal-diagnostic string.
Related Issues
Fixes #14827. Supersedes #15055.
Pattern harvest
Not generalizable: this is a targeted diagnostic enrichment for one floor whose decision is already token-level; the offset-alignment approach is specific to the self-kill by-name leg and does not describe a defect class worth a lint or review rule.
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)Contribution License Agreement
By submitting this pull request, I confirm that my contribution is made under the terms of the project's license.