Repository navigation
fix(security): read the -c script past options and redirections - #26087
Conversation
Sensitive Change ReviewSensitive files changed:
How to clear this check:
Only the author's comment counts this way. A reviewer can instead |
UX Review (Opus 5.5) — ⏭️ skippedRevision |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks: the change fixes the parsing of real shell command lines, which the OS sandbox does not cover for git publish or the token mint, and it only adds payloads, so a revert undoes it cleanly. Notes
[DESIGN-REVIEWED] dbac9e1 Description read[DESCRIPTION-READ] 32729a3d026b6465c09264c19fa52b6106128e5d9679bcbaebb975900a63474f 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 This fixes the cause: issue #25814, a reported bypass, in the one shared payload reader every floor goes through. The new tests fail on base. Nothing here changes the product's shape. What this change shipsInventory (8 items) — 8 justifiedIntent: make sure a nested shell's
[FIRST-PRINCIPLES-REVIEWED] dbac9e1 Description read[DESCRIPTION-READ] 6d38aff7cb6ad5b75eb6b1004a3cc4c1bba885fccb26d894bec93abb213a02d2 That sha256 names the PR description this verdict read. Recompute it with |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
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: |
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 reader now returns additional payloads: the word a shell runs after options or redirections that follow its own TIGHTENING: ADJUDICATED: 25 candidates, 0 confirmed newly-refused PLATFORM COVERAGE:
UNADJUDICATED: These are narrowing questions I can argue but not confirm. Each has a call path, but any refusal would come back through the shell classifier rows above.
[SCOPE-REVIEWED] dbac9e1 |
1769b42 to
1ac9f7a
Compare
|
self-added: yes
|
|
self-added: yes
|
1ac9f7a to
ef6b33c
Compare
|
|
ef6b33c to
3c5cb2b
Compare
|
3c5cb2b to
5a421b8
Compare
|
resolution: narrowed (sweep extra and env -S branch removed); redirect ambiguity yields both readings
|
ac0bf07 to
6e23e58
Compare
A shell keeps reading options after -c, and the outer shell strips a redirection wherever it sits, so bash -c -x '<script>', bash -c -o pipefail '<script>' and bash -c <<EOF '<script>' all run <script>. The nested-payload reader took the word right after -c (-x, -o, <<eof), so the self-protection and git-publish floors and the deny views never saw the script. env -S had the same miss with a redirection before its argument. _c_script_indexes finds the word a shell runs in one backward pass and the reader yields it in addition to the first-word reading, so it only adds payloads. Closes #25814 for the shared reader; the rm floor's nested reading uses the same reader.
6e23e58 to
dbac9e1
Compare
KiroCrewCaptain
left a comment
There was a problem hiding this comment.
Approved on behalf of the watch holder (bolichen). Design and First Principles pass on this head, UX skipped or pass, no conflict, no open change request.
Backports these main PRs to release/0.11.0, in pick order. Each was a `git cherry-pick -x` of its squash commit on main: - fix(memory): read memory.db off the writer lock, split background pool (#24290) (cherry picked from commit fed830c) - fix(dashboard): bound the pre-prompt build's wait to enter the memory pool (#24414) (cherry picked from commit 520cf2c) - fix(memory): keep the shared -wal when another process closes the memory store (#25852) (cherry picked from commit dc63bb6) - fix: read the page-cache prefetch in a child to keep sqlite locks (#26302) (cherry picked from commit 81dde23) - perf(memory): score facts from a term index and prebuild after restart (#25328) (cherry picked from commit 6824348) - fix(desktop): retry a failed netstat before Windows recovery gives up (#25792) (cherry picked from commit 043dd9f) - fix(cli): say a gateway still serves the port when restart's replacement is refused (#25366) (cherry picked from commit 2e13127) - fix(cli): refuse to stop or restart a gateway the desktop app supervises (#25705) (cherry picked from commit bbf0910) - fix(hooks): approve kiro-cli read-only file searches after the deny tiers (#25150) (cherry picked from commit a0c0bd4) - fix(settings): refuse a config save that config.local.json overrides (#26216) (cherry picked from commit 7f8688e) - fix(workflows): write non-finite floats as null so runs open (#26085) (cherry picked from commit 3591282) - fix(approvals): give each background tool approval its own id (#25905) (cherry picked from commit 51ef3bb) - fix(chat): record file changes for kiro-cli v3 write tools (#25650) (cherry picked from commit 5369270) - fix(sandbox): stop blaming a host-wide OOM kill on a per-tree limit (#25647) (cherry picked from commit 791d2a2) - fix(acp): replay history when a KAS resume restores no turns (#25521) (cherry picked from commit 47c71cb) - fix(kas): auto-approve granted built-ins after Crew's own checks (#25339) (cherry picked from commit dba4de5) - fix(kas): mount web_search as the engine's remote_web_search (#26435) (cherry picked from commit 65c21b5) - fix(kas): answer a spec's shell.allowedCommands at the gate, after Crew's checks (#25539) (cherry picked from commit 39d07d9) - fix(kas): relay an MCP server's boolean env flags, never its secrets (#25331) (cherry picked from commit b734a68) - fix(security): read the -c script past options and redirections (#26087) (cherry picked from commit fea0920) - fix(kas): refuse a shell command a denyByDefault spec does not allow (#26501) (cherry picked from commit 9f0d02f) - fix(kas): name a deniedCommands deny aimed at a redirect as not carried (#26489) (cherry picked from commit 4951c0c) - fix(security): delete the curl-upload deny rule (#26469) (cherry picked from commit 70e206e) Conflicts resolved by hand: - #26302: test/spawn_audit_helpers.py adds only the page_cache.py entry (the embeddings_child.py entry names a module 0.11.0 lacks); test/test_page_cache_prefetch.py takes main's file. - #25328: test/test_dashboard_server_composition_contract.py lazy-import count 93 -> 96 (the three names it adds). - #25705: test/test_cli_restart_refused_message.py takes main's file. - #26085: dashboard/handlers/workflows.py adds import math, keeps the release typing import. - #25339: platform/governance.py keeps the release rule for a missing ceiling (main's enterprise-baseline clause is not on 0.11.0). - #26435: harness-parity.md H6 row edited in place on the release text. - #25539: its acp-client.md and agent-spec-fields.md lines are left out; the paragraphs they edit are not on 0.11.0 (security.md carries it). - #25331: the test and two doc mentions use hoist_managed_servers / resume=, the 0.11.0 names of main's renamed hoist_servers_for_session. - #26087: security package line budget 32,552 -> 32,714 (re-measured). - #26501: kas_permissions.py comment keeps 0.11.0's shapes (main's subagent rules are absent); its acp-client.md line is left out, and the agent-spec-fields.md toolsSettings row says denyByDefault is gate-enforced. - #26489: its agent-spec-fields.md sentence is added to the 0.11.0 row. - #26469: test_denied_commands_security.py keeps 0.11.0's comment; count 113 -> 112. Test fixes (host-dependent tests made hermetic; none loosens an assertion): - tmpdir_helpers.short_tmp_path: a tmp_path override for modules whose code judges a path by its components (a .kiro/crew data-home part); an agent session's TMPDIR under ~/.kiro/crew made every test path the data home. Used by the file-explorer, design-tweak (both), spawn-offload, launch-copy, home-pin, native-skill and auto-improvement-members tests; the sage ancestor-chain test creates its dir under /tmp for the same reason. - pi-gate tests and the remote-session Python 3.9 test take the first real binary on PATH (playwright_cli_installer_helpers._native_tool_on_path): a mise shim under a scratch HOME hangs or writes to stdout. - snapshot-merge ACL test names its own uid; nobody (65534) is the overflow uid inside a user namespace and cannot be named in an ACL. - installer-step and push_guard interrupt tests spawn with SIGINT at its default; a background pytest run starts with SIGINT ignored, which a shell trap and Python both keep. Left out: #23920 (already on release/0.11.0), #26144 (needs sandbox_launch_mark from #24709), #26088 (fences a main-only port), #25346 (11 of its tests fail on 0.11.0: the kiro-cli skill scope it compares against differs there), #26397 (needs #26152's new download route, not on 0.11.0), #26428 (not merged).
…26487) Backports these main PRs to release/0.11.0, in pick order. Each was a `git cherry-pick -x` of its squash commit on main: - fix(memory): read memory.db off the writer lock, split background pool (#24290) (cherry picked from commit fed830c) - fix(dashboard): bound the pre-prompt build's wait to enter the memory pool (#24414) (cherry picked from commit 520cf2c) - fix(memory): keep the shared -wal when another process closes the memory store (#25852) (cherry picked from commit dc63bb6) - fix: read the page-cache prefetch in a child to keep sqlite locks (#26302) (cherry picked from commit 81dde23) - perf(memory): score facts from a term index and prebuild after restart (#25328) (cherry picked from commit 6824348) - fix(desktop): retry a failed netstat before Windows recovery gives up (#25792) (cherry picked from commit 043dd9f) - fix(cli): say a gateway still serves the port when restart's replacement is refused (#25366) (cherry picked from commit 2e13127) - fix(cli): refuse to stop or restart a gateway the desktop app supervises (#25705) (cherry picked from commit bbf0910) - fix(hooks): approve kiro-cli read-only file searches after the deny tiers (#25150) (cherry picked from commit a0c0bd4) - fix(settings): refuse a config save that config.local.json overrides (#26216) (cherry picked from commit 7f8688e) - fix(workflows): write non-finite floats as null so runs open (#26085) (cherry picked from commit 3591282) - fix(approvals): give each background tool approval its own id (#25905) (cherry picked from commit 51ef3bb) - fix(chat): record file changes for kiro-cli v3 write tools (#25650) (cherry picked from commit 5369270) - fix(sandbox): stop blaming a host-wide OOM kill on a per-tree limit (#25647) (cherry picked from commit 791d2a2) - fix(acp): replay history when a KAS resume restores no turns (#25521) (cherry picked from commit 47c71cb) - fix(kas): auto-approve granted built-ins after Crew's own checks (#25339) (cherry picked from commit dba4de5) - fix(kas): mount web_search as the engine's remote_web_search (#26435) (cherry picked from commit 65c21b5) - fix(kas): answer a spec's shell.allowedCommands at the gate, after Crew's checks (#25539) (cherry picked from commit 39d07d9) - fix(kas): relay an MCP server's boolean env flags, never its secrets (#25331) (cherry picked from commit b734a68) - fix(security): read the -c script past options and redirections (#26087) (cherry picked from commit fea0920) - fix(kas): refuse a shell command a denyByDefault spec does not allow (#26501) (cherry picked from commit 9f0d02f) - fix(kas): name a deniedCommands deny aimed at a redirect as not carried (#26489) (cherry picked from commit 4951c0c) - fix(security): delete the curl-upload deny rule (#26469) (cherry picked from commit 70e206e) Conflicts resolved by hand: - #26302: test/spawn_audit_helpers.py adds only the page_cache.py entry (the embeddings_child.py entry names a module 0.11.0 lacks); test/test_page_cache_prefetch.py takes main's file. - #25328: test/test_dashboard_server_composition_contract.py lazy-import count 93 -> 96 (the three names it adds). - #25705: test/test_cli_restart_refused_message.py takes main's file. - #26085: dashboard/handlers/workflows.py adds import math, keeps the release typing import. - #25339: platform/governance.py keeps the release rule for a missing ceiling (main's enterprise-baseline clause is not on 0.11.0). - #26435: harness-parity.md H6 row edited in place on the release text. - #25539: its acp-client.md and agent-spec-fields.md lines are left out; the paragraphs they edit are not on 0.11.0 (security.md carries it). - #25331: the test and two doc mentions use hoist_managed_servers / resume=, the 0.11.0 names of main's renamed hoist_servers_for_session. - #26087: security package line budget 32,552 -> 32,714 (re-measured). - #26501: kas_permissions.py comment keeps 0.11.0's shapes (main's subagent rules are absent); its acp-client.md line is left out, and the agent-spec-fields.md toolsSettings row says denyByDefault is gate-enforced. - #26489: its agent-spec-fields.md sentence is added to the 0.11.0 row. - #26469: test_denied_commands_security.py keeps 0.11.0's comment; count 113 -> 112. Test fixes (host-dependent tests made hermetic; none loosens an assertion): - tmpdir_helpers.short_tmp_path: a tmp_path override for modules whose code judges a path by its components (a .kiro/crew data-home part); an agent session's TMPDIR under ~/.kiro/crew made every test path the data home. Used by the file-explorer, design-tweak (both), spawn-offload, launch-copy, home-pin, native-skill and auto-improvement-members tests; the sage ancestor-chain test creates its dir under /tmp for the same reason. - pi-gate tests and the remote-session Python 3.9 test take the first real binary on PATH (playwright_cli_installer_helpers._native_tool_on_path): a mise shim under a scratch HOME hangs or writes to stdout. - snapshot-merge ACL test names its own uid; nobody (65534) is the overflow uid inside a user namespace and cannot be named in an ACL. - installer-step and push_guard interrupt tests spawn with SIGINT at its default; a background pytest run starts with SIGINT ignored, which a shell trap and Python both keep. Left out: #23920 (already on release/0.11.0), #26144 (needs sandbox_launch_mark from #24709), #26088 (fences a main-only port), #25346 (11 of its tests fail on 0.11.0: the kiro-cli skill scope it compares against differs there), #26397 (needs #26152's new download route, not on 0.11.0), #26428 (not merged). Co-authored-by: w <w@k.local>
Problem / Motivation
Goal: A nested shell's script is checked by the deny floors even when an option or a redirection sits between
-cand the script.bash -c -x '<script>',bash -c -o pipefail '<script>'andbash -c <<EOF '<script>'all run<script>. The shared nested-payload reader took the word right after-c(-x,-o,<<eof) as the script, so the floors that walk nested shells never saw it. Onmaintoday,bash -c -x 'git push origin main'andbash -c -x 'kirocrew token'pass the gate, whilebash -c 'git push origin main'is refused.Why it matters
An agent can write these shapes on its own. The floors that read nested shells (git publish, the token mint, self-protection, the deny views, and the rm floor once it reads nested shells) are the layer meant to stop the command before it runs.
Not a goal
&>split inside the rm floor's own nested reader (the comment on rm floor: heredoc or flag between -c and the script still hides the payload #25814). That reader is added by fix(security): a redirect before the -c operand hides no payload, and the rm floor reads nested shells #22719 and is not onmain; the shared reader here already reads the top-levelecho&>/dev/null sh -c '<script>'shape.-c(bash -c --posix ...): bash rejects them as invalid there, so no script runs.env -Sbehind a redirection or a value-takingenvoption (env -S 3</dev/null '<line>',env -u NAME -S ...):env -Sis not a-ccarrier, so it keeps main's first-word reading; it is open onmaintoo.What changed (motivation → approach → change)
Symptom: an option or redirection after
-chid the script from every floor. Cause: the reader assumed the script is the first word after-c(after any--). bash keeps reading options after-c, and the outer shell strips redirections from argv wherever they sit.Change: a new forward scanner,
_shell_option_run, finds the word a shell really runs. From the-ccarrier it skips options (short clusters, zsh's digit options like-1, a glued option+redirection like-x>/dev/null, long options such as--norc, and-o/-O/--rcfilewith the value word each takes) and redirections with their target, and stops at the first plain word, the script. bash reads eachoin a cluster as taking a value word (-oo pipefail errexittakes two); a getopt shell glues a mid-cluster name (-onoclobber); both readings are followed and their results unioned, the safe over-approximating direction. A redirection whose target holds a blank or shell syntax is ambiguous once quotes are gone: it may be the script ('2>/dev/null <cmd>') or a quoted target (>'a b', before-cor between an option and its value), so the scanner yields it and also reads past it, with no hop cap;seenkeeps the scan O(n). The scanner adds those words as payloads next to the old first-word reading, so it only adds payloads. It reads only a-cinside the shell word's own run (_run_endscans the same way from the program word), so a later command's count flag (grep bash x && grep -c -e '<text>' f) keeps its pattern as text, and so do the arguments after a script file (bash file -c -e '<text>'). A shell word that is only a printer's argument (echo bash -c -x '<text>') opens no run either, so a printed example keeps main's reading. The scan runs only when a carrier exists, so other commands cost nothing extra.The security spec gets one bullet, and the package line budget rises by the measured growth.
Backwards compatibility
Compatible: only a command whose
-cscript sits behind an option or redirection and is already refused when written plainly starts being refused. Ordinary commands such asbash -c -x 'echo hi',bash -c -o pipefail 'make 2>&1 | tee build.log',bash -c -x 'git push origin my-feature'andecho bash -c -x 'git status'still pass (pinned in the new test file).Removes nothing: no rule, key, payload or allow case is removed. The reader only yields more payloads.
Tests
test/test_shell_c_option_payloads.py(new):-co/-oc pipefailcarriers,-oo pipefail errexittwo-value clusters, long options and-Obefore-c, a glued option+redirection-x>/dev/null, zsh digit options, a quoted script that opens with a redirection, a quoted redirection target with a blank or;before-cor before an option value, options,-o/-xo/-oxnames, a glued ksh/zsh-onoclobber,-, herestring, heredoc in three spellings, redirections, a glued-eccarrier) are refused with agit push origin mainand akirocrew tokenscript. Onmainall 44 pass the gate.grep -c -e '<text>',grep -c -i '<text>'orwc -c -l '<text>'in a later stage, a shell name that is only another command's argument,bash /dev/null -c -e '<text>', and printed examples such asecho bash -c -o pipefail 'git push origin main'.pipefail) or$0is not read as the script.test/test_security_gate_liveness.py: the package line budget, re-measured.Existing
test/test_denied_commands_security_cost.pypins that the payload set for--runs is unchanged; it passes.Proof: PROVEN test/test_shell_c_option_payloads.py::test_the_script_after_options_or_redirections_is_a_payload[bash -c -x '{p}'], test/test_shell_c_option_payloads.py::test_the_script_after_options_or_redirections_is_a_payload[bash -c -e '{p}'], test/test_shell_c_option_payloads.py::test_the_script_after_options_or_redirections_is_a_payload[bash -c -o pipefail '{p}'], test/test_shell_c_option_payloads.py::test_the_script_after_options_or_redirections_is_a_payload[bash -c -xo pipefail '{p}'], test/test_shell_c_option_payloads.py::test_the_script_after_options_or_redirections_is_a_payload[bash -c +e '{p}'] (head 6e23e58)
The new tests are pure functions over strings: no files, clock, network or shared state.
Manual verification
bash behavior was checked with a harmless
echoscript for each shape class:bash -c -x,-o pipefail,+e,-xo pipefail,-O extglob,-,>/dev/null,<<EOF, and-x <<<word. Each ran the quoted script, as didbash -c -o 2>/dev/null pipefail,bash -c -- 2>/dev/null,bash -c -ox pipefail,bash -co/-oc pipefail -x,bash --norc -c -x,bash --rcfile /dev/null -c -x,bash -c -x '2>/dev/null <cmd>', andzsh/ksh -c -onoclobber.bash -c -xo 'echo Q'takesecho Qas the option name, which is why a cluster holdingotakes the next word.Related Issues
Closes #25814
Sibling sweep
Swept: git grep -nE "_is_shell_command_flag(|_SHELL_COMMAND_FLAG_RE|== "-c"|_nested_shell_payloads|_shell_payload_walk" -- src/
Sibling: src/kiro_crew/security/shell_normalizer.py -- changed here
Sibling: src/kiro_crew/security/argv_floor_git.py -- not affected -- reads payloads through _nested_shell_payloads, so it gets the fix
Sibling: src/kiro_crew/security/argv_floor_self.py -- not affected -- reads frames through _shell_payload_walk, so it gets the fix
Sibling: src/kiro_crew/security/deny_gate.py -- not affected -- its deny views call _nested_shell_payloads
Sibling: src/kiro_crew/security/inline_payload.py -- not affected -- it splits every word of the command, not the word after -c
Sibling: src/kiro_crew/acp/liveness_interactive.py -- not affected -- reads git -c config, not a shell script
Pattern harvest
Rule candidate: review-prompt
Pattern: "the operand of a flag" read as the next token, where the program keeps parsing options after that flag
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)