Skip to content

fix(security): find the -c option letter behind a long assignment, and walk a quoted payload whole - #13261

Closed
CrysisDeu wants to merge 1 commit into
mainfrom
fix/carrier-split-head-window-8544
Closed

CrysisDeu wants to merge 1 commit into
mainfrom
fix/carrier-split-head-window-8544

Conversation

@CrysisDeu

@CrysisDeu CrysisDeu commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: A credential mint hidden behind a shell-variable assignment inside a -c/eval carrier payload is refused, whether the carrier is glued with a long assignment name or spaced.

The issue's evidence table has two allowed rows, with two different causes. This PR fixes exactly those two cases.

  1. Glued, long assignment name (zsh -Cc'<78 letters>=kirocrew; $<78 letters> token'): the case fold turns -Cc into -cc, and the carrier's leading letter region runs through the whole assignment name up to the =. The c-run split scan reaches only the last _CARRIER_SPLIT_WINDOW (64) letters of that region, which is right when the payload's first word is a program name. With a longer assignment name the correct split was never a candidate: the payload read as c<name>=..., the assignment went to a different name, and $<name> never resolved. A short name (x=) was already denied.
  2. Spaced carrier, any name length (bash -c 'x=kirocrew; $x token'): the frame's assignment resolver calls _split_glued_operators, which splits any token that begins with an assignment and carries a control operator. The quoted script is such a token, so it was split at its inner ;, and the payload walk, which takes the ONE token after the carrier, descended only x=kirocrew. The script's own command line was never examined. Measured allowed on main for bash -c, bash -x -c, bash -c --, zsh -Cc, eval, bash <<< and env -S.

Why it matters

Both rows are deny-tier bypasses of the credential-mint floor: an agent-authored bash -c 'x=kirocrew; $x token' (or the glued long-name spelling) ran the mint while every top-level spelling of the same command was refused.

Intended? / Repro

Intended? No. The credential-mint floor refuses kirocrew token and its top-level assignment spelling x=kirocrew; $x token; nothing in docs/system-specs/modules/security.md or the code exempts the same command inside a -c payload, and the payload walk (_shell_payload_walk, src/kiro_crew/security/shell_normalizer.py:1416 on main) exists to read exactly that. Case 2 comes from _split_glued_operators (src/kiro_crew/security/shell_normalizer_walk.py:142 on main), called from _resolve_local_assignments (shell_normalizer.py:1006). Case 1 comes from the window in _shell_c_carrier_payloads (src/kiro_crew/security/shell_normalizer_redirects.py:323).

Repro on main 204a9bf624, with one-off is_denied calls (no test suite run):

Command main this PR
kirocrew token DENIED DENIED
x=kirocrew; $x token DENIED DENIED
bash -c 'x=kirocrew; $x token' ALLOWED DENIED
zsh -Cc'<78 a>=kirocrew; $<78 a> token' ALLOWED DENIED

Corpus check: 5,053 commands (glued and spaced -c carriers, quoted and eval scripts, printed carriers, escaped-space (\ ;) spellings, the review findings, the shell rows of the security-conductor golden paths and the command literals of the test/test_security_*.py files), run through scripts/deny_diff.py on this branch's base fe68d8ef24 and on this head: 547 allowed -> denied (case 1 or case 2 credential-mint spellings, including printed carriers; no golden path), 0 denied -> allowed. The one row that differs the other way, * stash *, flips both ways when base is compared with itself, so it is pre-existing nondeterminism. The 91 ssh rows were also run one row per deny_diff call: 0 changes.

