Skip to content

fix(hooks): build a hook's tool_input from the call's structured params - #32830

Open
dimwael wants to merge 2 commits into
kirodotdev:mainfrom
dimwael:fix/hook-tool-input-raw-params
Open

dimwael wants to merge 2 commits into
kirodotdev:mainfrom
dimwael:fix/hook-tool-input-raw-params

Conversation

@dimwael

@dimwael dimwael commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: A preToolUse hook on a dashboard chat turn always gets the call's own arguments as tool_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_replace edit reaches the agent spec's preToolUse hook with no tool_input key. 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 ran json.loads(event.tool_input), the parse failed, a bare except Exception set the input to None, and ScriptHookStore.fire only adds tool_input when it is not None. 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

  • The subagent / task-runner PreToolUse path (SpecHooks.refuse in tool_permission.py): fix(hooks): give a subagent's PreToolUse hook an edit call's params #32219 covers it. This PR only threads raw_tool_params through that call, so the two do not overlap.
  • Changing what the approval card renders: the diff stays the card's text.
  • Letting a hook see a raw credential. Hook input stays redacted (see Security).

What changed (motivation → approach → change)

Approach. Build the hook payload's tool_input from raw_tool_params instead of parsing the display text, and redact it the way the approval card is redacted.

  • hook_runtime/hook_dispatch.py: new hook_tool_input(raw_params, display_input) -> dict | None.
    • Invariant: the hook never sees more than the approval card shows. With a params dict it dumps and redacts the params exactly as the tool-call parser builds the card's input text (json.dumps(..., indent=2), then the tool-row scrub agent_sdk.tool_row_text, the same redact_text the 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 no tool_input, as on main, and a deny hook still denies.
    • It runs under 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_SITES lists the site with that reason.
    • Without params it parses the display text as before; a parse failure is logged at warning on kiro_crew.hooks (with the traceback) instead of swallowed, and a non-object yields None.
    • fire_tool_hooks and permission_pre_tool_block take a trailing raw_tool_params: dict | None = None and build tool_input through it.
  • The four dashboard permission-arm PreToolUse sites (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) call hook_tool_input(event.raw_tool_params, event.tool_input) and lose their bare except Exception.
  • Every other fire_tool_hooks / permission_pre_tool_block caller passes raw_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.py re-exports the new name; test_hooks_composition_contract.py registers it and re-pins _BASE_SHAPE_DIGEST for the two trailing keyword defaults.
  • security_posture.py: hook_runtime/hook_dispatch.py joins NON_EGRESS_REDACTION_MODULES with its reason (a helper for the already-registered hook-fire sinks).
  • docs/system-specs/modules/memory-skills-hooks.md: the hook tool_input paragraph 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_input is still an object), now present where it was missing. No field, key or public function is renamed or removed.

