Repository navigation
fix(hooks): coerce ScriptHook.enabled without dropping a deny gate - #22854
Conversation
Sensitive Change ReviewSensitive files changed:
|
Sensitive change review
|
UX Review (Opus 5.5) — ⏭️ skippedRevision |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks: the change only coerces Notes
[DESIGN-REVIEWED] 6786a36 Description read[DESCRIPTION-READ] 9baced3d33644e08b321ff01e704de0c7e05e1fc7204e6b1885b6dc399e7a443 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 The fix is at mechanism level and reuses the one existing spelling list in What this change shipsInventory (6 items) — 6 justifiedIntent: an operator's hand-edited
[FIRST-PRINCIPLES-REVIEWED] 6786a36 Description read[DESCRIPTION-READ] 2ab353c2e7a5b368675e22abebf78cadedb2ec64ba525fd3b1d2110bdec8889f 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: This change tightens how a stored script hook's TIGHTENING: ADJUDICATED: 15 candidates, 0 confirmed newly-refused PLATFORM COVERAGE: posix rows ( UNADJUDICATED: Guard: The change in that direction: in BASE, Candidate inputs I would have submitted if a hooks.json load classifier existed:
The last two are plausible hand-written "off" spellings that The narrowest change that still refuses the threat: treat a float like an int ( There is a second, smaller point: [SCOPE-REVIEWED] 6786a36 |
buluoray
left a comment
There was a problem hiding this comment.
Reviewed at c7f1fe6. Requesting changes on one point: the direction an unrecognised enabled value fails.
The "false"/"off"/"0" fix is right and well tested (every mutant of _enabled_from goes red).
The problem is the catch-all _coerce_bool(raw, default=False) in _enabled_from. A script hook is not only an action: a PreToolUse hook is a deny gate, and this codebase already treats it as one that fails closed. The ScriptHook docstring (hooks.py) says a crashed or timed-out PreToolUse hook BLOCKS the tool, and persisted_hook_store raises on an entry it cannot load so a gate fails closed instead of reading a saved deny hook as absent. For such a hook, "disabled" is the permissive answer. On main a non-empty junk value ("ture", "y", [1]) is truthy, so the gate runs. With this head the gate silently stops, and the next save writes false back over the operator's value (script_hooks.py:412-418), leaving no trace. The Design lane raised the same point as a Note, and it has no reply.
"Junk must not activate a shell command" does not hold up against an attacker either: anyone who can write hooks.json can write a real true. So the choice only decides what happens to an operator's typo, and for a gate the safe outcome is that it keeps running or the entry is visibly refused.
Suggested shape: keep the recognised spellings, ints, null/"" and the absent-key default as they are, and raise in from_dict for anything else. The fail-soft store then preserves the raw entry in _unparsed_hook_entries (script_hooks.py:403-410), and persisted_hook_store fails closed on it. If you prefer to keep loading it, default junk to enabled for PreToolUse and log a warning at load time. A test with a PreToolUse hook at "enabled": "junk" that still blocks (or refuses to load) would pin either one.
Non-blocking: acp/kas_wire.py:359-364 still says from_dict takes enabled verbatim; please update it in this commit. The First Principles note on the second int rule beside _coerce_bool also has no reply.
c7f1fe6 to
b0e0261
Compare
|
@buluoray thanks for the review. Addressed in b0e0261 (rebased on latest main), point by point:
Local: |
Sensitive change review
|
b0e0261 to
8622b49
Compare
|
@buluoray follow-up: I switched to your second option in 8622b49, which replaces my earlier reply on point 1. The raise variant (b0e0261) had the gap I flagged: both AI reviews confirmed it as blocking. In the gateway, Now, per your suggested alternative:
Local: |
Sensitive change review
|
buluoray
left a comment
There was a problem hiding this comment.
Re-reviewed at 8622b49. Approving: the blocking point from my review at c7f1fe6 is fixed.
1. Fail direction of an unrecognised enabled (was blocking): fixed. ScriptHook._enabled_from (src/kiro_crew/hooks.py:1536-1571, called from from_dict at :1638) keeps the recognised spellings, JSON ints, null/"" and the absent-key default, and loads anything else ("ture", "y", [1], {}, 1.0) enabled with a load-time warning naming the hook id and value type. The recognised/unrecognised split (_coerce_bool with default=True vs default=False) is correct. Both gate paths are pinned: test_registered_store_still_blocks_with_junk_enabled_gate fires a PreToolUse exit 2 hook at "junk"/"ture"/[1] through the registered store and gets the block, and test_persisted_store_loads_junk_enabled_gate_on covers the standalone path. This also avoids the gap in the intermediate raise variant, where the registered store would have skipped the entry.
2. Stale comment in acp/kas_wire.py: fixed (src/kiro_crew/acp/kas_wire.py:359-362).
3. Design note and First Principles int note: both answered; keeping the int branch so a hand-written 0/1 means off/on is sound.
Verification
-
test/test_script_hooks.py: 95 passed.test_script_hooks + test_hooks* + test_hook_* + test_kas_*: 2824 passed, 1 skipped. -
Mutations of
_enabled_from, one at a time, each restored before the next:- unrecognised ->
False: 15 red (loads_unrecognised_enabled_on_with_warningx11,registered_store_still_blocks...x3,persisted_store_loads_junk_enabled_gate_on) - warning removed: 11 red (
loads_unrecognised_enabled_on_with_warning) - int branch removed: 4 red (
coerces_enabled[0],recognised_enabled_does_not_warn[0/1],store_load_keeps_hand_disabled_hook_off[0]) - null/"" branch removed: 6 red (
coerces_enabled[None/""/" "],store_load_keeps_hand_disabled_hook_off[None], ...) - absent key -> off: 9 red (
absent_enabled_defaults_on,test_create_hook,test_fire_*) - warn on recognised values: 2 red (
recognised_enabled_does_not_warn[True/on]) - verbatim read restored: 34 red
No surviving mutant.
- unrecognised ->
CI on this head: the Security Scope lane failed because its runner could not install the review tool (exit 22), so it reported no verdict and failed closed. That is infrastructure, not this diff; one re-run should clear it. Sensitive Change Review needs this reasoned human approval, which the reasoning template already covers.
Non-blocking follow-ups
- The memory-skills-hooks spec does not describe how a hand-edited
enabledin hooks.json is read on load. One sentence there (recognised spellings map, unrecognised loads on with a warning) would keep the spec in step. test_registered_store_still_blocks_with_junk_enabled_gateruns a real sandboxed hook intmp_path, so it fails on a host where the sandbox refuses to pin the pytest temp directory. It passes on a neutral basetemp; worth noting in the test or forcing a neutral cwd.
8622b49 to
9972f74
Compare
Sensitive change review
|
bolichen97
left a comment
There was a problem hiding this comment.
HOLD
A whitespace-only string silently disables a hook after this change. Before the change, bool(" ") was true, so the deny hook ran. _enabled_from now strips the string and returns false without warning. That contradicts the stated rule that an unrecognized value must preserve the deny gate.
Please treat only None and the empty string as false. Route whitespace-only strings, including non-breaking spaces, through the unrecognized-value path so they load enabled with a warning. Update the compatibility text and tests.
KiroCrewCaptain
left a comment
There was a problem hiding this comment.
Review lanes PASS; the hold was advisory (a downgraded GPT 6.1 finding, a security-checklist item, or a missing reasoning template). The watch holder read the hold and approved explicitly.
hooks.json is hand-editable and ScriptHook.from_dict stored enabled verbatim, so a hand-set "false" stayed truthy and the hook kept firing. Coerce it when loading: recognised on/off spellings and JSON integers map to their value; null, empty string, lists and other junk load as disabled (a script hook runs a shell command, so junk must not activate it); an absent key keeps the default of enabled. The earlier update() hunk is dropped: its only caller validates enabled as a strict bool before the store sees it.
9972f74 to
a6ab998
Compare
A PreToolUse script hook is a deny gate, so reading a typo such as "ture" or [1] as off silently dropped the gate, and the next save wrote false over the operator's value. Refusing the entry is no better: the gateway's registered store skips an entry it cannot load, so the gate would stop there too. Keep the recognised spellings, JSON ints, null/"" and the absent-key default, and load anything else enabled with a warning naming the hook. That keeps the gate running in every process; it is not a privilege gain, since whoever can write hooks.json can write a real true. Only null and the empty string load off. A whitespace-only value (spaces, tabs, a non-breaking space) was truthy before, so a deny gate written that way ran; it takes the unrecognised path and loads enabled with a warning. The reader lives in the script_hooks owner as _script_hook_enabled_from, so hooks.py stays under the 2,000-line cap. Also update the kas_wire comment that still said from_dict takes enabled verbatim.
a6ab998 to
6786a36
Compare
Sensitive change review
@bolichen97 could you re-review the HOLD point on this head? |
Code change approver recommendation: ApproveWhy: the decider estimates a 10% chance that this change introduces a defect, within the 12% limit for approving on its own, and every check passes. ScriptHook.from_dict now reads a hand-edited 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 |
|
This review found no blocking issue on head 6786a36. It cannot approve while a change request is still open. A maintainer review from 2026-10-22 asked that whitespace-only What we checked on this head:
Done well: Notes:
|
buluoray
left a comment
There was a problem hiding this comment.
🤖 Kiro Crew Auto-Pipeline [operator: buluoray]:
Reviewed at 6786a36, merged onto current main (66dc266). Approving.
Earlier points
- bolichen97 on 9972f74: a whitespace-only
enabledturned a deny hook off. Fixed._script_hook_enabled_from(src/kiro_crew/hook_runtime/script_hooks.py:58-94) now treats onlyNoneand the exact""as off." ","\t\n"and a non-breaking space fall to_coerce_bool, which does not know them, so they load on with a warning. Tests cover all five spellings, and a PreToolUseexit 2hook set to" "or"\u00a0"still blocks through the registered store. - buluoray on c7f1fe6: an unrecognised value loaded off and dropped the gate. Still fixed at this head. Junk loads on with a warning naming the hook id and value type.
- Stale comment in src/kiro_crew/acp/kas_wire.py:413-416. Still fixed.
Fail-open check
enabled in hooks.json |
main | this head |
|---|---|---|
| key missing | on | on |
true, "true", "on", 1, 2 |
on | on |
"false", "off", "0", "no" |
on (string is truthy) | off |
false, 0, null, "" |
off | off |
" ", "\u00a0", "ture", "y", [1], 1.0 |
on | on, with a warning |
[], {}, 0.0 |
off | on, with a warning |
No value that ran a gate on main stops it now, except the recognised "off" spellings. Those are the operator's explicit off, which is the point of the PR. The loaded hook always holds a real bool, so normalize_script_hook's is True test and the store's fire path agree. Nothing that writes through the API changes.
No regex is added, in source or tests. The spellings come from the existing _coerce_bool table (src/kiro_crew/config/fields.py:123).
Verification
- Merged head,
test/test_script_hooks.py,test_hooks_composition_contract.py,test_kas_wire.py,test_hooks*.py,test_hook_*.py: 1496 passed, 1 skipped. - Mutations, one at a time, each restored before the next, run against
test/test_script_hooks.py(115 tests):from_dictreadsenabledverbatim again (the coercion reverted): 40 red, acrosstest_from_dict_coerces_enabled,test_from_dict_loads_unrecognised_enabled_on_with_warning,test_registered_store_still_blocks_with_junk_enabled_gate,test_persisted_store_loads_junk_enabled_gate_on,test_store_load_keeps_hand_disabled_hook_off.- unrecognised value loads off: 22 red (
loads_unrecognised_enabled_on_with_warningx16,registered_store_still_blocks_with_junk_enabled_gatex5,persisted_store_loads_junk_enabled_gate_on). - whitespace treated as empty: 7 red (the five whitespace cases of
loads_unrecognised_enabled_on_with_warning, andregistered_store_still_blocks_with_junk_enabled_gate[ ]and[\xa0]). - load warning removed: 16 red (
loads_unrecognised_enabled_on_with_warning).
- CI on this head: 94 pass, 15 skipping, 0 failing. Those runs used the base from when the head was pushed, not today's main. Auto-merge is on, so this approval can land it.
Non-blocking follow-ups
[],{}and0.0used to load off and now load on, so a hook hand-set that way starts running its command. The load warning names it, and anyone who can write hooks.json can writetrue. Worth one line in the PR body's compatibility notes.- docs/system-specs/modules/memory-skills-hooks.md still does not say how a hand-edited
enabledis read on load. One sentence would keep the spec in step: recognised spellings map,nulland""load off, anything else loads on with a warning. - I did not run the gateway's registered-store load path end to end. The docstring's claim that it skips an entry it cannot load was not re-checked here.
Verdict: APPROVE
bolichen97
left a comment
There was a problem hiding this comment.
Approving 6786a36ad5; my HOLD from 9972f74838 is resolved.
_script_hook_enabled_from now loads only null and "" as off. A whitespace-only string, including a non-breaking space, is not a value _coerce_bool recognises, so it loads enabled with a warning naming the hook, and the deny gate keeps running. The docstring states the rule, and test_script_hooks.py covers it. Locally the changed tests pass (181 passed). Auto merge is on.
Supersedes #12230 (by @aniruddhaadak80, whose commit is kept as-is). Moved to a branch of this repository because
src/kiro_crew/hooks.pyis a Sensitive Change Review path, which a fork PR cannot pass.Problem / Motivation
Goal: a hand-edited
enabledvalue in hooks.json means what the operator wrote, and a typo never silently turns a deny gate off.ScriptHook.from_dictstoredenabledverbatim. hooks.json is hand-editable, so"enabled": "false"stayed truthy and the hook kept firing (firegates onif not hook.enabled).UserDeniedPatternalready uses_coerce_boolfor the samebool("false")trap.Why it matters
enabledis the on/off switch for a hook that runs a shell command, including PreToolUse hooks that block tool calls. An operator who writes"false"must get an off hook, and an operator who writes"ture"must not lose a deny gate.Not a goal
enabledor to the absent-key default.What changed (motivation → approach → change)
Symptom:
"enabled": "false"kept a hook firing. Root cause: no coercion on load. Change:ScriptHook._enabled_from(data), used byfrom_dict:True(unchanged default)true/false/1/0/yes/no/on/offstrings (any case, trimmed) -> their value, via_coerce_bool!= 0(a hand-edited0stays off,1stays on)null,""->False(both were falsy before). A whitespace-only string (spaces, tabs, a non-breaking space) is not empty: it was truthy before, so it takes the unrecognised path below and loadsTruewith a warning"ture","y",[1],{},1.0) ->True, with a load-time warning naming the hook id and the value type.Why unrecognised loads on (maintainer review + AI review on b0e0261): a PreToolUse hook is a deny gate, so off silently drops it. Refusing the entry is not enough either: the gateway registers its store,
persisted_hook_storereturns it directly, and that store skips an entry it cannot load, so the gate would stop there too. On keeps the gate running in every process, and it is no privilege gain, since anyone who can write hooks.json can write a realtrue.Dropped from the earlier revision: the
ScriptHookStore.update()hunk. Its only caller validatesenabledas a strict bool (HOOK_UPDATE_SCHEMA,_reject_null_enabled) before the store sees it. Also updated the staleacp/kas_wire.pycomment that saidfrom_dicttakesenabledverbatim.Backwards compatibility
Compatible: real booleans and an absent key load exactly as before;
null,"",0loaded falsy before and still load off; a non-empty unrecognised string (including whitespace-only) or list loaded on before and still loads on (now with a warning). Changed: off spellings ("false","off","0","no") go from on to off, and falsy junk ([],{},0.0) goes from off to on with a warning.Reader: src/kiro_crew/hook_runtime/script_hooks.py:ScriptHookStore.fire -- chat|subagent|cron -- gates on the coerced bool; test_registered_store_still_blocks_with_junk_enabled_gate
Reader: src/kiro_crew/hook_runtime/hook_dispatch.py:persisted_hook_store -- subagent|cron -- loads the same bool; test_persisted_store_loads_junk_enabled_gate_on
Reader: src/kiro_crew/acp/kas_wire.py:script hook export -- chat|subagent -- reads the same bool, unchanged for real bools
Reader: src/kiro_crew/acp/kas_agents.py:PreToolUse hook selection -- subagent -- reads the same bool, unchanged for real bools
Reader: src/kiro_crew/dashboard/handlers/hooks_scripts.py:toggle audit -- crew page -- logs the bool; toggle flips a real bool
Tests
test_from_dict_coerces_enabled(off/on spellings incl. case and padding, ints 0/1/2/-1, null, ""),test_from_dict_loads_unrecognised_enabled_on_with_warning("ture","y","n","junk","enabled",[1],["x"],[],{},1.0,0.0, and whitespace-only" "," ","\t\n","\u00a0"," \u00a0 "),test_from_dict_recognised_enabled_does_not_warn,test_from_dict_absent_enabled_defaults_on.test_store_load_keeps_hand_disabled_hook_off(hooks.json round trip with"false",0,null).test_registered_store_still_blocks_with_junk_enabled_gate: gateway path, a PreToolUseexit 2hook at"enabled""junk"/"ture"/[1]still fires and blocks.test_persisted_store_loads_junk_enabled_gate_on: standalone path loads the same gate on.pytest test/test_script_hooks.py test/test_hooks*.py test/test_hook_*.py test/test_kas_*.py: 2824 passed, 1 skipped.Manual verification
N/A — unit coverage sufficient: the change is a pure load-time coercion, covered end to end through hooks.json round trips and both gate store paths.
Related Issues
None - self-identified defect during hooks review.
Pattern harvest
Rule candidate: review-prompt
Pattern: hand-editable bool stored without coercion (
bool("false")trap); an unrecognised value on a deny gate must not be read as offChecklist
Contribution License Agreement
Contributed under the project Apache-2.0 license (see CONTRIBUTING.md).