Repository navigation
fix(security): find the -c option letter behind a long assignment, and walk a quoted payload whole - #13261
fix(security): find the -c option letter behind a long assignment, and walk a quoted payload whole#13261CrysisDeu wants to merge 1 commit into
Conversation
Design Review (Opus 5.5) — ✅ PASSDesign-level review of 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
[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 |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of 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 What this change shipsInventory (7 items) — 7 justifiedIntent: refuse a credential mint hidden behind a variable assignment inside a
[FIRST-PRINCIPLES-REVIEWED] 84b000c Description read[DESCRIPTION-READ] 6a3b4cc60103adff54fc0f0c727044a589802286a53eb6436d9d14fb90b35f6b That sha256 names the PR description this verdict read. Recompute it with |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
Opus 5.5 Review — ✅ no blocking findingsReviewed Review detailsNo findings. Notes:
[OPUS-REVIEWED] 84b000c Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
Security Scope Review -- ✅ PASSWhich legitimate operations does Verdict basis: adjudicated, zero confirmed regressions. Security scope review -- adjudicated candidates
No candidate flipped from allowed to refused. Scope-Verdict: PASS Reason: The 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 ( TIGHTENING: the nested-shell payload walk ( ADJUDICATED: 25 candidates, 0 confirmed newly-refused PLATFORM COVERAGE: posix (20 rows). These cover every carrier spelling the diff reads: spaced UNADJUDICATED: the source text admits one over-refusal: a data consumer that only prints an assignment-first script is refused ( [SCOPE-REVIEWED] 84b000c |
216a7cf to
570c179
Compare
570c179 to
d9547d0
Compare
|
Security Scope Review -- candidate inputs mapped to tests (head d9547d0) The lane's two confirmed rows on the previous head ( All tests are in
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 |
d9547d0 to
0233cf5
Compare
|
Security Scope Review -- R3 row mapped (head 0233cf5) The one row the lane confirmed on Pinned in Also on this head: the GPT 5.6 finding on |
6e9578a to
a97b1d7
Compare
|
PR triage (2026-10-05) — REBASE + merge-coordination note Checked head
|
bolichen97
left a comment
There was a problem hiding this comment.
[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 ( |
There was a problem hiding this comment.
[P0] Guarded-reading enumeration lets a credential-mint command through that main denies — see the review summary for mechanism, fix and test.
There was a problem hiding this comment.
@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.
There was a problem hiding this comment.
@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_redirectionsblanks 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 maskingperm_verb_mention.pydoes. 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_closednow 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::TestGuardedReadingEnumerationFailsClosedassertsis_deniedis truthy for both paths, across several redirection and wrapper spellings, with controls that an ordinary redirection and an inert wrapper stay allowed.
There was a problem hiding this comment.
@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?
There was a problem hiding this comment.
@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?
Sensitive Change ReviewSensitive files changed:
|
UX Review (Opus 5.5) — ⏭️ skippedRevision |
|
@bolichen97 both P0 items from your review are fixed on head (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 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. |
|
This PR is now shrunk to the two cases in its Goal, on head
Checked with one-off |
|
The three findings on
Rechecked with one-off |
|
Round 3 on head
Corpus recheck (one-off |
|
Round 4: both GPT 6.1 findings on
Corpus check (one-off |
Sensitive change review
|
|
Round 5: the findings on
Corpus check (one-off |
Sensitive change review
|
Sensitive change review
|
|
Sensitive change review
|
|
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 Open blockers on this head:
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) |
|
self-added: no
|
|
Answering the r138 question on the GPT 6.1 BLOCK (
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. |
Sensitive change review
|
Sensitive change review
|
Sensitive change review
|
Sensitive change review
|
…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
Sensitive change review
|
|
[operator: bolichen97] Continuing this in #32885; thanks for the start. |
|
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. |
Problem / Motivation
Goal: A credential mint hidden behind a shell-variable assignment inside a
-c/evalcarrier 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.
zsh -Cc'<78 letters>=kirocrew; $<78 letters> token'): the case fold turns-Ccinto-cc, and the carrier's leading letter region runs through the whole assignment name up to the=. Thec-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 asc<name>=..., the assignment went to a different name, and$<name>never resolved. A short name (x=) was already denied.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 onlyx=kirocrew. The script's own command line was never examined. Measured allowed on main forbash -c,bash -x -c,bash -c --,zsh -Cc,eval,bash <<<andenv -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 tokenand its top-level assignment spellingx=kirocrew; $x token; nothing indocs/system-specs/modules/security.mdor the code exempts the same command inside a-cpayload, and the payload walk (_shell_payload_walk,src/kiro_crew/security/shell_normalizer.py:1416on main) exists to read exactly that. Case 2 comes from_split_glued_operators(src/kiro_crew/security/shell_normalizer_walk.py:142on 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-offis_deniedcalls (no test suite run):kirocrew tokenx=kirocrew; $x tokenbash -c 'x=kirocrew; $x token'zsh -Cc'<78 a>=kirocrew; $<78 a> token'Corpus check: 5,053 commands (glued and spaced
-ccarriers, quoted andevalscripts, printed carriers, escaped-space (\ ;) spellings, the review findings, the shell rows of the security-conductor golden paths and the command literals of thetest/test_security_*.pyfiles), run throughscripts/deny_diff.pyon this branch's basefe68d8ef24and 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 91sshrows were also run one row perdeny_diffcall: 0 changes.Not a goal
_nested_shell_payloadsalready walks._CARRIER_SPLIT_WINDOW, the tail window and the first-csplit are unchanged.Out of scope
x=kirocrew; false && x=echo; $x tokenboth 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
-cscript 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$xnames 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 --
_GluedBindingsinsrc/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-cpayload, always yielded, carries the whole glued word as its first token. When a frame is a payload the extractor takes from a glued-ccarrier occurrence and its first word assigns a name longer than the window (_nested_shell_payloadsreports these throughglued_out, so a printedecho -c'<s>'gives nothing to a spacedbash -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 ordinarystays 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'sc, reads that binding ($NAMEreaches<flags>cNAME=kirocrew; inzsh -c'<78 a>=kirocrew; ...$a...'the name is the whole run ofaand$astays 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 tokenand<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> tokenstays refused (an append folded onto the glued key would turn the mint binding intokirocrewzzz), while<L>=kiro; <L>+=crew; $<L> tokenstill readskirocrew. Both the=and+=spellings of the first word are recorded. In the glued view an explicit emptya=is a binding ofa, so it stops the suffix read.Case 2 --
_quoted_assignment_scriptsin 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 forwhole_scripts=Falseand sees exactly main's sources, so a scriptedbash -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_BUDGET32,909 -> 33,068 for the 159 added package lines. Every file stays under the per-file caps.Callers audited:
_shell_payload_walkgains a keyword-onlywhole_scriptsargument (default on;_shell_payload_sourcesturns it off),_self_tokensgains keyword-onlyresolveandgluedarguments,_resolve_local_assignmentsa keyword-onlygluedargument, and_nested_shell_payloadsa keyword-onlyglued_outcollector, all with the old behaviour as default; their other callers are unchanged._shell_c_carrier_payloadschanged in its docstring only._resolve_local_assignmentskeeps 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_mintandis_denied; unit pins that the extractor yields only the first-cframe and that the resolver reads$<name>and$<name>_1through 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> tokenand<65 a>=kirocrew; a+=zzz; $<65 a> token(top level andbash -c) stay denied, as do<65 a>=echo; a=; a+=kirocrew; $a tokenand<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 anevalscript stay denied as on main;_quoted_assignment_scriptsunit pins.test_benign_carrier_scripts_stay_allowed-- ordinary assignment scripts andpkill -f 'v=6777; KIROCREW_PORT=$v npm run dev'stay allowed, as does an ordinary long first assignment followed by an emptya=(top level,bash -c,${a}, and a gluedzsh -Cc'...'carrier).TestGluedViewNeedsAGluedCarrier.test_glued_status_is_not_carried_by_script_text-- a printedecho -c'<s>'before a spacedbash -c '<s>'of the same text gives it no glued view (allowed), whilezsh -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'(andbash) stays allowed; resolver unit pins for a suffix with and without the carriercin 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_mintassertion, 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
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)