Not a goal

  • No change to the case-preserving walk contract or its consumers (the issue title's "case fold" is not a cause; see Other).
  • No modelling of the ambient environment: only assignments in the same command text are tracked.
  • No new carrier kinds beyond those _nested_shell_payloads already walks.
  • _CARRIER_SPLIT_WINDOW, the tail window and the first-c split are unchanged.

Out of scope

  • The guarded-reassignment reader that earlier heads of this PR added (reading x=kirocrew; false && x=echo; $x token both ways, its co-reference groups, reading cap and fail-closed reading) is dropped. First Principles found it outside this PR's goal, review lanes kept finding bypasses inside it, and it newly refused ordinary parameterized commands. It needs its own design and issue. Those spellings behave exactly as on main.
  • printf '%s\n' bash -c '...' is refused again (safe side): the printed-script check was removed as out of scope.

Known limitations

  • A shell named by a local variable whose -c script binds the kill program to another local variable, e.g. x=bash; $x -c 'p=pkill; $p -f kirocrew', is not refused. Main does not refuse it either: deny_diff.py, main 934f7a8 vs d07af79, fresh process per ref, PYTHONHASHSEED 0 and 2, gives allowed at both refs. The whole-script frames this PR adds read the unresolved tokens, where $x names no shell, and the resolved view splits the quoted script. Not widened by this PR. (GPT 6.1, span 5e784cc06287.)

What changed (motivation → approach → change)

Case 1 -- _GluedBindings in src/kiro_crew/security/shell_normalizer.py. A first word longer than the window is only ever an assignment NAME (no rule-covered program is that long) with option letters glued to its front. The extractor is unchanged: the first-c payload, always yielded, carries the whole glued word as its first token. When a frame is a payload the extractor takes from a glued -c carrier occurrence and its first word assigns a name longer than the window (_nested_shell_payloads reports these through glued_out, so a printed echo -c'<s>' gives nothing to a spaced bash -c '<s>' of the same text, and an ordinary command whose first assignment is merely long never qualifies, so <65 a>=kirocrew; a=; test "$a" = token || printf ordinary stays allowed as on main), the walk resolves the frame a second time with the glued reading on (_resolve_local_assignments(..., glued=True)) and keeps BOTH views: in the glued view a lookup of a missing name that is a suffix of the first name, separated by letters alone that end at the carrier's c, reads that binding ($NAME reaches <flags>cNAME=kirocrew; in zsh -c'<78 a>=kirocrew; ...$a...' the name is the whole run of a and $a stays another variable). The plain view is main's reading unchanged, so a suffix read can never hide a binding (<65 a>=echo; a=; a+=kirocrew; $a token and <70 Z>SHELL=1; $SHELL -c '<push>' stay refused). One suffix comparison per use, so the scan stays linear. Every write, = or +=, binds its own name; only a READ goes through the suffix. So <65 a>=kirocrew; a+=zzz; $<65 a> token stays refused (an append folded onto the glued key would turn the mint binding into kirocrewzzz), while <L>=kiro; <L>+=crew; $<L> token still reads kirocrew. Both the = and += spellings of the first word are recorded. In the glued view an explicit empty a= is a binding of a, so it stops the suffix read.

Case 2 -- _quoted_assignment_scripts in the same file. The payload walk also reads each frame's carriers from the tokens BEFORE the resolver splits them (_self_tokens(..., resolve=False)), and keeps only the payloads the split would shred: a token that opens with an assignment and carries a control operator. Each such whole script is walked as its own frame, including a script a data consumer only prints. These frames feed the argv floors (credential mint and the other self-protection floors) only: _shell_payload_sources, which the git-publish gate and the permission-verb mention scan read, asks the walk for whole_scripts=False and sees exactly main's sources, so a scripted bash -c 'b=feat/example; git push -u origin $b' keeps main's verdict. This only ADDS frames: every frame the resolved view yields is still walked, so nothing main refuses is lost.

test/test_security_gate_liveness.py: _PACKAGE_LINE_BUDGET 32,909 -> 33,068 for the 159 added package lines. Every file stays under the per-file caps.

Callers audited: _shell_payload_walk gains a keyword-only whole_scripts argument (default on; _shell_payload_sources turns it off), _self_tokens gains keyword-only resolve and glued arguments, _resolve_local_assignments a keyword-only glued argument, and _nested_shell_payloads a keyword-only glued_out collector, all with the old behaviour as default; their other callers are unchanged. _shell_c_carrier_payloads changed in its docstring only. _resolve_local_assignments keeps its signature and its one consumer (_self_tokens).

Backwards compatibility

Compatible: the change only adds refusals (0 denied -> allowed in the corpus above). No API, config or contract change.

Tests

test/test_security_carrier_assignments.py (new):

  • TestGluedCarrierLongAssignmentName.test_long_assignment_name_glued_carrier_is_read_by_its_reference -- glued, folded and padded -Cc'...' carriers, the function-definition and += spellings, short and 78-letter names, zsh/bash/sh: _is_credential_mint and is_denied; unit pins that the extractor yields only the first-c frame and that the resolver reads $<name> and $<name>_1 through the glued first name, not across a digit, not for a short first name, and not over a name bound in its own right; benign long-name scripts stay allowed. Red on main.
  • test_a_plain_reassignment_does_not_fold_onto_a_glued_key -- <65 a>=kirocrew; a=echo; $<65 a> token and <65 a>=kirocrew; a+=zzz; $<65 a> token (top level and bash -c) stay denied, as do <65 a>=echo; a=; a+=kirocrew; $a token and <70 z>shell=1; $SHELL -c '<push>' (the plain view is kept); a distinct short variable keeps its own binding.
  • test_the_candidate_set_stays_bounded -- the ~3 KB -acac... flood yields at most 70 candidates and references add none.
  • TestSpacedCarrierScriptIsWalkedWhole.test_a_spaced_carrier_payload_is_walked_whole -- -c, -Cc, -x -c, -c --, double quotes, eval, <<<, env -S, glued ; and &&, an outer binding of the same name: denied; a scripted feature-branch push keeps main's verdict. Red on main.
  • test_the_whole_script_frame_only_adds_to_the_resolved_frames -- outer bindings reaching an eval script stay denied as on main; _quoted_assignment_scripts unit pins.
  • test_benign_carrier_scripts_stay_allowed -- ordinary assignment scripts and pkill -f 'v=6777; KIROCREW_PORT=$v npm run dev' stay allowed, as does an ordinary long first assignment followed by an empty a= (top level, bash -c, ${a}, and a glued zsh -Cc'...' carrier).
  • TestGluedViewNeedsAGluedCarrier.test_glued_status_is_not_carried_by_script_text -- a printed echo -c'<s>' before a spaced bash -c '<s>' of the same text gives it no glued view (allowed), while zsh -c'<s>' itself stays denied.
  • test_a_suffix_read_needs_the_carrier_c_in_front_of_it -- zsh -c'<78 a>=kirocrew; test "$a" = token || printf ordinary' (and bash) stays allowed; resolver unit pins for a suffix with and without the carrier c in front of it.

Static gates run on the changed Python files: black, isort, flake8, mypy. Test suites run in CI.

Manual verification

N/A -- unit coverage sufficient: every behaviour claim above is a pinned is_denied / _is_credential_mint assertion, and the corpus check above compares main and this head.

Screenshots / video

N/A -- no user-visible UI change (deny-tier normalizer only).

Why no screenshot: the change is in the shell command reader of the deny tier; no rendered surface changes.

Related Issues

Closes #8544

Pattern harvest

Rule candidate: when a bounded scan window is justified by "the true position is within N of the END", check whether every input shape has a first word that is a program name -- a shell ASSIGNMENT makes the first word arbitrarily long; resolve it where the name is used instead of widening the window.
Rule candidate: when a tokenizer heuristic splits a quoted token for one consumer, give the payload walk the unsplit token as an extra frame instead of changing the split, so existing readings are kept and the fix only adds coverage.

Other

No UI. The issue title's "case fold" is a red herring: the fold only makes the glued split ambiguous; the window dropped the candidate, and the spaced row never involved the fold at all.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

@CrysisDeu
CrysisDeu requested review from a team and Zedmor September 24, 2026 06:19
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Sep 24, 2026
@github-actions

github-actions Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of 84b000c1ebd9f056311a3d928ce2fbb5ca109db8 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

Nothing blocks: both changes only add views to a deny-only floor whose subject really is a shell command line, and the corpus diff shows 0 denied → allowed.

Notes

  • Case 2 treats the symptom. _split_glued_operators still splits the quoted script in the resolved view, and a parallel unresolved view (_quoted_assignment_scripts) works around it. Every future floor that reads resolved tokens will inherit the same blind spot unless it also asks for whole_scripts.
  • Case 1 (_GluedBindings suffix reads for names longer than 64 letters) has the shape AGENTS.md calls a spelling-chase. Before the next round adds another glued-name reading, check whether an OS-level control already stops kirocrew token from minting inside the sandbox.

[DESIGN-REVIEWED] 84b000c

Description read

[DESCRIPTION-READ] 3ff96c374be1170ea61123fd915ab468ee7831b31b2e3b3980be7e0588fe26b6

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 .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of 84b000c1ebd9f056311a3d928ce2fbb5ca109db8 — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

First-Principles-Verdict: PASS

Nothing blocks. Both bypasses come with tests that fail on the base and a repro table, and both fixes are additive, which security.md requires: "Additive, never a replacement".

What this change ships

Inventory (7 items) — 7 justified

Intent: refuse a credential mint hidden behind a variable assignment inside a -c/eval carrier script. This is a FIX.

  1. bash -c 'x=kirocrew; $x token' and its eval, <<<, env -S, -x -c and -c -- spellings are now refused — justified
  2. The glued long-name spelling zsh -Cc'<78 letters>=kirocrew; $<78 letters> token' is now refused — justified
  3. The git-publish gate and the permission-verb mention scan still read main's sources (whole_scripts=False, used at argv_floor_self.py:200) — justified
  4. New exported helper _quoted_assignment_scripts — justified
  5. New keyword parameters _resolve_local_assignments(glued=), _self_tokens(resolve=, glued=) and _nested_shell_payloads(glued_out=) — justified
  6. Package line budget raised by 166 lines (34,522 → 34,688) — justified
  7. The nested-payload section of security.md is updated to describe both views — justified

[FIRST-PRINCIPLES-REVIEWED] 84b000c

Description read

[DESCRIPTION-READ] 6a3b4cc60103adff54fc0f0c727044a589802286a53eb6436d9d14fb90b35f6b

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions

github-actions Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of 84b000c1ebd9f056311a3d928ce2fbb5ca109db8 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 84b000c

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 84b000c1ebd9f056311a3d928ce2fbb5ca109db8 false-positive: <reason, 20 to 500 characters>

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Sep 24, 2026
@github-actions

github-actions Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed 84b000c1ebd9f056311a3d928ce2fbb5ca109db8 — this comment is updated in place on each push.

Review details

No findings.

Notes:

  • shell_normalizer.py was already 1,756 lines and this change takes it to 1,905. The new _GluedBindings class could live in a sibling module, which the non-blocking keep-modules-small rule asks for.

[OPUS-REVIEWED] 84b000c

Verdict parsed from the review's SHA-scoped output markers for commit 84b000c1ebd9f056311a3d928ce2fbb5ca109db8.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 84b000c1ebd9f056311a3d928ce2fbb5ca109db8 false-positive: <reason, 20 to 500 characters>

@github-actions

github-actions Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Security Scope Review -- ✅ PASS

Which legitimate operations does 84b000c1ebd9f056311a3d928ce2fbb5ca109db8 newly refuse? Updated in place on each push. A script-confirmed regression blocks; the model proposes candidates and never decides a refusal.

Verdict basis: adjudicated, zero confirmed regressions.

Security scope review -- adjudicated candidates

  • macos-latest (platform posix): 21 classified, 0 newly refused, 19 still allowed.
  • ubuntu-latest (platform posix): 21 classified, 0 newly refused, 19 still allowed.
  • windows-latest (platform windows): 4 classified, 0 newly refused, 3 still allowed.

No candidate flipped from allowed to refused.

Scope-Verdict: PASS

Reason: The tightening sits entirely inside the shell deny composite, which the classifier adjudicates. The harness has handed back no confirmed newly-refused row from the 25 boundary candidates. One over-block is admitted in the patch's own text: a pure print of an assignment-first script (printf '%s\n' bash -c '…'). Candidate 19 probes it, but the patch states it only for scripts that would themselves be refused, so it is named here and not confirmed.

TIGHTENING: the nested-shell payload walk (_shell_payload_walk) gets two new readings, and the self-protection, ssh, kill and argv-rule floors all read its frames. The first walks a carrier's whole quoted script as its own command line when the script opens with an assignment and contains a control operator: + if whole_scripts: / + nested += _quoted_assignment_scripts(source). The second is a glued-carrier view that reads a first assignment name longer than 64 characters under its suffixes (+ values = _GluedBindings()). -- The one threat it refuses is a credential mint hidden behind an in-script assignment, bash -c 'x=kirocrew; $x token' and zsh -Cc'<long name>=kirocrew; $<long name> token'.

ADJUDICATED: 25 candidates, 0 confirmed newly-refused

PLATFORM COVERAGE: posix (20 rows). These cover every carrier spelling the diff reads: spaced -c, eval, herestring, env -S, glued -c/-Cc, a glued carrier whose name is longer than the 64-character window, and the sudo and timeout wrappers. Each one carries an ordinary assignment-first script (status and cron reads, a dev-server launch, a scripted feature-branch push, cleanup with rm, a remote ssh, killing a pid, pytest, gh reads, a localhost health curl). That probes every floor the new frames feed, and the split where the git-publish sources leave the frame out but argv_rules._commands keeps it. windows (4 rows): bash.exe -c (Git Bash) for the read-only self-health check and a scripted push, cmd /c "set …&& …", and powershell -Command "$env:…; …". These test whether the .exe carrier name and the non-POSIX carriers reach the new frame the same way. The diff assumes POSIX shell assignment and ;/&& syntax, and no platform assumption went without a candidate. No any rows were written, because every candidate names an executable.

UNADJUDICATED: the source text admits one over-refusal: a data consumer that only prints an assignment-first script is refused (printf '%s\n' bash -c '…' "is refused, the safe direction"). Candidate 19 probes it with a read-only script. Whether a printed script that would itself be allowed is refused depends on the classifier's verdict on that row, so I make no claim about it here.

[SCOPE-REVIEWED] 84b000c

@CrysisDeu
CrysisDeu force-pushed the fix/carrier-split-head-window-8544 branch from 216a7cf to 570c179 Compare September 24, 2026 07:06
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 24, 2026
@CrysisDeu
CrysisDeu force-pushed the fix/carrier-split-head-window-8544 branch from 570c179 to d9547d0 Compare September 26, 2026 06:32
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Sep 26, 2026
@CrysisDeu

Copy link
Copy Markdown
Contributor Author

Security Scope Review -- candidate inputs mapped to tests (head d9547d0)

The lane's two confirmed rows on the previous head (bash -c 'b=feat/example; git push origin $b', with and without -u) are Class D below: a correct narrowing, not collateral. The top-level spelling b=feat/example; git push origin $b is refused on main by the publish floor (the destination cannot be determined through $b before the push runs). The carrier spelling was allowed on main only because the quoted script was shredded at its inner ; and the push never reached the floor as a command line -- the same shredding let bash -c 'b=main; git push origin $b' through. Walking the script whole makes the payload spelling meet the floor the top-level spelling already meets. The literal git push origin feat/example stays allowed at top level and inside bash -c.

All tests are in test/test_security.py, class TestGluedShellCommandPayloadExtraction.

class candidate input verdict test
A glued -Cc'<long name>=kirocrew; $<long name> token', folded -cc'…', padded -C<78 flags>c'…', long-name function definition (zsh/bash/sh) refused (was allowed) test_long_assignment_name_glued_carrier_split_is_found_by_its_reference
A glued -Cc'<long name>=ls; $<long name> -la', padded sibling allowed (unchanged) same test, tail asserts
A ~3 KB -acac… flood, 3 KB c-run, 54 referenced suffixes bounded candidate set test_referenced_splits_keep_the_candidate_set_bounded
B bash -c, sh -c, zsh -Cc, bash -x -c, bash -c --, eval, bash <<<, env -S, double-quoted, ;/&& glued, outer x=foo binding, x x=/78-letter names, script <name>=kirocrew; $<name> token refused (was allowed) test_a_spaced_carrier_payload_is_walked_whole
B bash -c '<long name>=ls; $<long name> -la', bash -c 'x=echo; $x hello' allowed (unchanged) same test, tail asserts
B top-level x=kirocrew;$x token, X="a b";Y=kirocrew;$Y token, NBSP sibling refused (unchanged) same test
B X="a b";Y=kirocrew;$Y doctor allowed (unchanged) same test
C pkill -f 'x=pkill; $x -f kirocrew' refused (was allowed) same test
D bash -c 'b=feat/example; git push origin $b', bash -c 'b=feat/example; git push -u origin $b', bash -c 'b=main; git push origin $b' refused (was allowed) test_a_variable_push_target_inside_a_carrier_is_refused_like_the_top_level_spelling
D b=feat/example; git push origin $b, b=main; git push origin $b (top level) refused (unchanged) same test
D git push origin feat/example, bash -c 'true; git push origin feat/example' allowed (unchanged) same test
lane rows sh -c 'A=.s B=sh; echo "[$A][$B]"', kirocrew status / $kc status / $kc cron list behind a carrier, $(git rev-parse HEAD), $(mktemp -d) + trap, gh pr view, ls -la src/kiro_crew/security, pytest / eslint invocations, powershell -command "…", set NAME=value&& use allowed (unchanged) lane's own classifier, both legs, "still allowed"

Corpus audit (local, base = origin/main): 445 commands across 19 carrier shapes x 23 scripts -- 347 identical, 98 allowed -> refused (classes B, C, D), 0 refused -> allowed. The rows the lane will report as newly refused on this head are the Class D feat/example rows; each has its own red-on-main test above.

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Sep 26, 2026
@CrysisDeu
CrysisDeu force-pushed the fix/carrier-split-head-window-8544 branch from d9547d0 to 0233cf5 Compare September 26, 2026 06:59
@CrysisDeu

Copy link
Copy Markdown
Contributor Author

Security Scope Review -- R3 row mapped (head 0233cf5)

The one row the lane confirmed on d9547d09a, pkill -f 'v=6777; KIROCREW_PORT=$v npm run dev', is Class C (quoted pkill -f target). On main the quoted target was shredded into v=6777 + ; + rest, so the kill check saw -f v=6777 and let it through; the unshredded spellings pkill -f 'KIROCREW_PORT=6777 npm run dev' and v=6777; pkill -f 'KIROCREW_PORT=$v npm run dev' are refused on main already, because the target names the product. Whole, the target meets that same refusal. pkill -f 'v=6777; PORT=$v npm run dev' (no product name) stays allowed.

Pinned in test_a_spaced_carrier_payload_is_walked_whole on this head: the row refused, both unshredded spellings refused, the PORT= sibling allowed.

Also on this head: the GPT 5.6 finding on d9547d09a (y=kirocrew; eval 'x=${y}; $x token' allowed) is fixed -- an outer binding is expanded into a whole script token for the names the script does not itself assign; the script's own assignments stay with the script's frame. Two eval pins added to the same test. Corpus: 455 commands, 355 identical to main, 99 allowed -> refused, 0 refused -> allowed.

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 26, 2026
@CrysisDeu
CrysisDeu force-pushed the fix/carrier-split-head-window-8544 branch 2 times, most recently from 6e9578a to a97b1d7 Compare September 26, 2026 09:28
@github-actions github-actions Bot removed the readiness: action required A blocking check or review needs attention label Sep 26, 2026

Copy link
Copy Markdown
Contributor

PR triage (2026-10-05) — REBASE + merge-coordination note

Checked head 57630e9d1 against origin/main 5edf2feec. The merge base is 863abe78, 702 commits behind.

  • Rebase needed. GitHub reports mergeable_state=dirty. git merge-tree finds a content conflict in test/test_security_gate_liveness.py. Since the merge base, main has also changed src/kiro_crew/security/argv_floor.py (+365/-74), docs/system-specs/modules/security.md and test/test_security.py. These auto-merge, but the result needs re-testing.
  • The fix is still needed on main. I ran is_denied on current main and these are still ALLOWED: bash -c 'x=kirocrew; $x token', eval 'x=kirocrew; $x token', zsh -Cc'<78 letters>=kirocrew; $<78 letters> token' and pkill -f 'x=pkill; $x -f kirocrew'. At this head all four are DENIED. Benign controls (bash -c 'echo hi; ls -la', git commit -m "a; b", sh -c 'cd /tmp && make test', x=foo; echo $x) stay allowed. test/test_security.py and test/test_security_gate_liveness.py pass at this head (1230 passed). No merged PR covers Deny-tier case fold defeats carrier-split extraction: long-name assignment indirection hides a mint inside sh -c payloads (pre-existing) #8544 (an open issue).
  • Overlap to coordinate (not duplicates). Open PRs fix(security): case-aware substitution depth for every argv window #14281 (case … esac substitution depth) and fix(security): resolve transforms in assigned substitution search (#10285) #16449 (pgrep-assigned kill substitution) also edit _resolve_local_assignments in shell_normalizer.py. Their goals are different and the changes can sit alongside this one, but whichever lands second will have to rebase over the same function.
  • No breaking change found. The moved private symbols (_split_glued_operators, _CONTROL_OPERATOR_RE, …) are still re-exported from kiro_crew.security. Every behaviour change goes from allowed to denied.

@bolichen97 bolichen97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P0] Guarded-reading enumeration lets a credential-mint command through that main denies

