Repository navigation
Conversation
e2228eb to
bdcc12d
Compare
bdcc12d to
cb1f1c8
Compare
cb1f1c8 to
e25dc8e
Compare
e25dc8e to
ca80d23
Compare
ca80d23 to
7383c99
Compare
Code change approver recommendation: A person should decideWhy: the decider thinks the change is probably fine but estimates an 18% chance that this change introduces a defect, above the 12% limit for approving on its own. Approve. The PR fixes the bug it targets: a hook's tool_input is now built from the call's structured raw_tool_params, with each string value redacted through redact_via_context, instead of parsing display JSON whose redaction could eat an escaping backslash. All 11 call sites of fire_tool_hooks, permission_pre_tool_block and SpecHooks._pre_tool pass the params, including channel, cron and messaging ones the PR description doesn't list. The four dashboard permission sites lose their silent bare-except parse. Redaction stays at least as strong as before (stronger on the ACP client path, which used bare security.redact). The params come from the same tool-call cache or inline frame as the display text, so there is no trust change. The display-text fallback now logs a warning when parsing fails. Tests cover the unit cases, a real hook subprocess end to end, all four dashboard sites, the ACP client path, and a source check on the callers. 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 |
|
Hi @dimwael, we are helping land this one. Your commit stays as it is; we added one test commit on top (d88774d). Why: the same root cause also hits file edits on the dashboard. A
No production code changed in this commit. |
UX Review (Opus 5.5, fork) — ⏭️ skippedRevision |
Design Review (Opus 5.5, fork) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks: it fixes the root cause by building Notes
[DESIGN-REVIEWED] 9d2374d Description read[DESCRIPTION-READ] d3e4822d55520b9c4245172476cd7983bddb4a258b9bfb779ad5815665d33033 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, fork) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Nothing blocks. The fix sits at mechanism level: hooks now get What this change shipsInventory (7 items) — 7 justifiedIntent: let an agent spec's PreToolUse hook read the arguments of a dashboard file edit (path included), so a path-scoped hook can allow edits instead of always denying. FIX.
[FIRST-PRINCIPLES-REVIEWED] 9d2374d Description read[DESCRIPTION-READ] 181352969422b6b583e74caeb0a4e757e97bddaa19312d0b278d3c41f8bd4acc That sha256 names the PR description this verdict read. Recompute it with |
Opus 5.5 Review (fork) — ✅ no blocking findingsReviewed |
Security Scope Review (fork) — ✅ PASSWhich legitimate operations does adjudicated, zero confirmed regressions Scope-Verdict: PASS Reason: The patch doesn't touch any deny-composite tier ( TIGHTENING: Every PreToolUse fire now builds its hook ADJUDICATED: 14 candidates, 0 confirmed newly-refused PLATFORM COVERAGE: posix and windows rows cover the same operations: a token-URL curl and a bearer-header curl ( UNADJUDICATED: The guard is [SCOPE-REVIEWED] 9d2374dSecurity scope review -- adjudicated candidates
No candidate flipped from allowed to refused. |
GPT 6.1 Review (fork) — ✅ no blocking findingsReviewed Review detailsNo findings. |
f597c41 to
9c88e6c
Compare
|
New head
|
A PreToolUse hook's stdin `tool_input` was parsed out of the tool call's rendered display JSON after the exfiltration-URL scrubber ran on that text. A `[REDACTED: …]` tag replacing a URL inside an escaped `\"` consumed the backslash, the text no longer parsed, the error was swallowed and the payload went out with no `tool_input` key, so a fail-closed hook refused a harmless read. `hook_dispatch.hook_tool_input` now builds it from `raw_tool_params`, the dict the built-in tool policy already judges, redacting each string value on its own, so the redaction cannot break the JSON around it and hook scripts keep seeing redacted input. Every PreToolUse fire goes through it: the dashboard permission arm, the informational tool-call fire and the subagent/task-runner gate. An event with no structured params still parses the display text, and a parse failure is logged at warning instead of dropped. Closes kirodotdev#32388
9c88e6c to
04e80f7
Compare
|
Rebased onto main Why: main's redaction rework (rule table only, value-only masks, owner setting off by default) changed what the scrubber does, so 16 tests here failed on the merge with main (the
Local: the five touched test files + |
|
@buluoray thanks for carrying this. I reproduced the CI reds on A — mine (7383c99). B + D — C — not this PR. With A + B/D applied on the merge: 13,044 passed across the importing files, guards, contracts and the four red suites; black/comment-history/line-cap/docs-lint/mypy green. One policy point I did not decide: under #37408 the helper ( I won't push over your commit; take the patches as you see fit, or tell me to apply them as a third commit. |
|
Follow-up on One piece remains, and it is mine: the 10 direct
|
c033feb to
6837922
Compare
|
span=3202497c8b94
|
|
span=28c0e341313c
|
6837922 to
f0e1c6b
Compare
|
span=28c0e341313c
|
626266a to
68928a3
Compare
The hook never sees more than the approval card shows. A hook's tool_input is the call's params dumped and redacted exactly as the tool-call parser builds the card's input text, one whole-text pass, so every pairing a rule needs (an AWS key ID beside its secret, a header name beside its token, a credential name beside its value) is kept. The loaded credential policy's own patterns then run over that same text; they only mask more. After the read-back, every parsed string value and key is redacted once more, so a credential inside JSON file content whose quotes the dump escapes is masked too. When the redacted text parses to an object, that object is the input; otherwise the hook gets no tool_input, as on main, and a deny hook still denies. The pass runs under always_scan(), and the site is listed in ALWAYS_REDACTED_SITES: a dashboard turn runs inside the chat output seam, where the owner's redaction setting can stand down. Pin a dashboard file edit's preToolUse tool_input to the call's own arguments: a str_replace or fs_write create permission request carries the approval card's diff as display text, which is not JSON.
68928a3 to
9d2374d
Compare
|
span=28c0e341313c
|
Problem / Motivation
Goal: A
preToolUsehook on a dashboard chat turn always gets the call's own arguments astool_input, file edits included, and those arguments are always redacted, whatever the owner's redaction setting.Reported by a user on 0.12.2 with the KAS harness: in a dashboard chat, every
str_replaceedit reaches the agent spec'spreToolUsehook with notool_inputkey. A hook that guards file writes by path cannot read a path, so it can only deny, every time. Reads, shell and MCP calls are fine.Root cause: for a file edit, the permission request's display text (
event.tool_input) is the unified diff drawn for the approval card (derive_edit_diff), not JSON. The four dashboard PreToolUse sites ranjson.loads(event.tool_input), the parse failed, a bareexcept Exceptionset the input toNone, andScriptHookStore.fireonly addstool_inputwhen it is notNone. The call's structured arguments were already on the event (AcpEvent.raw_tool_params, the dict the built-in tool policy judges), and nothing handed them to the hook.The same gap hit a shell command whose display JSON a redaction mask broke (#32388). That repro is gone on current main, but a mask can still break the display JSON: an unterminated private-key block runs to the end of the text and swallows the closing quote and brace.
Why it matters
A spec hook that guards writes by path is the normal way to scope an agent ("this agent may only write tests"), and the fail-closed shape is the one the security docs recommend. With this bug that agent can run shell commands but cannot edit a single file on the dashboard, and the refusal it reports ("The user rejected this tool call") misleads both the model and the user. kiro-cli hands its own hooks the edit's arguments, so the same hook works there and fails here.
Not a goal
SpecHooks.refuseintool_permission.py): fix(hooks): give a subagent's PreToolUse hook an edit call's params #32219 covers it. This PR only threadsraw_tool_paramsthrough that call, so the two do not overlap.What changed (motivation → approach → change)
Approach. Build the hook payload's
tool_inputfromraw_tool_paramsinstead of parsing the display text, and redact it the way the approval card is redacted.hook_runtime/hook_dispatch.py: newhook_tool_input(raw_params, display_input) -> dict | None.json.dumps(..., indent=2), then the tool-row scrubagent_sdk.tool_row_text, the sameredact_textthe card uses, over the whole text, once). One whole-text pass keeps every pairing a rule needs (an AWS access-key ID beside its secret,"Authorization": "Bearer …", a credential name beside its value). The loaded credential policy's own patterns (redact_via_context) then run over that same text; they only mask more, so the hook can see less than the card, never more. If the redacted text parses to an object, every string value and key in it is redacted once more, after pairing is done, so a credential inside JSON file content whose quotes the dump escapes (an edit writing"Authorization": "Bearer …") is masked as the card's diff masks it; that object is the input. If not (a mask replaced a number or covered JSON syntax, as an unterminated private-key block's does), the hook gets notool_input, as onmain, and a deny hook still denies.redaction_switch.always_scan(). A dashboard turn runs inside the chat output seam, where the credential pass stands down when the owner turns redaction off; a hook is a sink no seam lists, so its input is redacted in full, as the Stop hook payload already is.redaction_seams.ALWAYS_REDACTED_SITESlists the site with that reason.kiro_crew.hooks(with the traceback) instead of swallowed, and a non-object yieldsNone.fire_tool_hooksandpermission_pre_tool_blocktake a trailingraw_tool_params: dict | None = Noneand buildtool_inputthrough it.chat_turn/tool_approval.py: context-builder auto-approve, allow-before-card, trusted/yolo slot;chat_turn/permission_prompt.py: the card's own approve) callhook_tool_input(event.raw_tool_params, event.tool_input)and lose their bareexcept Exception.fire_tool_hooks/permission_pre_tool_blockcaller passesraw_tool_params=getattr(event, "raw_tool_params", None):chat_turn/tool_rows.py,acp/client_tool_events.py,channel_spec_hooks.py,cron_service/turn_hooks.py,messaging/tool_hooks.py,subagent_manager/run_turn.py,task_executor.py,llm_helpers_parts/turn_stream.py,tool_permission.py.hooks.pyre-exports the new name;test_hooks_composition_contract.pyregisters it and re-pins_BASE_SHAPE_DIGESTfor the two trailing keyword defaults.security_posture.py:hook_runtime/hook_dispatch.pyjoinsNON_EGRESS_REDACTION_MODULESwith its reason (a helper for the already-registered hook-fire sinks).docs/system-specs/modules/memory-skills-hooks.md: the hooktool_inputparagraph states how it is built and redacted and which tests pin it.Backwards compatibility
Compatible: both changed functions gain a trailing keyword defaulting to
None, so every existing caller fits. The hook payload shape is unchanged (tool_inputis still an object), now present where it was missing. No field, key or public function is renamed or removed.Security
always_scan), and never less than the display path redacts:test_nothing_the_display_path_masks_reaches_the_hookruns every case insecret_cases()(79) through both paths; returning the raw params turns 65 of them red.test_params_are_redacted_inside_a_chat_seam_with_redaction_offfails withoutalways_scan.test_an_aws_secret_in_a_sibling_list_element_is_masked,test_an_aws_secret_in_a_sibling_field_is_maskedandtest_a_case_split_across_siblings_masks_what_the_display_path_masksover everysecret_cases()case split across siblings.test_a_loaded_policys_own_pattern_is_masked_in_hook_input).Authorization: Bearerheader inside JSON written by an edit is masked (test_an_authorization_header_in_json_edit_text_is_redacted,createandstrReplace); property test: for everysecret_cases()case, placed raw or inside a JSON string, nothing the card masks appears raw in the hook input (test_raw_and_json_embedded_cases_hide_every_word_the_card_masks); the last pass runs with the owner's redaction off too (test_parsed_strings_and_keys_are_redacted_inside_an_off_chat_seam).test_a_number_under_a_listed_credential_name_never_reaches_the_hook); a key ID still pairs with its secret, in a partly masked value or before an unterminated private-key block (test_a_key_id_in_a_partly_masked_value_still_pairs_with_its_secret,test_a_key_id_before_a_private_key_still_masks_its_paired_secret); an unterminated private-key block gives notool_input(test_a_private_key_before_the_path_gives_no_tool_input,test_an_unterminated_private_key_gives_no_tool_input, dashboardtest_an_unterminated_private_key_fires_the_hook_without_tool_input); a result that does not read back gives notool_input(test_a_dump_that_does_not_parse_gives_no_tool_input, end to endtest_a_dump_that_does_not_parse_fires_without_tool_input).test_acp_client_tool_hooks.py::test_pre_fire_redacts_credential_in_tool_inputand its dict sibling) are unchanged and green.tool_inputstill sees no input and can still refuse. The display, log and audit surfaces render what they did; the hook stdin payload is not logged or persisted.redaction_structured_casesgenerators or are built from parts.Tests
test/test_dashboard_approval.py::TestHookToolInputFromRawParams: drives a real_run_chatthrough the permission-arm sites.test_a_file_edit_hands_the_hook_its_arguments_not_the_diff(str_replaceandfs_writecreate atauto_approve,allow_then_card,trusted_slot): the hook gets exactly{command, path, oldStr, newStr}/{command, path, content}; with the two dashboard files reverted tomainall 6 cases fail withassert [None] == [...]. Also a URL token parameter reaches the hook with only its secret value masked, an unterminated private key fires the hook with notool_input, and the tool-call frame's informational fire carries the params.test/test_fire_tool_hooks.py::TestHookToolInput(unit): structured params win over display text; nestedAuthorization: Bearerheader, a listed credential name, a credential used as a key are redacted; a URL keeps its shape with only the secret value masked; the display-path parity and chat-seam tests above; no-params fallback parses, a non-object yieldsNone, an unparseable fallback logs one warning and yieldsNone; end to end through a real hook subprocess forfire_tool_hooksandpermission_pre_tool_block. The module runs as onexdist_groupwith a module-scoped probe script, so its hook children never cold-start in parallel.test/test_acp_client_tool_hooks.py::test_pre_fire_builds_tool_input_from_raw_params_still_redacted: the audit-source client path hands the hook the redacted dict when the display text is not JSON.test/test_tool_permission.py: the twopre_toolcall-shape pins gainraw_tool_params.Local on main
5ca143070dc: the five files above +test_redaction_one_setting.py,test_security_posture.py,test_workflow_security.py,test_subagent_empty_turn_after_work.py: 979 passed (-n 4 --dist loadgroup); flake8, mypy, the black and comment-history gates pass.Manual verification
N/A — unit coverage sufficient: the edit repro is the exact display text the KAS parser produces (
derive_edit_diffover the call's params), driven through the real_run_chatpermission arm, and the hook payload is read through a real hook subprocess's stdin.Related Issues
Closes #32388
Related: #32219 (the subagent/task-runner half of the same gap).
Sibling sweep
Swept:
git grep -nE "json\.loads\((event|tool_event)\.tool_input\)" -- src/andgit grep -nE "_parsed_input = None" -- src/Sibling: src/kiro_crew/dashboard/chat_turn/permission_prompt.py -- changed here
Sibling: src/kiro_crew/dashboard/chat_turn/tool_approval.py (three sites) -- changed here
Sibling: src/kiro_crew/hook_runtime/hook_dispatch.py (both
json.loadssites) -- changed hereSibling: src/kiro_crew/acp/types.py -- not affected --
AcpEvent.shell_commandreadsraw_tool_paramsfirst and treats an unparseabletool_inputas no command, which the gate denies by defaultSibling: src/kiro_crew/tool_permission.py -- changed here (params threaded; #32219 owns the rest)
Pattern harvest
Rule candidate: review-prompt
Pattern: build a hook's or a gate's input from the call's structured params, never by re-parsing display text: display text may be a rendered diff or a masked string that is no longer JSON.
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)Contribution License Agreement
Contributed under the project's Apache-2.0 license (CONTRIBUTING.md, Licensing).
Original change and design by @dimwael; the file-edit tests, the key-bound redaction and the forced redaction for hook input were added on top to help land it.