Security

  • Hook input is redacted in full whatever the owner's redaction setting (always_scan), and never less than the display path redacts: test_nothing_the_display_path_masks_reaches_the_hook runs every case in secret_cases() (79) through both paths; returning the raw params turns 65 of them red.
  • test_params_are_redacted_inside_a_chat_seam_with_redaction_off fails without always_scan.
  • A secret whose detection needs a sibling (an access-key ID and its secret in separate list elements or fields) is masked: test_an_aws_secret_in_a_sibling_list_element_is_masked, test_an_aws_secret_in_a_sibling_field_is_masked and test_a_case_split_across_siblings_masks_what_the_display_path_masks over every secret_cases() case split across siblings.
  • A credential format only the loaded credential policy knows is masked in hook input (test_a_loaded_policys_own_pattern_is_masked_in_hook_input).
  • An Authorization: Bearer header inside JSON written by an edit is masked (test_an_authorization_header_in_json_edit_text_is_redacted, create and strReplace); property test: for every secret_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).
  • A number under a credential name never reaches the hook (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 no tool_input (test_a_private_key_before_the_path_gives_no_tool_input, test_an_unterminated_private_key_gives_no_tool_input, dashboard test_an_unterminated_private_key_fires_the_hook_without_tool_input); a result that does not read back gives no tool_input (test_a_dump_that_does_not_parse_gives_no_tool_input, end to end test_a_dump_that_does_not_parse_fires_without_tool_input).
  • The pinned redaction tests on the audit-source client path (test_acp_client_tool_hooks.py::test_pre_fire_redacts_credential_in_tool_input and its dict sibling) are unchanged and green.
  • Deny paths are unchanged: a hook that gets no tool_input still 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.
  • Credential-shaped values in tests come from redaction_structured_cases generators or are built from parts.

Tests

  • test/test_dashboard_approval.py::TestHookToolInputFromRawParams: drives a real _run_chat through the permission-arm sites. test_a_file_edit_hands_the_hook_its_arguments_not_the_diff (str_replace and fs_write create at auto_approve, allow_then_card, trusted_slot): the hook gets exactly {command, path, oldStr, newStr} / {command, path, content}; with the two dashboard files reverted to main all 6 cases fail with assert [None] == [...]. Also a URL token parameter reaches the hook with only its secret value masked, an unterminated private key fires the hook with no tool_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; nested Authorization: Bearer header, 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 yields None, an unparseable fallback logs one warning and yields None; end to end through a real hook subprocess for fire_tool_hooks and permission_pre_tool_block. The module runs as one xdist_group with 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 two pre_tool call-shape pins gain raw_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_diff over the call's params), driven through the real _run_chat permission 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/ and git 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.loads sites) -- changed here
Sibling: src/kiro_crew/acp/types.py -- not affected -- AcpEvent.shell_command reads raw_tool_params first and treats an unparseable tool_input as no command, which the gate denies by default
Sibling: 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

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

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.

@dimwael
dimwael requested review from a team and KiroCrewCaptain as code owners November 8, 2026 01:27
@dimwael
dimwael requested a review from Zedmor November 8, 2026 01:27
@github-actions github-actions Bot added the fork Pull request from a fork (external contributor) label Nov 8, 2026
@github-actions github-actions Bot added the readiness: action required A blocking check or review needs attention label Nov 8, 2026
@github-actions github-actions Bot added the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Nov 8, 2026
@dimwael
dimwael force-pushed the fix/hook-tool-input-raw-params branch from e2228eb to bdcc12d Compare November 8, 2026 05:28
@github-actions github-actions Bot added merge conflict Branch has merge conflicts with its base — author must resolve before merge and removed merge conflict Branch has merge conflicts with its base — author must resolve before merge labels Nov 8, 2026
@dimwael
dimwael force-pushed the fix/hook-tool-input-raw-params branch from bdcc12d to cb1f1c8 Compare November 8, 2026 08:28
@github-actions github-actions Bot removed the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Nov 8, 2026
@github-actions github-actions Bot added the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Nov 8, 2026
@dimwael
dimwael force-pushed the fix/hook-tool-input-raw-params branch from cb1f1c8 to e25dc8e Compare November 9, 2026 00:29
@github-actions github-actions Bot added merge conflict Branch has merge conflicts with its base — author must resolve before merge and removed merge conflict Branch has merge conflicts with its base — author must resolve before merge labels Nov 9, 2026
@dimwael
dimwael force-pushed the fix/hook-tool-input-raw-params branch from e25dc8e to ca80d23 Compare November 10, 2026 00:30
@github-actions github-actions Bot added merge conflict Branch has merge conflicts with its base — author must resolve before merge and removed merge conflict Branch has merge conflicts with its base — author must resolve before merge labels Nov 10, 2026
@dimwael
dimwael force-pushed the fix/hook-tool-input-raw-params branch from ca80d23 to 7383c99 Compare November 13, 2026 00:30
@github-actions github-actions Bot removed the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Nov 13, 2026
@KiroCrewCaptain

Copy link
Copy Markdown
Collaborator

Code change approver recommendation: A person should decide

Why: 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 7383c99d80 · 481 changed lines. If this recommendation is wrong, reply here: replies are how the approver is evaluated.

@buluoray

Copy link
Copy Markdown
Contributor

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 str_replace or fs_write create permission request carries the approval card's diff as its display text. That text is not JSON, so on main a preToolUse hook gets no tool_input and a write guard can only deny. Your hook_tool_input(event.raw_tool_params, ...) change already fixes it; this commit pins it.

  • test/test_dashboard_approval.py::TestHookToolInputFromRawParams::test_a_file_edit_hands_the_hook_its_arguments_not_the_diff: str_replace and fs_write create, at all four permission-arm sites (auto_approve, allow_then_card, trusted_slot). The hook must get {command, path, oldStr, newStr} / {command, path, content} exactly.
  • Red first: with tool_approval.py and permission_prompt.py reverted to main, all 6 cases fail with assert [None] == [{...}]. With this PR they pass; test_dashboard_approval.py + test_fire_tool_hooks.py: 102 passed.

No production code changed in this commit.

@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5, fork) — ⏭️ skipped