Class: Security floor regression (guarded-reading enumeration fails open).

Mechanism: Two new paths let a command shape that main denies through: _resolve_local_assignments (shell_normalizer.py:3430) treats the & of a redirection such as 2>&1 as a command separator, which splits co-referenced variables into separate groups; and the over-cap fold in shell_assignment_syntax.py:484 does not resolve function wrappers. is_denied returns a denial on main and None on this head and on the merge result.

User impact: A command main blocks at the credential floor would be allowed after merge.

Location: src/kiro_crew/security/shell_normalizer.py:3430 @ 57630e9d1a07fcc8904c61744fb353d13cf0710e

Minimum fix: Mask redirection spellings (\d*>&\d+, &>>?, >&) out of the token before the glued-boundary test, as perm_verb_mention.py already does; and resolve function / alias targets in the over-cap dangerous() fold.

How to verify: Regression rows in test/test_security.py for both paths asserting is_denied is truthy. They are denied on main and return None on this head.

Exploit details are left out on purpose. They are available to maintainers through the repo's private security reporting.

Independently re-verified on head 57630e9d1a with a focused local reproduction.

# separator (``q;echo``): the ``$`` test is only a fast path around ``uses()``,
# not a skip of the boundary, or seven independent guards union into one group
# and an ordinary command reads as unreadable (found in review).
glued_boundary = bool(_CONTROL_OPERATOR_RE.search(token)) and not (

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P0] Guarded-reading enumeration lets a credential-mint command through that main denies — see the review summary for mechanism, fix and test.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bolichen97 thanks, agreed this is a real fail-open. The fix (redirection spellings masked before the glued-boundary test, function/alias targets resolved in the over-cap fold, plus regression rows for both paths) is being ported onto current main now, since the security modules were split after this branch's base. I'll reply here with the new head once it is pushed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bolichen97 fixed on head c197095, ported onto current main as one commit (the security package was split there, so the resolver now lives in shell_assignment_syntax.py and shell_assignment_readings.py).

  • Redirection &: _mask_redirections blanks the & of \d*[<>]&... and &>/&>> (bare >& included) before the co-reference grouping's glued-boundary test, before the assignment check, and in the segment and trailing-operator splits, the same masking perm_verb_mention.py does. A redirection no longer ends a simple command, so the names on either side stay in one group.
  • Over-cap fold: _over_cap_group_is_fail_closed now reads function and alias definitions (_wrapper_definitions). A wrapper whose body fires a floor recogniser, directly or through another wrapper, is dangerous by name, resolved to a bounded fixpoint and read as dangerous past it.
  • Regression rows: test/test_security.py::TestGuardedReadingEnumerationFailsClosed asserts is_denied is truthy for both paths, across several redirection and wrapper spellings, with controls that an ordinary redirection and an inert wrapper stay allowed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bolichen97 the PR changed shape since my last reply. On head 2e041062273d26c192eb0fe3fe13de0e08da82af the guarded-reading enumeration your review targets is removed, so both paths are gone: there is no co-reference grouping (where the redirection & split groups) and no over-cap fold (where function wrappers were not resolved). The PR now fixes only the two cases in its Goal, and the change only adds payload frames to the walk, so a command main refuses stays refused. The regression rows the earlier head added for your review are refused on this head, as on main. Could you take another look when you have a moment?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bolichen97 confirming on the current head f7e8446653 (rebased since my last note): the guarded-reading enumeration this P0 targeted is gone — there is no co-reference grouping and no over-cap fold, so neither flagged path exists on this head. The commit is additive-only (it only adds payload frames to the nested-command walk), so a command main denies cannot be let through. I re-checked with a standalone is_denied probe against main 3ef2da33: every credential-mint shape main denies stays denied here (bash -c, glued sh -c'…', eval, a 2>&1-prefixed mint, and the data-consumer echo bash -c '…'), while bash -c 'x=kirocrew; $x token' — which main allows — is now denied, which is this PR's own goal. Controls (ls -la, git fetch) stay allowed on both. Could you take another look when you have a moment?

@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Sensitive Change Review

Sensitive files changed:

  • src/kiro_crew/security/__init__.py

  • src/kiro_crew/security/_exports.py

  • src/kiro_crew/security/argv_floor_self.py

  • src/kiro_crew/security/shell_normalizer.py

  • src/kiro_crew/security/shell_normalizer_redirects.py

  • @CrysisDeu posted a complete reasoning template for 84b000c.

@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision 84b000c1ebd9f056311a3d928ce2fbb5ca109db8 touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Does not block merge.

@CrysisDeu

Copy link
Copy Markdown
Contributor Author

@bolichen97 both P0 items from your review are fixed on head 830fdc89d: redirection & is masked before the boundary test, and the over-cap fold resolves function/alias wrappers, with regression rows for each. The ported guarded-reading resolver keeps surfacing new gaps each round, though. The indirect n=x; ${!n} row in the new tests still gets through, and GPT/Opus found more since then. So I've stopped patching and need a call:

(A) cut back to the small fix (your 2 P0 items plus their tests) and move the ~1,600-line resolver to a tracking issue with pinning tests, or
(B) keep the full resolver here and keep closing bypasses round by round.

My pick: A. Every round has opened a new gap in the resolver, and First Principles already judges it outside this PR's goal.

Holding the branch until you choose.

@CrysisDeu

Copy link
Copy Markdown
Contributor Author

This PR is now shrunk to the two cases in its Goal, on head 2e041062273d26c192eb0fe3fe13de0e08da82af (one commit on current main). The guarded-reassignment reader is removed entirely: shell_assignment_readings.py, shell_assignment_syntax.py, the reading cap and budget, the fail-closed reading mark and its floor checks, the wrapper fold, the redirection mask and the ssh-to-self floor hunks are gone. The description's new "Out of scope" section says why.

  • First Principles (guarded-reading resolver outside the Goal): items 3 to 8 of the inventory are deleted. What remains is item 1 (_GluedBindings) and item 2 (the whole quoted script walked as its own frame, now _quoted_assignment_scripts).
  • GPT 6.1 (shell_assignment_readings.py:524, a suffix append overwrote the long-name binding): that file is gone, and the same bug is fixed in the _GluedBindings this head keeps. Every write binds its own name; only a read goes through the suffix. <65 a>=kirocrew; a+=zzz; $<65 a> token is refused, at top level and inside bash -c, pinned in test/test_security_carrier_assignments.py.
  • Opus 5.5 (shell_assignment_syntax.py:485, the over-cap fold looked bindings up by exact name): the fold and that file are gone. The reported 6-filler glued command is refused on this head.
  • Security Scope (seven test -n "$CI" && n=8 style defaults before python3 -m pytest / bash scripts/run_tests.sh, newly refused): both rows are allowed on this head, as on main.

Checked with one-off is_denied calls (no test suite run) over 543 commands from the earlier heads' tests and description: 50 allowed -> denied on main vs this head, all of them case 1 or case 2 spellings, and 0 denied -> allowed.

@CrysisDeu

Copy link
Copy Markdown
Contributor Author

