Repository navigation
fix(cron): scan nested shell levels and resolved assignments for braces - #15344
Conversation
Design Review (Fable 5) — ✅ PASSDesign-level review of Design-Verdict: PASS Verify the in-code residual — a brace group behind two-plus nested re-parses where one shell is unlisted — is a maintainer-accepted trade-off. [DESIGN-REVIEWED] ca8f2ca Description read[DESCRIPTION-READ] 54a7bacb92f64f9bbfd455f664630fccc0e610bdc709bd65ea2fe98be4556524 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 (Fable 5) — 🟡 CONCERNSPremise-level review of First-Principles-Verdict: CONCERNS Resolution now feeds three composition checks but skips Not justified as shipped
What this change shipsInventory (7 items) — 5 justifiedIntent: close two verified bypasses of the cron
[FIRST-PRINCIPLES-REVIEWED] ca8f2ca Description read[DESCRIPTION-READ] 22d16890e2a7faccc9323624e74483242bd00e8b438c5b1cca0e68ee234b255e That sha256 names the PR description this verdict read. Recompute it with |
GPT 5.6 Review — ✅ human override acceptedHuman judgment by @iamwhatever overrides the GPT 5.6 finding for [GPT-OVERRIDE] ca8f2ca This comment is updated in place on each push. The model was not re-run because an authorized human decision supersedes it. False positive or not applicable? A repository writer can comment: |
|
Opus 5 Review — ✅ no blocking findingsReviewed Review detailsAdvisory only: the new FINDING — src/kiro_crew/mcp_cron.py:1182 — [OPUS-REVIEWED] ca8f2ca Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
8f0f5ec to
12ac07f
Compare
|
Opus review on
|
|
|
12ac07f to
e074b8f
Compare
|
Opus review on
|
|
|
|
|
Human judgment recorded@iamwhatever marked the gpt AI finding as false positive, not applicable, or explicitly accepted for
This decision applies only to this commit. A new push requires a new judgment. |
e074b8f to
cae00a8
Compare
|
… braces Follow-up to #15253. The cron command vet read brace groups at two levels over the raw text only, so several shapes reached a nested shell unseen: - an escape inside the outer quotes survives the first removal, so `bash -c "bash -c cat\ p{s\,s}q"` expands only at the third shell; - `A={; B=}` then `${A}s,s${B}` spells the group only after the assignments resolve, and `A=$; B='('` spells `$(` the same way. The brace scan now follows quote removal until the text stops changing, under one shared step budget. Level N past the second is taken only when that level's own text names at least N-1 shell re-parsers; argv wrappers such as env, timeout, flock, xargs and find are not counted, so the documented BRE rewrite `grep "[0-9]\{1,3\}"` stays accepted behind them. The vet resolves local assignments once, with the shell's own quote removal so `PAT="[0-9]\{1,3\}"` keeps its backslashes, refuses a resolved form over the 8192-character ceiling, and runs the command-substitution, non-plain `${...}` and brace checks on both the raw and resolved forms.
cae00a8 to
ca8f2ca
Compare
|
Opus and GPT reviews on
|
|
|
|
|
/ai-review override gpt ca8f2ca: The OOM this claims requires unbounded value growth, but mcp_cron.py:916 truncates every stored value to 5000 chars, :915 caps tracked names at 64, and :1085 refuses a raw command over 8192 before resolution runs, so the pre-refusal allocation is bounded to tens of MB (pinned at test/test_mcp_cron_security.py:444) rather than exponential. |
Human judgment recorded@iamwhatever marked the gpt AI finding as false positive, not applicable, or explicitly accepted for
This decision applies only to this commit. A new push requires a new judgment. |
…release/0.8.0 (#15631) * fix(security): backport the MCP registry, config seal, cron brace and folder-picker fixes (#14629, #14748, #14486, #15344) Backport of #14629, #14748, #14486, #15344 to release/0.8.0, cherry-picked in main's merge order. * fix(knowledge): require a direct local request for the native folder picker (#14629) (cherry picked from commit a25b321) * fix(security): write-protect the kiro-cli MCP registry (#14748) (cherry picked from commit d55957e) * fix(sandbox): mount config.json and config.local.json read-only (#14486) (cherry picked from commit 909e0fc) * fix(cron): scan every nested shell level and resolved assignments for braces (#15344) (cherry picked from commit 481476a) Co-authored-by: Joe Guo <zejiangg@amazon.com> Co-authored-by: leonlaiyc <276034861+leonlaiyc@users.noreply.github.com> Co-authored-by: Leon <leon.lai.yc@gmail.com> * fix(security): backport the apps-tree cron mask, listener-scoped credentials and dev-fleet git hardening (#13273, #13929, #14960, #13348) Backport of #13273, #13929, #14960, #13348 to release/0.8.0, cherry-picked in main's merge order. * fix(cron): mask the apps tree from every cron child that runs model-supplied code (#13273) (cherry picked from commit 0496784) * fix(electron): scope the local-token mint to the dialed listener (#13929) (cherry picked from commit 497361d) * fix(instances): pair the internal-API credential read with the dialed listener (#14960) (cherry picked from commit 2087cde) * fix(dev-fleet): harden every git read, and resolve the base branch per repository (#13348) (cherry picked from commit 64b0a33) Co-authored-by: kirocrew-agent <agent@kirocrew.local> Co-authored-by: wave1 verify <worker@localhost> --------- Co-authored-by: Joe Guo <zejiang.guo@gmail.com> Co-authored-by: Joe Guo <zejiangg@amazon.com> Co-authored-by: leonlaiyc <276034861+leonlaiyc@users.noreply.github.com> Co-authored-by: Leon <leon.lai.yc@gmail.com> Co-authored-by: Raymond Chen <45910466+chenmingwei23@users.noreply.github.com> Co-authored-by: kirocrew-agent <agent@kirocrew.local> Co-authored-by: wave1 verify <worker@localhost>
Problem / Motivation
Goal: the cron
commandbrace-expansion refusal that #15253 added also covers brace groups hidden behind a third shell level or built from local assignments.Follow-up to #15253 (thanks @bolichen97), which landed the #7414 port. Two review lanes on #15240 found shapes the scan on
mainstill stores, and both reach a nested shell as a live brace group:/bin/bash -c "/bin/bash -c cat\ /tmp/.q{s\,s}h/x": the escapes sit inside the outer double quotes, so they survive the one quote-removal projection the scan reads. The third shell sees.q{s,s}h. Verified:bash -c 'bash -c "bash -c echo\ p{s\,s}q"'printspsq psq.A={; B=}; sh -c "cat /tmp/.q${A}s,s${B}h/x": the group only exists after the assignments resolve, and the scan reads the raw text. Verified:/bin/sh +B -c 'A={; B=}; sh -c "echo p${A}s,s${B}q"'printspsq psq.Why it matters
Brace expansion builds a path the stored text never spells out, which is why #15253 refuses it at save time and at every fire. A group that slips past the scan can name any path, including a credential file, so it defeats the refusal in its own class.
Not a goal
+Bshell probe, which fix(cron): run command crons where /bin/sh is bash, incl. macOS #15253 already ships.What changed (motivation → approach → change)
_has_bash_brace_expansioninsrc/kiro_crew/mcp_cron.pyscanned exactly two projections. It now scans the command, then each successive_strip_shell_quotesprojection until quote removal changes nothing, under one step budget shared across levels. Levels 1 and 2 are unconditional. Level N past that is taken only when that level's own text names at least N-1 shell re-parsers (sh,bash,dash,zsh,ksh,ash,busybox,eval,ssh,su). Counting on the projection being entered, not the one just scanned, is what sees a second shell spelled\bash. Argv wrappers (env,timeout,nice,nohup,flock,xargs,find) are not counted: they exec their argument as words, so counting them refused the escaped BRE interval the refusal text recommends._vet_shell_commandresolves local assignments once, refuses a resolved form over the same 8192-character ceiling, and runs the command-substitution, non-plain${...}and brace checks on both the raw and the resolved form.A=$; B='('then${A}${B}printf ...)spells$(only after resolution. Assignment values now get the shell's own quote removal (_shell_quote_removal, measured equal to bash on 3,155 generated words), soPAT="[0-9]\{1,3\}"keeps its backslashes andB=s\hstill becomessh. The credential-path checks reuse the same resolved form.Backwards compatibility
Breaking: a
commandcron whose resolved form exceeds 8192 characters, whose$(or non-plain${...}only appears after its assignments resolve, or whose brace group only appears after a nested shell's quote removal or after local assignments resolve is now refused at save time and at every fire. Writer sweep on origin/main:cron_add/cron_update,portability._sanitize_imported_cronsandvet_job_at_fire_timeall route through_vet_shell_command. No other writer stores acommand.echo helloandA=x; echo $Astill pass.Tests
In
test/test_mcp_cron_security.py:test_brace_scan_follows_every_nested_shell_levelpins a group only the third shell expands and a four-level one.test_brace_group_built_from_local_assignments_is_refusedpins theA={; B=}shape.test_composition_hidden_from_the_raw_text_is_refusedpins the\bashsecond shell and theA=$; B='('command substitution. Reverting the gate to count on the scanned level fails the first.test_escaped_bre_interval_in_double_quotes_is_storedpins the BRE rewrite alone, behindtimeout, behindflock+timeout, behindenv+timeout, afterfind | xargs, and throughPAT="..."; grep "$PAT".test_assignment_values_get_the_shells_quote_removalpins bash's value for seven backslash and quote spellings.test_resolved_form_over_the_ceiling_is_refused_fastpins that an 8189-character command resolving to about 8 MB is refused in under 2 s.test_plain_command_with_a_local_assignment_is_storedpins that resolution refuses nothing ordinary.Payloads use neutral
/tmptargets, since the refusals key on the shape and not the path. Measured on this branch acrosstest_mcp_cron_security.py,test_cron_script.py,test_cron_script_more_coverage.pyandtest_portability.py: 651 passed, 6 skipped. The twotest_script_leaf_swap_never_reads_the_targetfailures reproduce onmainon this host and are host-only.Manual verification
Both bypass shapes were run in real bash on a host whose
/bin/shis bash (commands above), and each prints the expansion._vet_shell_commandstores both onmainand refuses both on this branch.Related Issues
Follow-up to #15253. Replaces #15240, which carried the same #7414 port and is being closed. Refs #7412.
Pattern harvest
Rule candidate: review-prompt
Pattern: a static scan that models "what a nested parser receives" with a fixed number of projections, or over the raw text only, misses the next level and the resolved form. Scan to a fixed point, over every form the sibling checks already resolve.
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)