Revision 9d2374da6557ef3f73eb22bcf6abdac248b530f5 touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Does not block merge.

@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5, fork) — ✅ PASS

Design-level review of 9d2374da6557ef3f73eb22bcf6abdac248b530f5 via the fork AI-review pipeline — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

Nothing blocks: it fixes the root cause by building tool_input from the structured params the policy already judges, redacting them the way the approval card does, and using the same builder at every fire site.

Notes

  • Params that redaction turns into invalid JSON still reach the hook with no tool_input, so a deny-by-path hook keeps refusing those calls with the misleading "user rejected" text. That stays fail-closed and is no regression, but it is worth a follow-up issue.

[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 .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5, fork) — ✅ PASS

Premise-level review of 9d2374da6557ef3f73eb22bcf6abdac248b530f5 via the fork AI-review pipeline — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

First-Principles-Verdict: PASS

Nothing blocks. The fix sits at mechanism level: hooks now get tool_input from the call's structured params instead of parsing display text, and it reaches every PreToolUse caller, not just the one reported.

What this change ships

Inventory (7 items) — 7 justified

Intent: 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.

  1. On a dashboard chat turn, a PreToolUse hook now gets tool_input for str_replace/create edits. Before, the key was missing. — justified
  2. The other PreToolUse fire paths (ACP layer, channel, cron, subagent, task runner, CLI turn stream, tool_rows, tool_permission) build tool_input the same way, which closes the sibling instances of one root cause. — justified
  3. Hook tool_input is redacted in full even when the owner has turned redaction off (always_scan). — justified
  4. A second redaction pass over every parsed string value and key catches credentials inside JSON that the dump escaped. — justified
  5. When tool_input is not JSON, a warning is logged on kiro_crew.hooks instead of the failure being swallowed. — justified
  6. New hook_tool_input is re-exported from hooks.py, and two functions gain a trailing raw_tool_params kwarg. It has 4 call sites in chat_turn plus 2 inside hook_dispatch, and 12 callers pass the kwarg. — justified
  7. hook_dispatch.py is added to ALWAYS_REDACTED_SITES and NON_EGRESS_REDACTION_MODULES, the registries the redaction pins require. — justified

[FIRST-PRINCIPLES-REVIEWED] 9d2374d

Description read

[DESCRIPTION-READ] 181352969422b6b583e74caeb0a4e757e97bddaa19312d0b278d3c41f8bd4acc

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review (fork) — ✅ no blocking findings

Reviewed 9d2374da6557ef3f73eb22bcf6abdac248b530f5 via the fork AI-review pipeline; updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 9d2374d

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Nov 18, 2026
@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Security Scope Review (fork) — ✅ PASS

