Repository navigation
fix: never run a hooks.json hook whose matcher is not text - #38798
bolichen97 wants to merge 1 commit into
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 |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS The guard sits where the crash happens, in What this change shipsInventory (5 items) — 5 justifiedIntent: a hand-edited
[FIRST-PRINCIPLES-REVIEWED] b5eb0d5 Description read[DESCRIPTION-READ] 24b6454321e495c1f7a85fa1f97dfed081ea215ddd1c2f7b611de9ad7a0b7af4 That sha256 names the PR description this verdict read. Recompute it with |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks. The fix sits at the one place the event's fire raised, and failing closed on PreToolUse follows the maintainer decision cited in the description. Notes
[DESIGN-REVIEWED] b5eb0d5 Description read[DESCRIPTION-READ] 3369241a4b27c272c258b254eb4bf0046cccabee40a5a32fcb2e0e87c506116a 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 |
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 tightening affects only stored script hooks whose TIGHTENING: ADJUDICATED: 11 candidates, 0 confirmed newly-refused PLATFORM COVERAGE: The diff makes no assumption about paths, separators, interpreters or argv. It checks the type of a JSON value. I wrote posix rows ( UNADJUDICATED: The guard is the non-text-matcher check in
[SCOPE-REVIEWED] b5eb0d5 |
[operator: bolichen97] |
9c1d626 to
1997b4f
Compare
|
Rebased: main moved in docs/system-specs/modules/memory-skills-hooks.md and src/kiro_crew/hook_runtime/script_hooks.py since this head went green (d155058 -> 27cd6ac); CI re-running. The change itself is unchanged: the new head 1997b4f carries the same patch as 9c1d626, with no conflict. The rebase also answers the earlier GPT 6.1 finding at [operator: bolichen97] |
1997b4f to
39b9b07
Compare
|
Rebased: main moved in docs/system-specs/modules/memory-skills-hooks.md since this head went green (27cd6ac -> 983fd61); CI re-running. The change itself is unchanged: the new head 39b9b07 carries the same patch as 1997b4f, with no conflict. The two Windows reds on the old head were main's flakes, and their fixes reached main after the old base: #39516 runs the Windows backend shards with 4 workers again and #39545 makes that test file's poll helpers wait on the lost-run bound ( [operator: bolichen97] |
|
[operator: bolichen97] Sensitive change review
|
Code change approver recommendation: A person should decideWhy: the decider estimates a 10% chance that this change introduces a defect, within the 12% limit for approving on its own, but it is held at tier 3: merge conflict. ScriptHookStore.fire now checks for a set, non-text matcher before matching. On PreToolUse it adds a failed result with exit code -1 and from_spec=False, so pre_tool_blocks is True. Both gates refuse on it: permission_pre_tool_block blocks with the row-naming reason, and turn_spec_hooks._fire fails closed through its "exit not 0 or 2" branch. On other events the row is skipped, and because touched is not set, no hooks.json rewrite happens. The row still loads as written and a save keeps its matcher. Spec hooks cannot reach the new branch because conversion sets a non-text matcher to "". The new parametrised test fails on main and covers the block reason, that the healthy sibling hook still runs, the Stop skip with and without text, and save preservation. The docs are updated. I found no regression, fail-open path or missing test. Tier: 3, held for a person: merge conflict. An automated recommendation, not a review: a maintainer still decides. It approves on its own only when the estimated chance of a defect is at most 12% and the change has at most 400 changed lines. Decider v3c (217fe607) · commit |
A hand-edited hooks.json row whose matcher is a list, a number or an object loaded as a live hook, and fire() raised when it folded the matcher's case. On PreToolUse the dispatcher turned that raise into a block for every tool call with a Python error, and on any event the raise stopped that event's other hooks. Such a hook now loads as written, with a warning naming it, and a save keeps the value the operator wrote. Its command never runs, since running it would widen it to every call. On PreToolUse it blocks the call with a reason that names the row, because a gate with no verdict blocks; on every other event it is skipped. The event's other hooks run. Closes #37310
39b9b07 to
b5eb0d5
Compare
|
Rebased: main moved in docs/system-specs/modules/memory-skills-hooks.md and src/kiro_crew/hook_runtime/script_hooks.py since this head went green (983fd61 -> ae93f16); CI re-running. GitHub reported this PR as conflicting: main's #38686 ( [operator: bolichen97] |
Problem / Motivation
Goal: A
hooks.jsonrow whosematcheris not text no longer breaks the hooks around it: its command never runs, a PreToolUse call is refused with a reason that names the row, and every other hook keeps firing.A row such as
{"event": "PreToolUse", "matcher": ["Bash", "Write"], "command": "true"}(or"matcher": 3, or an object) loads as a live hook. From then on every tool call is refused withPreToolUse hook could not run: 'list' object has no attribute 'lower', and the healthy hooks of that event never run. On a message event such as Stop the same row breaks that event's hooks whenever there is text to match.Why it matters
One malformed row refuses every tool call with a Python error that does not say which row to fix, and it silences every other hook on that event, deny gates included.
Not a goal
null,0,[]): it is no matcher, as on main.What changed (motivation → approach → change)
A
hooks.jsonrow whosematcheris a list, a number or an object no longer crashes the hooks of its event, and its command never runs. On PreToolUse the call is refused with a reason that names the row (bad: hook 'bad' has a matcher that is not text (list); fix it in hooks.json) instead of a Python error, and the event's other hooks run. On every other event the row is skipped. The row loads as written, a load warning names it, and a save keeps the matcher the operator wrote.The cause:
fire()folds a set matcher's case, which raises for a value that is not text, and the raise ended the whole event's fire.ScriptHookStore.fire(hook_runtime/script_hooks.py) checks a set matcher's type before matching. A matcher it cannot read never reaches the spawn, because running the hook would widen it to every call. On PreToolUse it adds a failed result, which every PreToolUse gate already reads as a block (a gate with no verdict blocks); on other events the hook is skipped._load_datalogs the warning. The Script hooks section ofmemory-skills-hooks.mdstates the rule.Backwards compatibility
Compatible: only a row with a set, non-text matcher behaves differently, and on main that row raised every time its matcher was read. Every text or falsy matcher loads and fires as it does on main.
Reader: src/kiro_crew/hook_runtime/hook_dispatch.py:permission_pre_tool_block -- subagent|cron|channel -- blocks on the row's failed result and returns its reason, where main blocked on the raise; test_non_text_matcher_never_runs_and_blocks_only_pre_tool_use
Reader: src/kiro_crew/dashboard/chat_turn/turn_spec_hooks.py:_fire -- chat -- turns the failed result into a
BLOCKED:marker carrying its error (the fail-closed branch for any exit but 0 and 2), where main raised into the hook-error refusalReader: src/kiro_crew/hook_runtime/script_hooks.py:ScriptHookStore.fire -- chat|subagent -- a message-event row with such a matcher ran as match-all on main when the event had no text, and raised when it had some; it now never runs; test_non_text_matcher_never_runs_and_blocks_only_pre_tool_use (
context=""and"done")Reader: src/kiro_crew/hook_runtime/hook_dispatch.py:persisted_hook_store -- subagent|cron -- the row loads, so the strict read of the saved hooks is unaffected, as on main
Reader: src/kiro_crew/acp/kas_wire.py:normalize_script_hook -- chat -- already withholds a hook whose matcher is not a string; unchanged
Reader: src/kiro_crew/acp/kas_hook_coverage.py:hook_gated_capabilities -- chat -- already reads such a matcher as covering every tool, so each call reaches Crew's gate, which now refuses it with the named reason; unchanged
Reader: src/kiro_crew/hook_runtime/hook_dispatch.py:_run_one_lane_hook -- chat -- a SessionLaneChanged row with such a matcher already never ran (its own task raised); unchanged
Tests
test/test_hook_validation_parity.py::TestStoreLoadResilience::test_non_text_matcher_never_runs_and_blocks_only_pre_tool_use(list, number and object matcher): writes a PreToolUse row and a Stop row with that matcher beside a healthyBashPreToolUse row, then checks thatpermission_pre_tool_blockrefusesBashwith the named reason, that Stop fires with and without text return nothing, that only the healthy hook runs, and that both rows keep their matcher inhooks.jsonafter a save.Proof: PROVEN test/test_hook_validation_parity.py::TestStoreLoadResilience::test_non_text_matcher_never_runs_and_blocks_only_pre_tool_use[matcher0], test/test_hook_validation_parity.py::TestStoreLoadResilience::test_non_text_matcher_never_runs_and_blocks_only_pre_tool_use[3], test/test_hook_validation_parity.py::TestStoreLoadResilience::test_non_text_matcher_never_runs_and_blocks_only_pre_tool_use[matcher2] (head f47ead078679)
Determinism: the new test 20/20 at
-n0; the whole file 10/10 at-n 4 --dist loadgroup; the whole file once in a seeded shuffled order (seed 37310, 74/74). On the base source the new test fails all three cases: the list and the object on the.lowererror, the number onargument of type 'int' is not iterable.Manual verification
Reproduced and smoke-tested on Linux (Ubuntu 24.04.5 LTS, kernel 7.0, Python 3.12.3) in an isolated
KIROCREW_HOME, on main 6911319 without and with this change. A driver wrotehooks.json(a bad PreToolUse row, a bad Stop row with the same matcher, then a healthyBashPreToolUse row), builtScriptHookStore()and calledpermission_pre_tool_block(store, (), None, "Bash")andstore.fire("Stop", ...). Each bad row's command writes a marker, so the table shows whether it ran. The healthy hook ran through the real sandboxed spawn: namespace backend, its own mount namespace, seccomp on, exit 0. The hooks HTTP routes ran against an isolated gateway on 127.0.0.1. No model is signed in on that host, so no chat turn was driven.["Bash", "Write"], PreToolUsePreToolUse hook could not run: 'list' object has no attribute 'lower'; the healthy hook never runsbad: hook 'bad' has a matcher that is not text (list); fix it in hooks.json; the healthy hook runs; the bad command never runs3/{"tool": "Bash"}argument of type 'int' is not iterable/'dict'(int)/(dict)GET /api/hooks, togglegoodoff and on"Write", `"Write,null, eventFutureEvent`Writefires only for Write; `WriteGates, on that host for this change on main 6911319: 65 of the project's 66 profile gates green, including the related-test runner's backend shard (1,184 passed) and its frontend shard (15,840 vitest tests), mypy, flake8 and isort; plus 673 tests across the eight hook test files, the flake-pattern ratchet (75 passed) and semgrep (0 findings). The one red, the bundle-size check, fails the same way on main itself (#39726, fix open in #39727); this PR changes no
website/file. This head sits on a later main, whose added commits change none of this PR's code or test files.Real-machine verification
Machine: EC2 m7i.2xlarge, Ubuntu 24.04.5 LTS x86_64, 8 vCPU / 32 GiB, Python 3.12.3; a disposable verification host with no inbound rules, about 35 minutes for this job (about $0.23 on-demand)
Before (main 6911319):
PYTHONPATH=<tree>/src KIROCREW_HOME=<fresh mktemp -d home> python drive.py <dir> V1(the driver under Manual verification, list matcher) ->PreToolUse hook could not run: 'list' object has no attribute 'lower'; the healthyBashhook never runs;fire("Stop", context="done")raisesAttributeErrorandcontext=""runs the bad Stop row's commandAfter (this change on main 6911319): the same command ->
bad: hook 'bad' has a matcher that is not text (list); fix it in hooks.json; the healthy hook runs in its own mount namespace under a seccomp filter and exits 0; both Stop fires return[]; neither bad command runs. V2 (3) and V3 (an object) give the same with(int)and(dict)Cleanup: the isolated homes, markers and the test gateway (stopped by its own PID, port closed) were removed; no key pair was made (session access only); the host is a pooled verification host still serving other jobs, which the pool terminates once idle
Related Issues
Closes #37310
Sibling sweep
Swept: git grep -nE "_tool_matches(hook.matcher|_context_matches, hook.matcher" -- src/kiro_crew
Sibling: src/kiro_crew/hook_runtime/script_hooks.py -- changed here
Sibling: src/kiro_crew/hook_runtime/hook_dispatch.py -- not affected --
_run_one_lane_hookevaluates one lane hook in its own task, so such a hook already never runs and the other lane hooks doSibling: src/kiro_crew/acp/kas_wire.py -- not affected --
normalize_script_hookwithholds a hook whose matcher is not a string beforeselect_hooksmatches itSibling: src/kiro_crew/agent_sdk/spec_hooks.py -- not affected -- an agent spec hook with an invalid matcher is dropped at conversion
Pattern harvest
Not generalizable: every other reader of a hand-edited matcher already keeps such a hook from running (the agent spec loader and the KAS projection withhold it, and the lane dispatcher's per-hook task fails alone); this was the one reader whose raise took the whole event down.
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)