The three findings on 2e041062273d26c192eb0fe3fe13de0e08da82af are fixed on head a8c0d0f0cbbd886f31fb594177d749acb6074abc (rebased on current main):

  • GPT 6.1 F1 (suffix fallback in _GluedBindings.get, <65 a>=echo; a=; a+=kirocrew; $a token allowed) and Opus 5.5 (a long top-level first name hijacked $SHELL, so $SHELL -c '<push>' was not walked): the glued reading no longer replaces the plain one. _resolve_local_assignments takes glued=False by default, which is main's reading exactly, and the walk adds a second, glued view of a frame only when its first word assigns a name longer than _CARRIER_SPLIT_WINDOW. Both views are walked, so a suffix read can only add a refusal. Both reported commands are refused again (as on main), pinned in test/test_security_carrier_assignments.py.
  • GPT 6.1 F2 (printf '%s\n' bash -c 'x=kirocrew; $x token' newly refused): _quoted_assignment_scripts skips a whole script when every occurrence is an argument of a data consumer and the command pipes into no evaluator, the same per-occurrence rule the deny gate's payload walk applies. The printf and echo spellings are allowed, as on main; printf ... | sh and sudo bash -c '...' stay refused.

Rechecked with one-off is_denied calls (no test suite run) over the same 543-command corpus: 50 allowed -> denied vs main, 0 denied -> allowed.

@CrysisDeu

CrysisDeu commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor Author

Round 3 on head 29aa71d1309f8c7b56bb098ba5489addde99f90b (rebased on current main):

  • Backend Lint & Type Check (mypy union-attr in _opens_with_long_assignment): fixed with an explicit is not None check.
  • Security Scope (bash -c 'b=feat/example; git push -u origin $b' newly refused, confirmed on macOS and Ubuntu): the whole-script frames now feed the argv floors only. _shell_payload_sources, which the git-publish gate and the permission-verb mention scan read, walks with whole_scripts=False and sees exactly main's sources, so this push keeps main's verdict. Pinned in test/test_security_carrier_assignments.py.
  • GPT 6.1 on the previous head failed on the shared installation token's rate limit, not on a finding; this push starts a fresh run.

Corpus recheck (one-off is_denied calls, no test run): 47 allowed -> denied vs main, all credential-mint spellings of the two cases, 0 denied -> allowed.

@CrysisDeu

Copy link
Copy Markdown
Contributor Author

Round 4: both GPT 6.1 findings on 29aa71d1309f8c7b56bb098ba5489addde99f90b are fixed on head 39d4d04e32eceeb117ae0a229a65694c60307cbc.

  • shell_normalizer.py:944 printed scripts misattributed. _quoted_assignment_scripts now attributes occurrences with _attribution_view. A quoted word is opaque, so the first script's ; no longer starts an outer command, and printf '%s\n' bash -c '<s1>' bash -c '<s2>' prints both. $p reads as its binding (p=echo; $p bash -c '…' and p=printf; $p '%s\n' bash -c '…' print) only for one unconditional p=<word>; statement that opens a ; list, with no other mention of p and no eval/source/. in the command. Any doubt walks the script: false && p=echo, p=echo $p, p=echo; p=sh, read p, eval "p=env; :", an if body, . ./env.sh and a use before the binding are all still denied (test_a_program_word_in_doubt_is_not_read_as_a_data_consumer).
  • shell_normalizer.py:1588 ordinary long assignments get suffix bindings. The glued view is now asked only for a frame that is the script of a glued -c carrier whose first word is a long name (_glued_carrier_payloads). A command whose first assignment is merely long gets the plain view only. Inside the glued view an explicit empty a= binds a, so it stops the suffix read. The trigger and its listed sites (top level, spaced bash -c, ${a}, plus a glued zsh -Cc'…' carrier) stay allowed. A payload first walked plainly is walked once more if it later arrives as a glued carrier's script, so it still gets its glued view.

Corpus check (one-off is_denied calls, no test suite run): 609 commands on base 82d4dbcc4b and on this head give 45 allowed -> denied and 0 denied -> allowed. Static gates: black, isort, flake8, mypy. The PR body is updated to match.