Which legitimate operations does 9d2374da6557ef3f73eb22bcf6abdac248b530f5 newly refuse? Model proposes, scripts/deny_diff.py decides — updated in place on each push. A script-confirmed regression blocks PR readiness.

adjudicated, zero confirmed regressions

Scope-Verdict: PASS

Reason: The patch doesn't touch any deny-composite tier (sensitive-bash, exfil, deny-rules). What got stricter is the redaction of the PreToolUse hook payload's tool_input, so the shell candidates can only show that ordinary commands are no worse off. The real narrowing is that hooks newly receive no tool_input at all in some cases. The classifier can't measure that, so it is named under UNADJUDICATED and does not block.

TIGHTENING: Every PreToolUse fire now builds its hook tool_input through a single builder, hook_dispatch.hook_tool_input. It uses the structured raw_tool_params, applies the full redaction pass under always_scan(), then runs redact_via_context over the keys and strings again -- the ONE threat it refuses is a hook script seeing a credential the approval card masks: with always_scan(): whole = redact_via_context(tool_row_text(dump)) ... return {redact_via_context(key): redact_strings(value) for key, value in parsed.items()}.

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 (curl with $VAR against curl.exe with %VAR%), the touched test runs (.venv/bin/python with / against .venv\Scripts\python.exe with \), reading the saved hooks.json (cat ~/… against type %USERPROFILE%\…), and a hook script reading its stdin payload (python3 against py). One any row, ls -la, is the exact command the PR's test_tool_permission.py threads through SpecHooks. The diff adds no path, separator, or interpreter assumption of its own: hook_tool_input works on JSON dicts and is platform-neutral. Every platform spelling the touched call paths can carry has a row.

UNADJUDICATED: The guard is hook_dispatch.hook_tool_input. Inputs reach it from these callers: fire_tool_hooks (via acp/client_tool_events._maybe_fire_pre_tool_hooks, dashboard/chat_turn/tool_rows._on_tool_call, llm_helpers_parts/turn_stream.stream_and_collect, subagent_manager/run_turn, task_executor.execute_task, messaging/tool_hooks.ChannelTurnHooks); permission_pre_tool_block (via tool_permission.SpecHooks, channel_spec_hooks.pre_tool_refusal, cron_service/turn_hooks, ChannelTurnHooks); and the dashboard arm's four sites in tool_approval._decide_permission_request and permission_prompt._on_permission_prompt. Its output is the tool_input key of a user hook process's stdin, not a deny decision, so no shell verdict exists for it. These are the legitimate inputs I would have submitted, in prose:
(a) A shell call whose raw params contain a number under a listed credential-name key, e.g. env.DB_PASSWORD as an integer. The mask replaces the number, the dump no longer parses, and the hook gets no tool_input. It previously got none either, because the display text didn't parse.
(b) A file write whose params pass the card's scrub, but where the loaded credential policy's extra pattern (redact_via_context, applied on top of tool_row_text) masks JSON syntax inside the dump. The card shows parseable params, yet the hook newly gets no tool_input.
(c) A shell call carrying an unterminated private-key block. The hook gets no tool_input, the same as the display path before.
(d) A user's PreToolUse hook that guards writes by tool_input.path or blocks by tool_input.command. It now receives the structured params, including for file edits that previously gave it none. A hook that exits 2 on any present tool_input could newly block edits it used to wave through.
None of these can be shown as a shell row. They are evidence for a human to weigh, not confirmed regressions. Case (b) is the only one that newly drops tool_input because of this change.

[SCOPE-REVIEWED] 9d2374d

Security scope review -- adjudicated candidates

  • macos-latest (platform posix): 9 classified, 0 newly refused, 9 still allowed.
  • ubuntu-latest (platform posix): 9 classified, 0 newly refused, 9 still allowed.
  • windows-latest (platform windows): 6 classified, 0 newly refused, 6 still allowed.

No candidate flipped from allowed to refused.

@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review (fork) — ✅ no blocking findings

Reviewed 9d2374da6557ef3f73eb22bcf6abdac248b530f5 via the fork AI-review pipeline; updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 9d2374d

@buluoray
buluoray force-pushed the fix/hook-tool-input-raw-params branch from f597c41 to 9c88e6c Compare November 18, 2026 03:42
@buluoray

Copy link
Copy Markdown
Contributor

New head 9c88e6c0d25 (still two commits):

  • GPT lane BLOCK on f597c41 (D8, interpreter children in test_fire_tool_hooks.py), fixed. The module now carries pytestmark = pytest.mark.xdist_group(name="fire_tool_hooks_probe"), so every case that starts a real hook child runs on one worker and they never cold-start in parallel. The probe script is a module-scoped fixture, written once; each case keeps its own output file, cwd and store. A hook child per fire stays: launching that child is what run_script_hook does, and these cases exist to prove the real stdin payload carries tool_input. Local: 41 passed serially, with -n 4 --dist loadgroup, and in reversed order; the repo's black and comment-history gates pass.

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
@buluoray
buluoray force-pushed the fix/hook-tool-input-raw-params branch from 9c88e6c to 04e80f7 Compare November 18, 2026 05:19
@github-actions github-actions Bot removed the readiness: action required A blocking check or review needs attention label Nov 18, 2026
@buluoray

Copy link
Copy Markdown
Contributor

Rebased onto main 5ca143070dc (new head 04e80f7e7a1, still two commits, dimwael's first).

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 New-test stability red). The production fix still stands; the tests now follow main's semantics.

  • Hook inputs stay redacted with the owner's setting off. 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 hook_tool_input builds tool_input under always_scan() (as the Stop hook payload does), and hook_runtime/hook_dispatch.py is listed in redaction_seams.ALWAYS_REDACTED_SITES. New test: test_params_are_redacted_inside_a_chat_seam_with_redaction_off (fails without always_scan).
  • Parity with the display path: test_nothing_the_display_path_masks_reaches_the_hook runs all 79 secret_cases() through both paths; returning raw params turns 65 red.
  • Rewritten on main's fixtures: the URL cases assert a URL keeps its shape with only the secret value masked; the key-bound case uses a listed credential name; the "display text is not JSON" repro uses an unterminated private-key block, which still swallows the display JSON's closing quote on main. The edit-call tests are unchanged and green.
  • Dropped: test_a_non_string_value_under_a_secret_key_is_redacted: main's rule table does not mask a number under a credential name, on either path.

Local: the five touched test files + test_redaction_one_setting.py: 629 passed (-n 4 --dist loadgroup); test_security_posture.py, test_credential_redaction_switch.py, test_redaction_facade.py pass; flake8, mypy, the black and comment-history gates pass.

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Nov 18, 2026
@dimwael

dimwael commented Nov 18, 2026

Copy link
Copy Markdown
Contributor Author

@buluoray thanks for carrying this. I reproduced the CI reds on 9c88e6c0d2 merged with current main (54b60f24a9; the PR base is ~1,350 commits behind, merge is conflict-free). Three causes, patches ready as a gist (apply clean on the merge): https://gist.github.com/dimwael/614d22d0a1ab00bdfbc402148da6d89b

A — mine (7383c99). test_workflow_security.py::TestMaxTurns ×3 and test_subagent_turn_resilience.py::test_transient_error_after_tool_call_sends_continue_prompt: AttributeError: … no attribute 'raw_tool_params'. My commit reads event.raw_tool_params directly at 10 sites (turn_stream.py:413, run_turn.py, the four hook_tool_input(event.raw_tool_params, …) calls, and the pass-throughs); upstream fakes (FakeEvent, SimpleNamespace) don't carry it. Fix in kc-32388-groupA.patch: getattr(event, "raw_tool_params", None) at all 10 sites, matching the channel/cron/CLI callers and AcpEvent's own None default. Mutation-checked.