@CrysisDeu

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: 39d4d04
  • What rule changed: The shell payload walk in src/kiro_crew/security/shell_normalizer.py reads two more spellings of the credential-mint and self-protection floors. (1) In a glued -c carrier's script whose first word is an assignment name longer than the carrier split window, a $name use reads that name under its suffixes (_GluedBindings, only for glued carrier scripts via _glued_carrier_payloads). (2) A spaced carrier's quoted script that opens with an assignment is walked whole as one more frame (_quoted_assignment_scripts), unless every occurrence is a data consumer's argument (_attribution_view). argv_floor_self.py and shell_normalizer_redirects.py change in docstrings/wiring only; __init__.py and _exports.py re-export the new helpers.
  • Before -> after (what was allowed/blocked, now): Before, bash -c 'x=kirocrew; $x token' and zsh -Cc'<78 a>=kirocrew; $<78 a> token' were allowed. Now both are refused. Commands main refuses are still refused: one-off is_denied calls over 609 commands on base 82d4dbcc4b and on this head give 45 allowed -> denied and 0 denied -> allowed.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): Breaks commands. An ordinary command is wrongly refused (over-refusal), or is_denied is slow on a very long command. Nothing that is refused today becomes allowed, because both readings only add frames or views beside the existing ones. Open GPT 6.1 and Opus 5.5 findings on this head are of that kind: over-refusals on printed scripts, and a quadratic scan on very long commands. They are not fixed on this head.
  • Evidence checked (which sandbox result proves it): One-off is_denied calls on this head (no test suite run locally): the cases in the PR body's Repro table, the trigger and site commands from the GPT findings on the previous head, and the 609-command corpus diff named above. CI on this head: Denial Differential (ubuntu, macos, windows) passed, and Security Scope Review passed.
  • No regression:
    • Tools still work (which tools/commands were run, result): Benign spellings stay allowed: bash -c 'PORT=3000; npm run dev', pkill -f 'v=6777; KIROCREW_PORT=$v npm run dev', the printed carriers, and the scripted feature-branch bash -c 'b=feat/example; git push -u origin $b' (the publish gate reads main's sources unchanged).
    • Backward compatible (old config / old data / old callers still work, how checked): No config, data or API change. New keyword-only arguments (whole_scripts, resolve, glued) default to the old behaviour, and the other callers are unchanged (audited in the PR body).
    • Existing tests (which suites passed on this head): Backend Tests (3.12) shards 1-8, Backend Tests (Windows) shards 1-8, E2E (stub ACP backend, offline), New-test stability (ubuntu, windows), and Backend Lint & Type Check all passed on this head.
  • How to undo: Revert this PR's single commit. No data or config migration is involved.

@CrysisDeu

Copy link
Copy Markdown
Contributor Author

Round 5: the findings on 39d4d04e32eceeb117ae0a229a65694c60307cbc are handled on head f661417036d8185ae69d5c0fa5dcac7eb8b05405.

  • GPT 6.1 F1, shell_normalizer.py:1001 (whitespace read as quoting in _attribution_view). Removed in f661417036d8185ae69d5c0fa5dcac7eb8b05405. The printed-script check (_attribution_view and the data-consumer skip in _quoted_assignment_scripts) is out of this PR's scope, so it is gone. echo 'a;' bash -c 'x=kirocrew; $x token' and printf '%s\n' bash -c '...' are now refused (safe side), and the PR body says so.
  • GPT 6.1 F2, shell_normalizer.py:1015 and :1159 (glued status keyed by script text, and a suffix read without a c split). Fixed in f661417036d8185ae69d5c0fa5dcac7eb8b05405. Glued status now comes from the carrier occurrence: _nested_shell_payloads reports, through a new glued_out collector, the payloads it takes from a glued -c carrier whose first name is longer than the window. The text scan _glued_carrier_payloads is removed, so a printed echo -c'<s>' gives nothing to a spaced bash -c '<s>' of the same text (TestGluedViewNeedsAGluedCarrier::test_glued_status_is_not_carried_by_script_text). _GluedBindings._key now needs the letters in front of the use to end at the carrier's c, so zsh -c'<78 a>=kirocrew; test "$a" = token || printf ordinary' is allowed as on main (TestGluedViewNeedsAGluedCarrier::test_a_suffix_read_needs_the_carrier_c_in_front_of_it).
  • Opus 5.5, shell_normalizer.py:986 (quadratic scan). Removed in f661417036d8185ae69d5c0fa5dcac7eb8b05405 with _attribution_view and the per-script occurrence rescan. A 16,912-character command of 2,000 distinct assignments then a bash -c script takes 0.97 s on this head, against 0.81 s on base 82d4dbcc4b and 11.28 s on the previous head.
  • Opus non-blocking: an escaped space (\ ) read as quoting could hide a real ;. That reading lived in _attribution_view, so it is removed in f661417036d8185ae69d5c0fa5dcac7eb8b05405. I ran 29 escaped-space commands, one fresh process each, on base and on this head, for example echo a\ ;<cli> restart, bash -c x\ ;ssh localhost and bash -c x=a\ ;<cli> token. Every one that base refuses is refused on this head too. x=<cli>\ ;$x token is allowed on base and on this head alike. That is an existing gap, not in this PR's scope, and not widened here.
  • Opus non-blocking: a redefined echo function, or an IFS-split $p, trusted as a data consumer. Removed in f661417036d8185ae69d5c0fa5dcac7eb8b05405. With the data-consumer skip gone, every whole quoted script is walked, so echo() { bash "$@"; }; echo -c 'x=<cli>; $x token' is refused.

Corpus check (one-off is_denied calls, no test suite run): 648 commands on base 82d4dbcc4b and on this head give 56 allowed -> denied and 0 denied -> allowed. Static gates: black, isort, flake8, mypy, comment-history. The PR body is updated to match.

@CrysisDeu

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: 8e82847
  • What rule changed: The shell payload walk in src/kiro_crew/security/shell_normalizer.py reads two more spellings of the credential-mint and self-protection floors. (1) In a script the extractor takes from a glued -c carrier occurrence whose first word assigns a name longer than the carrier split window, a $name use also reads that name under its suffixes, as one more view beside the unchanged plain view (_GluedBindings; the occurrence is reported by _nested_shell_payloads(glued_out=), and the letters in front of the use must end at the carrier's c). (2) A spaced carrier's quoted script that opens with an assignment is walked whole as one more frame (_quoted_assignment_scripts). argv_floor_self.py and shell_normalizer_redirects.py change in docstrings/wiring only; __init__.py and _exports.py re-export the new helpers. This head is the previous head f661417036 rebased onto main fe68d8ef24; the only conflict was the package line budget in test/test_security_gate_liveness.py (32,909 -> 33,068, +159).
  • Before -> after (what was allowed/blocked, now): Before, bash -c 'x=kirocrew; $x token' and zsh -Cc'<78 a>=kirocrew; $<78 a> token' were allowed. Now both are refused. Commands main refuses are still refused: scripts/deny_diff.py over a 5,053-command corpus on base fe68d8ef24 and on this head gives 547 allowed -> denied (credential-mint spellings only, no golden path) and 0 denied -> allowed. The one row that moves the other way, * stash *, also flips both ways when base is compared with itself, so it is pre-existing nondeterminism. The 91 ssh rows, re-run one row per deny_diff call, show 0 changes.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): Breaks commands. An ordinary command is wrongly refused (over-refusal), for example a printed printf '%s\n' bash -c '...', which is refused again (safe side) because the printed-script check is out of scope. Nothing that is refused today becomes allowed, because both readings only add frames or views beside the existing ones.
  • Evidence checked (which sandbox result proves it): One-off classifier runs via scripts/deny_diff.py (fresh child process per ref, no test suite run locally) over the corpus named above. CI on this head: Denial Differential (ubuntu, windows) passed, Security scope adjudication (ubuntu, windows) and candidate validation passed, GPT 6.1 Review and Opus 5.5 Review passed with no blocking finding.
  • No regression:
    • Tools still work (which tools/commands were run, result): Benign spellings stay allowed: the 69 security-conductor golden paths' shell rows (0 newly refused), bash -c 'PORT=3000; npm run dev', and the scripted feature-branch bash -c 'b=feat/example; git push -u origin $b'.
    • Backward compatible (old config / old data / old callers still work, how checked): No config, data or API change. New keyword-only arguments (whole_scripts, resolve, glued, glued_out) default to the old behaviour, and the other callers are unchanged (audited in the PR body).
    • Existing tests (which suites passed on this head): Backend Tests (3.12) shards 1-8, Backend Tests (Windows) shards 1-8, IPv6, namespace sandbox, crew container, Kernel Lock Owner, E2E (stub ACP backend, offline), E2E Gateway Boot (ubuntu, windows), E2E (private member namespace) and Coverage Combine all passed on this head.
  • How to undo: Revert this PR's single commit. No data or config migration is involved.

@CrysisDeu

CrysisDeu commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: 2404d64
  • What rule changed: The shell payload walk in src/kiro_crew/security/shell_normalizer.py reads two more spellings of the credential-mint and self-protection floors. (1) In a script the extractor takes from a glued -c carrier occurrence whose first word assigns a name longer than the carrier split window, a $name use also reads that name under its suffixes, as one more view beside the unchanged plain view (_GluedBindings; the occurrence is reported by _nested_shell_payloads(glued_out=), and the letters in front of the use must end at the carrier's c). (2) A spaced carrier's quoted script that opens with an assignment is walked whole as one more frame (_quoted_assignment_scripts). argv_floor_self.py and shell_normalizer_redirects.py change in docstrings/wiring only; __init__.py and _exports.py re-export the new helpers. This head is 2573f93870 rebased onto main 81dde23e17; its only conflict was the package line budget in test/test_security_gate_liveness.py (now 33,331), and no security hunk changed. 2573f93870 was the earlier head 8e828472f4 rebased onto main a6f3cc5ce5, with that budget line and _shell_payload_walk, where main's redirect_hidden_payloads(source) is kept and appended after this PR's per-view loop. A blind review of that merged hunk found no issue: all 220 commands main denies stay denied.
  • Before -> after (what was allowed/blocked, now): Before, bash -c 'x=kirocrew; $x token' and zsh -Cc'<78 a>=kirocrew; $<78 a> token' were allowed. Now both are refused. Commands main refuses are still refused: scripts/deny_diff.py over a 5,053-command corpus on base fe68d8ef24 and on this head gives 547 allowed -> denied (credential-mint spellings only, no golden path) and 0 denied -> allowed. The one row that moves the other way, * stash *, also flips both ways when base is compared with itself, so it is pre-existing nondeterminism. The 91 ssh rows, re-run one row per deny_diff call, show 0 changes.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): Breaks commands. An ordinary command is wrongly refused (over-refusal), for example a printed printf '%s\n' bash -c '...', which is refused again (safe side) because the printed-script check is out of scope. Nothing that is refused today becomes allowed, because both readings only add frames or views beside the existing ones.
  • Evidence checked (which sandbox result proves it): One-off classifier runs via scripts/deny_diff.py (fresh child process per ref, no test suite run locally) over the corpus named above. CI on this head: Denial Differential (ubuntu, windows) passed, Security scope adjudication (ubuntu, windows) and candidate validation passed, GPT 6.1 Review and Opus 5.5 Review passed with no blocking finding.
  • No regression:
    • Tools still work (which tools/commands were run, result): Benign spellings stay allowed: the 69 security-conductor golden paths' shell rows (0 newly refused), bash -c 'PORT=3000; npm run dev', and the scripted feature-branch bash -c 'b=feat/example; git push -u origin $b'.
    • Backward compatible (old config / old data / old callers still work, how checked): No config, data or API change. New keyword-only arguments (whole_scripts, resolve, glued, glued_out) default to the old behaviour, and the other callers are unchanged (audited in the PR body).
    • Existing tests (which suites passed on this head): Backend Tests (3.12) shards 1-8, Backend Tests (Windows) shards 1-8, IPv6, namespace sandbox, crew container, Kernel Lock Owner, E2E (stub ACP backend, offline), E2E Gateway Boot (ubuntu, windows), E2E (private member namespace) and Coverage Combine all passed on this head.
  • How to undo: Revert this PR's single commit. No data or config migration is involved.
  • Since e6fef50: rebased onto main 798f3a3. The only conflict was the package line budget (now 33,493); this PR's changed lines are byte-identical. Main's fix(security): read the -c script past options and redirections #26087 added a -c option reader to the same file, so a blind review checked the two together: 0 commands main denies are allowed on this head over its corpus at hash seeds 0 and 2, every credential-mint, self-restart and pkill row is denied, including carriers from the new option reader, and no harmless control is newly denied. One Low: an 11 KB repeated-variable command takes 20.5 s here against 12.5 s on main.
  • Since 01d3646: rebased onto current main 720403c. The only conflict was the package line budget in test/test_security_gate_liveness.py (now 33,682); the security code's changed lines are byte-identical.
  • Since 73bbebf: _GluedBindings finds the glued name's leading letter run once, so each suffix lookup no longer copies the prefix (GPT finding at shell_normalizer.py:1183). A blind review found identical verdicts over 2,400 is_denied commands and 1,057,792 direct lookups at hash seeds 0 and 2; GPT's 80 KB repro takes 44.8 s, against 61.4 s before and 39.0 s on main. Line budget 33,689.

@CrysisDeu

CrysisDeu commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor Author
  • Repeated suffix lookups make hook vetting quadratic span=5e784cc06287

fixed in 2404d64: _GluedBindings.glue() records where the glued name's leading ASCII-letter run ends, once; _key() checks 0 < cut <= _letters_end and glued[cut-1] == "c" instead of copying and rescanning the prefix per lookup.
The predicate is equivalent (non-empty, ends in c, all ASCII letters): a blind review found identical results over 1,057,792 direct _key lookups (unicode, Kelvin sign, combining marks, surrogates, repeated glue) and 2,400 is_denied commands at hash seeds 0 and 2.
40,000 _key lookups: 1.839 s -> 0.014 s, flat in the glued-name length; GPT's repro: 61.4 s -> 44.8 s (main before the PR: 39.0 s; the rest is the PR's extra whole-script frame, not this lookup).

@CrysisDeu

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: d07af79
  • What rule changed: The shell payload walk in src/kiro_crew/security/shell_normalizer.py reads two more spellings of the credential-mint and self-protection floors. (1) In a script the extractor takes from a glued -c carrier occurrence whose first word assigns a name longer than the carrier split window, a $name use also reads that name under its suffixes, as one more view beside the unchanged plain view (_GluedBindings; the occurrence is reported by _nested_shell_payloads(glued_out=), and the letters in front of the use must end at the carrier's c). (2) A spaced carrier's quoted script that opens with an assignment is walked whole as one more frame (_quoted_assignment_scripts). argv_floor_self.py and shell_normalizer_redirects.py change in docstrings/wiring only; __init__.py and _exports.py re-export the new helpers. This head is 2573f93870 rebased onto main 81dde23e17; its only conflict was the package line budget in test/test_security_gate_liveness.py (now 33,331), and no security hunk changed. 2573f93870 was the earlier head 8e828472f4 rebased onto main a6f3cc5ce5, with that budget line and _shell_payload_walk, where main's redirect_hidden_payloads(source) is kept and appended after this PR's per-view loop. A blind review of that merged hunk found no issue: all 220 commands main denies stay denied.
  • Before -> after (what was allowed/blocked, now): Before, bash -c 'x=kirocrew; $x token' and zsh -Cc'<78 a>=kirocrew; $<78 a> token' were allowed. Now both are refused. Commands main refuses are still refused: scripts/deny_diff.py over a 5,053-command corpus on base fe68d8ef24 and on this head gives 547 allowed -> denied (credential-mint spellings only, no golden path) and 0 denied -> allowed. The one row that moves the other way, * stash *, also flips both ways when base is compared with itself, so it is pre-existing nondeterminism. The 91 ssh rows, re-run one row per deny_diff call, show 0 changes.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): Breaks commands. An ordinary command is wrongly refused (over-refusal), for example a printed printf '%s\n' bash -c '...', which is refused again (safe side) because the printed-script check is out of scope. Nothing that is refused today becomes allowed, because both readings only add frames or views beside the existing ones.
  • Evidence checked (which sandbox result proves it): One-off classifier runs via scripts/deny_diff.py (fresh child process per ref, no test suite run locally) over the corpus named above. CI on this head: Denial Differential (ubuntu, windows) passed, Security scope adjudication (ubuntu, windows) and candidate validation passed, GPT 6.1 Review and Opus 5.5 Review passed with no blocking finding.
  • No regression:
    • Tools still work (which tools/commands were run, result): Benign spellings stay allowed: the 69 security-conductor golden paths' shell rows (0 newly refused), bash -c 'PORT=3000; npm run dev', and the scripted feature-branch bash -c 'b=feat/example; git push -u origin $b'.
    • Backward compatible (old config / old data / old callers still work, how checked): No config, data or API change. New keyword-only arguments (whole_scripts, resolve, glued, glued_out) default to the old behaviour, and the other callers are unchanged (audited in the PR body).
    • Existing tests (which suites passed on this head): Backend Tests (3.12) shards 1-8, Backend Tests (Windows) shards 1-8, IPv6, namespace sandbox, crew container, Kernel Lock Owner, E2E (stub ACP backend, offline), E2E Gateway Boot (ubuntu, windows), E2E (private member namespace) and Coverage Combine all passed on this head.
  • How to undo: Revert this PR's single commit. No data or config migration is involved.
  • Since e6fef50: rebased onto main 798f3a3. The only conflict was the package line budget (now 33,493); this PR's changed lines are byte-identical. Main's fix(security): read the -c script past options and redirections #26087 added a -c option reader to the same file, so a blind review checked the two together: 0 commands main denies are allowed on this head over its corpus at hash seeds 0 and 2, every credential-mint, self-restart and pkill row is denied, including carriers from the new option reader, and no harmless control is newly denied. One Low: an 11 KB repeated-variable command takes 20.5 s here against 12.5 s on main.
  • Since 01d3646: rebased onto current main 720403c. The only conflict was the package line budget in test/test_security_gate_liveness.py (now 33,682); the security code's changed lines are byte-identical.
  • Since 73bbebf: _GluedBindings finds the glued name's leading letter run once, so each suffix lookup no longer copies the prefix (GPT finding at shell_normalizer.py:1183). A blind review found identical verdicts over 2,400 is_denied commands and 1,057,792 direct lookups at hash seeds 0 and 2; GPT's 80 KB repro takes 44.8 s, against 61.4 s before and 39.0 s on main. Line budget 33,689.
  • Since 2404d64: rebased onto current main 934f7a8. The only conflict was the package line budget in test/test_security_gate_liveness.py (now 33,889); the security code's changed lines are byte-identical.