B + D — main drift from #37408 (one redaction switch, rule table only, value-only masks), breaking both your TestHookToolInput cases and my test_pre_fire_builds_tool_input_from_raw_params_still_redacted. All 12 stability-job failures reproduce deterministically on pass 1 with the job's exact command; no order/repeat dependence. On main now: redaction is off by default outside always-scan seams; the whole-URL [REDACTED: suspicious URL …] rewrite is gone (only credential values inside a URL are masked); the rule table masks listed vendor formats and named-key pairs only, so AKIAIOSFODNN7EXAMPLE stays visible, a short or non-string value under aws_secret_access_key isn't masked, and masks are value-only so they never break JSON — hence the DID NOT RAISE JSONDecodeError. Fix in kc-32388-groupBD.patch: the structural "display text isn't JSON" repro becomes the file-edit diff you already pinned (derive_edit_diff); redaction cases use kiro_crew.testing.synthetic_credentials (github_classic, 40-char aws_secret), as #31863 did for the pinned pair; your nested-bearer and credential-as-key cases stay (still valid, mutation-checked); I dropped "non-string value under a secret key" since the table no longer masks by key name alone; dashboard-arm shell cases use a benign command because exfil.refuses now rejects a credential-bearing command before any hook fires; docs paragraph restated on main's premise.

C — not this PR. test_kas_policy_hidden_readiness ×2, test_unexpected_cancel_after_tool_activity_finalizes_without_respawn, test_subagent_empty_turn_after_work ×4 pass on plain origin/main and on the merge tree (-n 4 and -n0); shard-load flakes.

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 (redact_via_context) honours the owner switch, so a hook sees unredacted params when the switch is off (the default), like every other owner-alone surface. If hook stdin should stay redacted regardless (the decision doc lists Stop hook payloads as always-redacted), the helper wants always_scan() or an output seam. Your call.

I won't push over your commit; take the patches as you see fit, or tell me to apply them as a third commit.

@dimwael

dimwael commented Nov 18, 2026

Copy link
Copy Markdown
Contributor Author

Follow-up on 04e80f7e7a: your rebase supersedes my B/D patch — same premise, and always_scan() on hook_tool_input settles the policy point. Thanks.

One piece remains, and it is mine: the 10 direct event.raw_tool_params reads in af3bc18bef. On 04e80f7e7a they still fail test_workflow_security.py::TestMaxTurns ×3 and test_subagent_turn_resilience.py::test_transient_error_after_tool_call_sends_continue_prompt (AttributeError on upstream fakes without the attribute), and I was wrong to call the test_subagent_empty_turn_after_work ×4 and the first-yield timeout flakes: the subagent run dies on the same read, the error is logged ("Subagent … failed") rather than raised, and the turn then yields nothing. All pass with the fix. Only test_kas_policy_hidden_readiness ×2 was real drift (#38941), and your rebase already has it.

kc-32388-groupA-v2.patch in the gist (https://gist.github.com/dimwael/614d22d0a1ab00bdfbc402148da6d89b): getattr(event, "raw_tool_params", None) at the 10 sites, matching the channel/cron/CLI callers and AcpEvent's default, plus the caller-sweep pin widened to the getattr spelling and the three later callers. Applies clean on 04e80f7e7a; 9 files, +26/−13; our four hook suites + the formerly red tests → 437 passed; comment-history and black ratchet green. Say the word and I'll push it as a third commit, or fold it into yours.

@buluoray
buluoray force-pushed the fix/hook-tool-input-raw-params branch 3 times, most recently from c033feb to 6837922 Compare November 18, 2026 07:51
@buluoray

Copy link
Copy Markdown
Contributor

span=3202497c8b94
self-added: yes
mechanism: leaf fallback in hook_tool_input returned non-string leaves raw
resolution: removed

  • Fallback leaf pass returned non-string credentials raw

fixed in 6837922: the leaf fallback is removed. Strings are masked one by one, then the JSON dump of the result is masked as one text, the pass the display path runs, so a number under a credential name is caught there.
A result that does not read back as an object gives no tool_input, as on main, so the number never reaches the hook.
Tests: test_a_number_under_a_listed_credential_name_never_reaches_the_hook, test_a_dump_that_does_not_parse_gives_no_tool_input, test_a_dump_that_does_not_parse_fires_without_tool_input.

@buluoray

Copy link
Copy Markdown
Contributor

span=28c0e341313c
self-added: yes
mechanism: leaf fallback tagged keys after an unterminated private-key mask
resolution: removed

  • Fallback redaction removes unrelated argument keys

fixed in 6837922: the leaf fallback is removed. Each string is masked on its own first, and a string whose mask runs to its end becomes the tag alone, so an unterminated private-key block stays inside its own value and cannot reach path.
The whole-object pass then runs on that result for context pairs; a key ID in a partly masked value still pairs with its sibling secret.
Tests: test_a_private_key_before_the_path_leaves_the_path_intact, test_a_key_id_in_a_partly_masked_value_still_pairs_with_its_secret, test_a_pair_beside_an_unterminated_private_key_is_masked.

@buluoray buluoray closed this Nov 18, 2026
@buluoray buluoray reopened this Nov 18, 2026
@buluoray
buluoray force-pushed the fix/hook-tool-input-raw-params branch from 6837922 to f0e1c6b Compare November 18, 2026 08:54
@buluoray

Copy link
Copy Markdown
Contributor

span=28c0e341313c
self-added: yes
mechanism: per-value rewrite before the whole-object pass dropped pairing context
resolution: removed

  • Collapsing a value removes context needed to redact sibling credentials

fixed in f0e1c6b: the class is closed. Every pass that rewrote a value before the whole-object pass is removed (the per-value mask and the run-to-end rule).
Invariant: the hook never sees more than the approval card shows. tool_input is the params dumped and redacted exactly as the tool-call parser builds the card's input text, one whole-text pass, so a key ID always sits beside its secret when the rule runs.
If the redacted text does not parse to an object, the hook gets no tool_input, as on main, and a deny hook still denies.
Tests: test_a_key_id_before_a_private_key_still_masks_its_paired_secret, test_a_key_id_in_a_partly_masked_value_still_pairs_with_its_secret, test_a_private_key_before_the_path_gives_no_tool_input, test_a_dump_that_does_not_parse_gives_no_tool_input.

@buluoray
buluoray force-pushed the fix/hook-tool-input-raw-params branch 2 times, most recently from 626266a to 68928a3 Compare November 18, 2026 09:35
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.
@buluoray
buluoray force-pushed the fix/hook-tool-input-raw-params branch from 68928a3 to 9d2374d Compare November 18, 2026 10:18
@buluoray

Copy link
Copy Markdown
Contributor

span=28c0e341313c
self-added: yes
mechanism: JSON escaping of string contents hid a quote-bound pattern from the whole-text pass
resolution: narrowed

  • JSON escaping bypasses credential redaction in file-edit hook input

fixed in 9d2374d: after the whole-text pass and the read-back, every parsed string value and key is redacted once more (redact_via_context, under always_scan). It runs after pairing is done and only masks more; a mask inside one parsed value cannot break the object.
Invariant kept: the hook never sees more than the approval card shows.
Tests: test_an_authorization_header_in_json_edit_text_is_redacted (create and strReplace), test_raw_and_json_embedded_cases_hide_every_word_the_card_masks (every secret_cases() case, raw and inside a JSON string), test_parsed_strings_and_keys_are_redacted_inside_an_off_chat_seam.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fork Pull request from a fork (external contributor) readiness: action required A blocking check or review needs attention

Projects

None yet

Development

Successfully merging this pull request may close these issues.

preToolUse hooks get no tool_input when the URL scrubber hits a double-quoted URL in a shell command

3 participants