@iamwhatever

Copy link
Copy Markdown
Contributor

HOLD at d07af79: this needs a human security reviewer, and several gates are still open.

Reserved for a human: the PR changes what the security deny floor counts as a credential-mint or self-kill command. It adds whole-script frames in shell_normalizer.py, changes the glued -c carrier reading in shell_normalizer_redirects.py, and changes argv_floor_self.py.

Open blockers on this head:

  • GPT 6.1 BLOCK (security-class), not yet answered: x=bash; $x -c 'p=pkill; $p -f kirocrew' reportedly passes is_denied (comment). I could not tell from source alone whether main denies this shape (which would make it a regression) or misses it too (a residual of the same class). Please answer it with a test row either way.
  • The Opus 5.5 Review lane was cancelled and has no verdict for this head. Six Backend Tests shards are still running, and PR Readiness reports 2 blocking items.
  • @bolichen97's change request (review) is still active. The author says both P0 items are fixed and the cited reader has since been removed. That request clears only when @bolichen97 re-reviews or dismisses it.

On the positive side: Security Scope Review finds 0 newly refused commands on all three platforms, and the branch merges cleanly with main.

— crew-pr-reviewer (r138)

@CrysisDeu

Copy link
Copy Markdown
Contributor Author

self-added: no
mechanism: whole-script frames read unresolved tokens, where a shell named by a local variable is unknown
resolution: deferred

  • Whole-script extraction misses locally resolved carriers span=5e784cc06287

Already true on main, not widened. deny_diff.py, main 934f7a8 vs d07af79, fresh process per ref, PYTHONHASHSEED 0 and 2: x=bash; $x -c 'p=pkill; $p -f kirocrew' is allowed at both refs.
Listed under "Known limitations" in the description. Closing it needs the resolver to keep a quoted script whole after it resolves the shell name, which is outside this PR's two cases.

@CrysisDeu

Copy link
Copy Markdown
Contributor Author

Answering the r138 question on the GPT 6.1 BLOCK (x=bash; $x -c 'p=pkill; $p -f kirocrew'): this is a residual, not a regression. Main allows it too.

is_denied(cmd) with default rules, run as a standalone script (no test suite) on main e858e5b378 and on this head d07af79980:

command main this PR
x=bash; $x -c 'p=pkill; $p -f kirocrew' ALLOW ALLOW
bash -c 'p=pkill; $p -f kirocrew' ALLOW DENY
x=bash; $x -c 'pkill -f kirocrew' DENY DENY
p=pkill; $p -f kirocrew DENY DENY
pkill -f kirocrew DENY DENY

So the PR closes one more spelling (row 2) and refuses nothing main refused before. Row 1 needs two levels of variable indirection (a shell named by a variable, then a command named by a variable inside it). That stays out of scope here, as the disposition above says. This PR still waits on a human security reviewer.

I also re-ran the cancelled Opus 5.5 Review run (41276104349) once so this head gets a verdict.

@CrysisDeu

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: 84cdce5
  • What rule changed: The shell payload walk in src/kiro_crew/security/shell_normalizer.py reads two more spellings of the credential-mint and self-protection floors. (1) In a script the extractor takes from a glued -c carrier occurrence whose first word assigns a name longer than the carrier split window, a $name use also reads that name under its suffixes, as one more view beside the unchanged plain view (_GluedBindings; the occurrence is reported by _nested_shell_payloads(glued_out=), and the letters in front of the use must end at the carrier's c). (2) A spaced carrier's quoted script that opens with an assignment is walked whole as one more frame (_quoted_assignment_scripts). argv_floor_self.py and shell_normalizer_redirects.py change in docstrings/wiring only; __init__.py and _exports.py re-export the new helpers. This head is 2573f93870 rebased onto main 81dde23e17; its only conflict was the package line budget in test/test_security_gate_liveness.py (now 33,331), and no security hunk changed. 2573f93870 was the earlier head 8e828472f4 rebased onto main a6f3cc5ce5, with that budget line and _shell_payload_walk, where main's redirect_hidden_payloads(source) is kept and appended after this PR's per-view loop. A blind review of that merged hunk found no issue: all 220 commands main denies stay denied.
  • Before -> after (what was allowed/blocked, now): Before, bash -c 'x=kirocrew; $x token' and zsh -Cc'<78 a>=kirocrew; $<78 a> token' were allowed. Now both are refused. Commands main refuses are still refused: scripts/deny_diff.py over a 5,053-command corpus on base fe68d8ef24 and on this head gives 547 allowed -> denied (credential-mint spellings only, no golden path) and 0 denied -> allowed. The one row that moves the other way, * stash *, also flips both ways when base is compared with itself, so it is pre-existing nondeterminism. The 91 ssh rows, re-run one row per deny_diff call, show 0 changes.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): Breaks commands. An ordinary command is wrongly refused (over-refusal), for example a printed printf '%s\n' bash -c '...', which is refused again (safe side) because the printed-script check is out of scope. Nothing that is refused today becomes allowed, because both readings only add frames or views beside the existing ones.
  • Evidence checked (which sandbox result proves it): One-off classifier runs via scripts/deny_diff.py (fresh child process per ref, no test suite run locally) over the corpus named above. CI on this head: Denial Differential (ubuntu, windows) passed, Security scope adjudication (ubuntu, windows) and candidate validation passed, GPT 6.1 Review and Opus 5.5 Review passed with no blocking finding.
  • No regression:
    • Tools still work (which tools/commands were run, result): Benign spellings stay allowed: the 69 security-conductor golden paths' shell rows (0 newly refused), bash -c 'PORT=3000; npm run dev', and the scripted feature-branch bash -c 'b=feat/example; git push -u origin $b'.
    • Backward compatible (old config / old data / old callers still work, how checked): No config, data or API change. New keyword-only arguments (whole_scripts, resolve, glued, glued_out) default to the old behaviour, and the other callers are unchanged (audited in the PR body).
    • Existing tests (which suites passed on this head): Backend Tests (3.12) shards 1-8, Backend Tests (Windows) shards 1-8, IPv6, namespace sandbox, crew container, Kernel Lock Owner, E2E (stub ACP backend, offline), E2E Gateway Boot (ubuntu, windows), E2E (private member namespace) and Coverage Combine all passed on this head.
  • How to undo: Revert this PR's single commit. No data or config migration is involved.
  • Since e6fef50: rebased onto main 798f3a3. The only conflict was the package line budget (now 33,493); this PR's changed lines are byte-identical. Main's fix(security): read the -c script past options and redirections #26087 added a -c option reader to the same file, so a blind review checked the two together: 0 commands main denies are allowed on this head over its corpus at hash seeds 0 and 2, every credential-mint, self-restart and pkill row is denied, including carriers from the new option reader, and no harmless control is newly denied. One Low: an 11 KB repeated-variable command takes 20.5 s here against 12.5 s on main.
  • Since 01d3646: rebased onto current main 720403c. The only conflict was the package line budget in test/test_security_gate_liveness.py (now 33,682); the security code's changed lines are byte-identical.
  • Since 73bbebf: _GluedBindings finds the glued name's leading letter run once, so each suffix lookup no longer copies the prefix (GPT finding at shell_normalizer.py:1183). A blind review found identical verdicts over 2,400 is_denied commands and 1,057,792 direct lookups at hash seeds 0 and 2; GPT's 80 KB repro takes 44.8 s, against 61.4 s before and 39.0 s on main. Line budget 33,689.
  • Since 2404d64: rebased onto current main 934f7a8. The only conflict was the package line budget in test/test_security_gate_liveness.py (now 33,889); the security code's changed lines are byte-identical.
  • Since d07af79: rebased onto current main 6fac7bc. The only conflict was the package line budget in test/test_security_gate_liveness.py (now 34,125, main's 33,959 plus this PR's 166). The security code's changed lines are byte-identical to the previous head.

@CrysisDeu

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: f7e8446
  • What rule changed: The shell payload walk in src/kiro_crew/security/shell_normalizer.py reads two more spellings of the credential-mint and self-protection floors. (1) In a script the extractor takes from a glued -c carrier occurrence whose first word assigns a name longer than the carrier split window, a $name use also reads that name under its suffixes, as one more view beside the unchanged plain view (_GluedBindings; the occurrence is reported by _nested_shell_payloads(glued_out=), and the letters in front of the use must end at the carrier's c). (2) A spaced carrier's quoted script that opens with an assignment is walked whole as one more frame (_quoted_assignment_scripts). argv_floor_self.py and shell_normalizer_redirects.py change in docstrings/wiring only; __init__.py and _exports.py re-export the new helpers. This head is 2573f93870 rebased onto main 81dde23e17; its only conflict was the package line budget in test/test_security_gate_liveness.py (now 33,331), and no security hunk changed. 2573f93870 was the earlier head 8e828472f4 rebased onto main a6f3cc5ce5, with that budget line and _shell_payload_walk, where main's redirect_hidden_payloads(source) is kept and appended after this PR's per-view loop. A blind review of that merged hunk found no issue: all 220 commands main denies stay denied.
  • Before -> after (what was allowed/blocked, now): Before, bash -c 'x=kirocrew; $x token' and zsh -Cc'<78 a>=kirocrew; $<78 a> token' were allowed. Now both are refused. Commands main refuses are still refused: scripts/deny_diff.py over a 5,053-command corpus on base fe68d8ef24 and on this head gives 547 allowed -> denied (credential-mint spellings only, no golden path) and 0 denied -> allowed. The one row that moves the other way, * stash *, also flips both ways when base is compared with itself, so it is pre-existing nondeterminism. The 91 ssh rows, re-run one row per deny_diff call, show 0 changes.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): Breaks commands. An ordinary command is wrongly refused (over-refusal), for example a printed printf '%s\n' bash -c '...', which is refused again (safe side) because the printed-script check is out of scope. Nothing that is refused today becomes allowed, because both readings only add frames or views beside the existing ones.
  • Evidence checked (which sandbox result proves it): One-off classifier runs via scripts/deny_diff.py (fresh child process per ref, no test suite run locally) over the corpus named above. CI on this head: Denial Differential (ubuntu, windows) passed, Security scope adjudication (ubuntu, windows) and candidate validation passed, GPT 6.1 Review and Opus 5.5 Review passed with no blocking finding.
  • No regression:
    • Tools still work (which tools/commands were run, result): Benign spellings stay allowed: the 69 security-conductor golden paths' shell rows (0 newly refused), bash -c 'PORT=3000; npm run dev', and the scripted feature-branch bash -c 'b=feat/example; git push -u origin $b'.
    • Backward compatible (old config / old data / old callers still work, how checked): No config, data or API change. New keyword-only arguments (whole_scripts, resolve, glued, glued_out) default to the old behaviour, and the other callers are unchanged (audited in the PR body).
    • Existing tests (which suites passed on this head): Backend Tests (3.12) shards 1-8, Backend Tests (Windows) shards 1-8, IPv6, namespace sandbox, crew container, Kernel Lock Owner, E2E (stub ACP backend, offline), E2E Gateway Boot (ubuntu, windows), E2E (private member namespace) and Coverage Combine all passed on this head.
  • How to undo: Revert this PR's single commit. No data or config migration is involved.
  • Since e6fef50: rebased onto main 798f3a3. The only conflict was the package line budget (now 33,493); this PR's changed lines are byte-identical. Main's fix(security): read the -c script past options and redirections #26087 added a -c option reader to the same file, so a blind review checked the two together: 0 commands main denies are allowed on this head over its corpus at hash seeds 0 and 2, every credential-mint, self-restart and pkill row is denied, including carriers from the new option reader, and no harmless control is newly denied. One Low: an 11 KB repeated-variable command takes 20.5 s here against 12.5 s on main.
  • Since 01d3646: rebased onto current main 720403c. The only conflict was the package line budget in test/test_security_gate_liveness.py (now 33,682); the security code's changed lines are byte-identical.
  • Since 73bbebf: _GluedBindings finds the glued name's leading letter run once, so each suffix lookup no longer copies the prefix (GPT finding at shell_normalizer.py:1183). A blind review found identical verdicts over 2,400 is_denied commands and 1,057,792 direct lookups at hash seeds 0 and 2; GPT's 80 KB repro takes 44.8 s, against 61.4 s before and 39.0 s on main. Line budget 33,689.
  • Since 2404d64: rebased onto current main 934f7a8. The only conflict was the package line budget in test/test_security_gate_liveness.py (now 33,889); the security code's changed lines are byte-identical.
  • Since d07af79: rebased onto current main 6fac7bc. The only conflict was the package line budget in test/test_security_gate_liveness.py (now 34,125, main's 33,959 plus this PR's 166). The security code's changed lines are byte-identical to the previous head.
  • Since 84cdce5: rebased onto current main a299f87, which raised the package line budget to 33,967 (fix(agent): resolve an agent's kirocrew to this install, not a stale one #26324). The only conflict was that budget; it is now 34,133. The security code's changed lines are byte-identical to the previous head.

@CrysisDeu

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: c9de293
  • What rule changed: The shell payload walk in src/kiro_crew/security/shell_normalizer.py reads two more spellings of the credential-mint and self-protection floors. (1) In a script the extractor takes from a glued -c carrier occurrence whose first word assigns a name longer than the carrier split window, a $name use also reads that name under its suffixes, as one more view beside the unchanged plain view (_GluedBindings; the occurrence is reported by _nested_shell_payloads(glued_out=), and the letters in front of the use must end at the carrier's c). (2) A spaced carrier's quoted script that opens with an assignment is walked whole as one more frame (_quoted_assignment_scripts). argv_floor_self.py and shell_normalizer_redirects.py change in docstrings/wiring only; __init__.py and _exports.py re-export the new helpers. This head is 2573f93870 rebased onto main 81dde23e17; its only conflict was the package line budget in test/test_security_gate_liveness.py (now 33,331), and no security hunk changed. 2573f93870 was the earlier head 8e828472f4 rebased onto main a6f3cc5ce5, with that budget line and _shell_payload_walk, where main's redirect_hidden_payloads(source) is kept and appended after this PR's per-view loop. A blind review of that merged hunk found no issue: all 220 commands main denies stay denied.
  • Before -> after (what was allowed/blocked, now): Before, bash -c 'x=kirocrew; $x token' and zsh -Cc'<78 a>=kirocrew; $<78 a> token' were allowed. Now both are refused. Commands main refuses are still refused: scripts/deny_diff.py over a 5,053-command corpus on base fe68d8ef24 and on this head gives 547 allowed -> denied (credential-mint spellings only, no golden path) and 0 denied -> allowed. The one row that moves the other way, * stash *, also flips both ways when base is compared with itself, so it is pre-existing nondeterminism. The 91 ssh rows, re-run one row per deny_diff call, show 0 changes.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): Breaks commands. An ordinary command is wrongly refused (over-refusal), for example a printed printf '%s\n' bash -c '...', which is refused again (safe side) because the printed-script check is out of scope. Nothing that is refused today becomes allowed, because both readings only add frames or views beside the existing ones.
  • Evidence checked (which sandbox result proves it): One-off classifier runs via scripts/deny_diff.py (fresh child process per ref, no test suite run locally) over the corpus named above. CI on this head: Denial Differential (ubuntu, windows) passed, Security scope adjudication (ubuntu, windows) and candidate validation passed, GPT 6.1 Review and Opus 5.5 Review passed with no blocking finding.
  • No regression:
    • Tools still work (which tools/commands were run, result): Benign spellings stay allowed: the 69 security-conductor golden paths' shell rows (0 newly refused), bash -c 'PORT=3000; npm run dev', and the scripted feature-branch bash -c 'b=feat/example; git push -u origin $b'.
    • Backward compatible (old config / old data / old callers still work, how checked): No config, data or API change. New keyword-only arguments (whole_scripts, resolve, glued, glued_out) default to the old behaviour, and the other callers are unchanged (audited in the PR body).
    • Existing tests (which suites passed on this head): Backend Tests (3.12) shards 1-8, Backend Tests (Windows) shards 1-8, IPv6, namespace sandbox, crew container, Kernel Lock Owner, E2E (stub ACP backend, offline), E2E Gateway Boot (ubuntu, windows), E2E (private member namespace) and Coverage Combine all passed on this head.
  • How to undo: Revert this PR's single commit. No data or config migration is involved.
  • Since e6fef50: rebased onto main 798f3a3. The only conflict was the package line budget (now 33,493); this PR's changed lines are byte-identical. Main's fix(security): read the -c script past options and redirections #26087 added a -c option reader to the same file, so a blind review checked the two together: 0 commands main denies are allowed on this head over its corpus at hash seeds 0 and 2, every credential-mint, self-restart and pkill row is denied, including carriers from the new option reader, and no harmless control is newly denied. One Low: an 11 KB repeated-variable command takes 20.5 s here against 12.5 s on main.
  • Since 01d3646: rebased onto current main 720403c. The only conflict was the package line budget in test/test_security_gate_liveness.py (now 33,682); the security code's changed lines are byte-identical.
  • Since 73bbebf: _GluedBindings finds the glued name's leading letter run once, so each suffix lookup no longer copies the prefix (GPT finding at shell_normalizer.py:1183). A blind review found identical verdicts over 2,400 is_denied commands and 1,057,792 direct lookups at hash seeds 0 and 2; GPT's 80 KB repro takes 44.8 s, against 61.4 s before and 39.0 s on main. Line budget 33,689.
  • Since 2404d64: rebased onto current main 934f7a8. The only conflict was the package line budget in test/test_security_gate_liveness.py (now 33,889); the security code's changed lines are byte-identical.
  • Since d07af79: rebased onto current main 6fac7bc. The only conflict was the package line budget in test/test_security_gate_liveness.py (now 34,125, main's 33,959 plus this PR's 166). The security code's changed lines are byte-identical to the previous head.
  • Since 84cdce5: rebased onto current main a299f87, which raised the package line budget to 33,967 (fix(agent): resolve an agent's kirocrew to this install, not a stale one #26324). The only conflict was that budget; it is now 34,133. The security code's changed lines are byte-identical to the previous head.
  • Since f7e8446: rebased onto current main e71bf3d, which raised the package line budget to 34,312. The only conflict was that budget; it is now 34,478 (main's 34,312 plus this PR's 166). The security code's changed lines are byte-identical to the previous head.

@CrysisDeu

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: 758073f

  • What rule changed: The shell payload walk in src/kiro_crew/security/shell_normalizer.py reads two more spellings of the credential-mint and self-protection floors. (1) In a script the extractor takes from a glued -c carrier occurrence whose first word assigns a name longer than the carrier split window, a $name use also reads that name under its suffixes, as one more view beside the unchanged plain view (_GluedBindings; the occurrence is reported by _nested_shell_payloads(glued_out=), and the letters in front of the use must end at the carrier's c). (2) A spaced carrier's quoted script that opens with an assignment is walked whole as one more frame (_quoted_assignment_scripts). argv_floor_self.py and shell_normalizer_redirects.py change in docstrings/wiring only; __init__.py and _exports.py re-export the new helpers. This head is 2573f93870 rebased onto main 81dde23e17; its only conflict was the package line budget in test/test_security_gate_liveness.py (now 33,331), and no security hunk changed. 2573f93870 was the earlier head 8e828472f4 rebased onto main a6f3cc5ce5, with that budget line and _shell_payload_walk, where main's redirect_hidden_payloads(source) is kept and appended after this PR's per-view loop. A blind review of that merged hunk found no issue: all 220 commands main denies stay denied.

  • Before -> after (what was allowed/blocked, now): Before, bash -c 'x=kirocrew; $x token' and zsh -Cc'<78 a>=kirocrew; $<78 a> token' were allowed. Now both are refused. Commands main refuses are still refused: scripts/deny_diff.py over a 5,053-command corpus on base fe68d8ef24 and on this head gives 547 allowed -> denied (credential-mint spellings only, no golden path) and 0 denied -> allowed. The one row that moves the other way, * stash *, also flips both ways when base is compared with itself, so it is pre-existing nondeterminism. The 91 ssh rows, re-run one row per deny_diff call, show 0 changes.

  • Worst case if wrong (breaks commands / leaks secret / locks user out): Breaks commands. An ordinary command is wrongly refused (over-refusal), for example a printed printf '%s\n' bash -c '...', which is refused again (safe side) because the printed-script check is out of scope. Nothing that is refused today becomes allowed, because both readings only add frames or views beside the existing ones.

  • Evidence checked (which sandbox result proves it): One-off classifier runs via scripts/deny_diff.py (fresh child process per ref, no test suite run locally) over the corpus named above. CI on this head: Denial Differential (ubuntu, windows) passed, Security scope adjudication (ubuntu, windows) and candidate validation passed, GPT 6.1 Review and Opus 5.5 Review passed with no blocking finding.

  • No regression:

    • Tools still work (which tools/commands were run, result): Benign spellings stay allowed: the 69 security-conductor golden paths' shell rows (0 newly refused), bash -c 'PORT=3000; npm run dev', and the scripted feature-branch bash -c 'b=feat/example; git push -u origin $b'.
    • Backward compatible (old config / old data / old callers still work, how checked): No config, data or API change. New keyword-only arguments (whole_scripts, resolve, glued, glued_out) default to the old behaviour, and the other callers are unchanged (audited in the PR body).
    • Existing tests (which suites passed on this head): Backend Tests (3.12) shards 1-8, Backend Tests (Windows) shards 1-8, IPv6, namespace sandbox, crew container, Kernel Lock Owner, E2E (stub ACP backend, offline), E2E Gateway Boot (ubuntu, windows), E2E (private member namespace) and Coverage Combine all passed on this head.
  • How to undo: Revert this PR's single commit. No data or config migration is involved.

  • Since e6fef50: rebased onto main 798f3a3. The only conflict was the package line budget (now 33,493); this PR's changed lines are byte-identical. Main's fix(security): read the -c script past options and redirections #26087 added a -c option reader to the same file, so a blind review checked the two together: 0 commands main denies are allowed on this head over its corpus at hash seeds 0 and 2, every credential-mint, self-restart and pkill row is denied, including carriers from the new option reader, and no harmless control is newly denied. One Low: an 11 KB repeated-variable command takes 20.5 s here against 12.5 s on main.

  • Since 01d3646: rebased onto current main 720403c. The only conflict was the package line budget in test/test_security_gate_liveness.py (now 33,682); the security code's changed lines are byte-identical.

  • Since 73bbebf: _GluedBindings finds the glued name's leading letter run once, so each suffix lookup no longer copies the prefix (GPT finding at shell_normalizer.py:1183). A blind review found identical verdicts over 2,400 is_denied commands and 1,057,792 direct lookups at hash seeds 0 and 2; GPT's 80 KB repro takes 44.8 s, against 61.4 s before and 39.0 s on main. Line budget 33,689.

  • Since 2404d64: rebased onto current main 934f7a8. The only conflict was the package line budget in test/test_security_gate_liveness.py (now 33,889); the security code's changed lines are byte-identical.

  • Since d07af79: rebased onto current main 6fac7bc. The only conflict was the package line budget in test/test_security_gate_liveness.py (now 34,125, main's 33,959 plus this PR's 166). The security code's changed lines are byte-identical to the previous head.

  • Since 84cdce5: rebased onto current main a299f87, which raised the package line budget to 33,967 (fix(agent): resolve an agent's kirocrew to this install, not a stale one #26324). The only conflict was that budget; it is now 34,133. The security code's changed lines are byte-identical to the previous head.

  • Since f7e8446: rebased onto current main e71bf3d, which raised the package line budget to 34,312. The only conflict was that budget; it is now 34,478 (main's 34,312 plus this PR's 166). The security code's changed lines are byte-identical to the previous head.

  • Since c9de293: rebased onto current main df8598d, which raised the package line budget to 34,352. The only conflict was that budget; it is now 34,518 (main's 34,352 plus this PR's 166). The security code's changed lines are byte-identical to the previous head.

…k a quoted payload whole

A glued -Cc'<name>=<cli>; $<name> <verb>' folds to -cc<name>=... and the
carrier's leading letter region runs through the whole assignment name, so
with a name longer than _CARRIER_SPLIT_WINDOW the correct split was never a
candidate. A first word that long is read as a name: the resolver's table
(_GluedBindings) reads its binding under every suffix the payload refers
back to, in the one first-c frame. No extra split is enumerated, so the scan
stays linear.

A spaced carrier (bash -c 'x=<cli>; $x <verb>', eval, <<<, env -S) hands the
whole script over as one token, but the resolver splits a token that begins
with an assignment and carries an operator, so the walk descended only
x=<cli>. The payload walk now also reads the carriers from the tokens before
that split (_quoted_assignment_scripts) and walks a whole quoted script that
opens with an assignment as its own frame. It only adds frames: every frame
the resolved view yields is still walked.

Refs #8544
@CrysisDeu

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: 84b000c

  • What rule changed: The shell payload walk in src/kiro_crew/security/shell_normalizer.py reads two more spellings of the credential-mint and self-protection floors. (1) In a script the extractor takes from a glued -c carrier occurrence whose first word assigns a name longer than the carrier split window, a $name use also reads that name under its suffixes, as one more view beside the unchanged plain view (_GluedBindings; the occurrence is reported by _nested_shell_payloads(glued_out=), and the letters in front of the use must end at the carrier's c). (2) A spaced carrier's quoted script that opens with an assignment is walked whole as one more frame (_quoted_assignment_scripts). argv_floor_self.py and shell_normalizer_redirects.py change in docstrings/wiring only; __init__.py and _exports.py re-export the new helpers. This head is 2573f93870 rebased onto main 81dde23e17; its only conflict was the package line budget in test/test_security_gate_liveness.py (now 33,331), and no security hunk changed. 2573f93870 was the earlier head 8e828472f4 rebased onto main a6f3cc5ce5, with that budget line and _shell_payload_walk, where main's redirect_hidden_payloads(source) is kept and appended after this PR's per-view loop. A blind review of that merged hunk found no issue: all 220 commands main denies stay denied.

  • Before -> after (what was allowed/blocked, now): Before, bash -c 'x=kirocrew; $x token' and zsh -Cc'<78 a>=kirocrew; $<78 a> token' were allowed. Now both are refused. Commands main refuses are still refused: scripts/deny_diff.py over a 5,053-command corpus on base fe68d8ef24 and on this head gives 547 allowed -> denied (credential-mint spellings only, no golden path) and 0 denied -> allowed. The one row that moves the other way, * stash *, also flips both ways when base is compared with itself, so it is pre-existing nondeterminism. The 91 ssh rows, re-run one row per deny_diff call, show 0 changes.

  • Worst case if wrong (breaks commands / leaks secret / locks user out): Breaks commands. An ordinary command is wrongly refused (over-refusal), for example a printed printf '%s\n' bash -c '...', which is refused again (safe side) because the printed-script check is out of scope. Nothing that is refused today becomes allowed, because both readings only add frames or views beside the existing ones.

  • Evidence checked (which sandbox result proves it): One-off classifier runs via scripts/deny_diff.py (fresh child process per ref, no test suite run locally) over the corpus named above. CI on this head: Denial Differential (ubuntu, windows) passed, Security scope adjudication (ubuntu, windows) and candidate validation passed, GPT 6.1 Review and Opus 5.5 Review passed with no blocking finding.

  • No regression:

    • Tools still work (which tools/commands were run, result): Benign spellings stay allowed: the 69 security-conductor golden paths' shell rows (0 newly refused), bash -c 'PORT=3000; npm run dev', and the scripted feature-branch bash -c 'b=feat/example; git push -u origin $b'.
    • Backward compatible (old config / old data / old callers still work, how checked): No config, data or API change. New keyword-only arguments (whole_scripts, resolve, glued, glued_out) default to the old behaviour, and the other callers are unchanged (audited in the PR body).
    • Existing tests (which suites passed on this head): Backend Tests (3.12) shards 1-8, Backend Tests (Windows) shards 1-8, IPv6, namespace sandbox, crew container, Kernel Lock Owner, E2E (stub ACP backend, offline), E2E Gateway Boot (ubuntu, windows), E2E (private member namespace) and Coverage Combine all passed on this head.
  • How to undo: Revert this PR's single commit. No data or config migration is involved.

  • Since e6fef50: rebased onto main 798f3a3. The only conflict was the package line budget (now 33,493); this PR's changed lines are byte-identical. Main's fix(security): read the -c script past options and redirections #26087 added a -c option reader to the same file, so a blind review checked the two together: 0 commands main denies are allowed on this head over its corpus at hash seeds 0 and 2, every credential-mint, self-restart and pkill row is denied, including carriers from the new option reader, and no harmless control is newly denied. One Low: an 11 KB repeated-variable command takes 20.5 s here against 12.5 s on main.

  • Since 01d3646: rebased onto current main 720403c. The only conflict was the package line budget in test/test_security_gate_liveness.py (now 33,682); the security code's changed lines are byte-identical.

  • Since 73bbebf: _GluedBindings finds the glued name's leading letter run once, so each suffix lookup no longer copies the prefix (GPT finding at shell_normalizer.py:1183). A blind review found identical verdicts over 2,400 is_denied commands and 1,057,792 direct lookups at hash seeds 0 and 2; GPT's 80 KB repro takes 44.8 s, against 61.4 s before and 39.0 s on main. Line budget 33,689.

  • Since 2404d64: rebased onto current main 934f7a8. The only conflict was the package line budget in test/test_security_gate_liveness.py (now 33,889); the security code's changed lines are byte-identical.

  • Since d07af79: rebased onto current main 6fac7bc. The only conflict was the package line budget in test/test_security_gate_liveness.py (now 34,125, main's 33,959 plus this PR's 166). The security code's changed lines are byte-identical to the previous head.

  • Since 84cdce5: rebased onto current main a299f87, which raised the package line budget to 33,967 (fix(agent): resolve an agent's kirocrew to this install, not a stale one #26324). The only conflict was that budget; it is now 34,133. The security code's changed lines are byte-identical to the previous head.

  • Since f7e8446: rebased onto current main e71bf3d, which raised the package line budget to 34,312. The only conflict was that budget; it is now 34,478 (main's 34,312 plus this PR's 166). The security code's changed lines are byte-identical to the previous head.

  • Since c9de293: rebased onto current main df8598d, which raised the package line budget to 34,352. The only conflict was that budget; it is now 34,518 (main's 34,352 plus this PR's 166). The security code's changed lines are byte-identical to the previous head.

  • Since 758073f: rebased onto current main e86fbdc, which raised the package line budget to 34,522. The only conflict was that budget; it is now 34,688 (main's 34,522 plus this PR's 166). The security code's changed lines are byte-identical to the previous head.

@bolichen97

Copy link
Copy Markdown
Contributor

[operator: bolichen97] Continuing this in #32885; thanks for the start.

@iamwhatever

Copy link
Copy Markdown
Contributor

Thanks for starting this. A maintainer continued this work in #32885, which has since merged on main, so I'm closing this PR as superseded. Please reopen if anything here is still missing from main.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge conflict Branch has merge conflicts with its base — author must resolve before merge needs-human-security-review Security scan flagged — needs manual review no-screenshots PR has no visual delta; screenshot gate exempt readiness: passed Eligible automated validation passed for the current revision

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Deny-tier case fold defeats carrier-split extraction: long-name assignment indirection hides a mint inside sh -c payloads (pre-existing)

4 participants