Skip to content

fix(security): exempt the file-search builtin from the curl upload-flag exfil rows - #23845

Closed
chenmingwei23 wants to merge 1 commit into
mainfrom
fix/exfil-upload-program-scope-23586
Closed

chenmingwei23 wants to merge 1 commit into
mainfrom
fix/exfil-upload-program-scope-23586

Conversation

@chenmingwei23

@chenmingwei23 chenmingwei23 commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: stop the built-in file-search (Grep) tool being refused for text that merely appears in its title.

Bug fix: the exfiltration gate's curl body/upload rows match their substring/glob over the whole judged text. A file-search tool call has no shell command; its title is LLM-authored prose that can carry the literal flag text, so the gate refused the search tool even though it runs no shell and uploads nothing (#23586).

Why it matters

A benign file-search for the literal pattern text is blocked, so an agent cannot search the codebase for these flag strings (for example when working on the exfil gate itself). The refusal looks to the agent like a human cancellation.

Not a goal

  • No shell-command exception is added. A real shell command that merely contains the flag text (echo/printf of it) stays refused, exactly as on main.
  • exfil_bash.py is not changed; date -d @<epoch> keeps passing via main's own pre-existing exception.

What changed (motivation → approach → change)

Symptom: a file-search tool call is refused by the exfil tier for its title text. Root cause: the exfil rows are matched against the judged title, and a file-search builtin has no command of its own, so only the title reaches them. Change: GateFacts.is_file_search_builtin recognises a file-search builtin by a POSITIVE tool identity and argument shape — never by title text, so no title can opt a shell tool out, and (the stricter part) a call that merely happens to carry a pattern argument cannot opt itself in. The exemption fires only when every condition holds: not a shell tool, no recovered command/cmd argument (raw_shell_commands empty), not MCP-served, call.kind == "search" AND the host-stamped tool name (_meta.kiro.toolName, normalized) is in the new _SEARCH_BUILTIN_TOOL_NAMES set (grep, glob), and the arguments are search-shaped. call.kind is agent-influenced and can only narrow here; the host-stamped tool name is the non-model-authored discriminator, so a kind=other / kind=fetch call that writes a pattern argument no longer skips the exfil tier. _rule_exfil returns None only for such a positively-identified search builtin; every other call keeps the full rows.

Backwards compatibility

Compatible: the change only ADDS an exemption for a file-search builtin; it rejects/renames/removes nothing main accepts. No public name, config key, or rule id changed, and exfil_bash.py and the exfil facade are unchanged from main.

Removes nothing: no path is hidden, no record/row deleted, no validator tightened, no key or public function removed — the diff adds one GateFacts property and an early return None in one gate rule.

Tests

test/test_exfil_search_tool_carveout_23586.py: a file-search call identified by kind == "search" and the grep tool name is allowed; the same title on a shell tool is refused by the exfil tier; a kind=other frame carrying both a command and a pattern is refused. The positive-identity boundary is pinned by three cases that all stay refused: a kind=other call and a kind=fetch call (the two kinds the probe named) that carry the flag text in the title and a search-shaped pattern argument but no search tool identity, and a shell call that also carries a pattern argument. echo/printf of the flag text, plus every upload / wrapper / interpreter / path-qualified form, stay refused. Reverting the gate change makes the kind=other and kind=fetch boundary cases fail, confirming they pin the defect.

Proof: not provable -- the fix is in the invocation gate (_rule_exfil early return), not in audit_bash_exfiltration; the new assertions exercise the full HookManager.judge path, and reverting the one-line gate change makes the file-search assertion fail. Classed: other -- gate-layer behaviour exercised through the judge, not a single revertible production hunk prove.py targets.

Manual verification

N/A — unit coverage through the real gate (HookManager.judge) is sufficient; this is a backend-only gate change with no UI.

Related Issues

Fixes #23586

Sibling sweep

Swept: git grep -n "is_file_search_builtin|_rule_exfil|_search_deny_target" -- src/kiro_crew
Sibling: src/kiro_crew/hook_runtime/gate_tiers.py:_rule_exfil -- changed here -- the one place the exfil rule runs on a file-search builtin's title.
Siblings: none -- the file-search target (_search_deny_target) never carried the pattern, so the title path in _rule_exfil was the only site refusing a search tool for its text.

Pattern harvest

Not generalizable: this is a one-off scoping of one tool kind out of one gate rule; the fix is specific to the file-search builtin's title reaching the exfil rows and does not describe a reusable defect class.

CI note

Backend Tests shards 3.12 (4), Windows (4) and macOS (1) report one failure, test/test_governance_policy_viewer.py::TestNoPolicyDefault::test_enterprise_unnamed_scope_reports_the_baseline, with PlatformCompositionError: ... could not fetch the ceiling ... urlopen error ... Name or service not known. This is a runner network/DNS failure reaching the policy source, not a code result: this PR touches no governance/policy code (only gate_tiers.py, hooks.py, and one new test), and the identical failure appears on unrelated open backend-only PRs. It is main's, left as-is (no rerun). Every other shard and gate is green.

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

@github-actions

github-actions Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Sensitive Change Review

Sensitive files changed:

  • src/kiro_crew/hook_runtime/gate_tiers.py

  • src/kiro_crew/hooks.py

  • @chenmingwei23 posted a complete reasoning template for 37e4456.

@github-actions

github-actions Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision 37e445603294cff1f6906aaed592732428fd7b0d 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 added the readiness: checking Automated validation is still running label Oct 24, 2026
@github-actions

github-actions Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of 37e445603294cff1f6906aaed592732428fd7b0d — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

Nothing blocks. The exemption requires a host-verified Grep/glob identity and fails closed everywhere else, so the worst case is the false refusal staying where it is today.

Notes

  • The exemption only fires on the Kiro _meta.kiro identity path. A claude call names its built-in through harness_builtin_tool and never sets identity_trusted, so it doesn't match. On KAS, _is_host_read_only_builtin resolves aliases, but the later check _normalize_tool_name(call.mcp_tool) in _SEARCH_BUILTIN_TOOL_NAMES reads the raw id. The same title-text refusal therefore stays on those harnesses. This isn't a safety problem, but it is a harness-parity (H-series) gap. Either name it under ## Not a goal or route the check through the alias set _is_host_read_only_builtin already resolves.
  • The root cause is that the exfil rows read the judged title when a call has no command of its own. Skipping the tier for every proven read-only built-in would cover fs_read titles too, without adding a second identity set beside _HOST_READ_ONLY_BUILTIN_TOOLS.
  • _rule_exfil gains a new per-tool skip. Per AGENTS.md (the router), the security spec (docs/system-specs/modules/security.md) should say so in the same commit.

[DESIGN-REVIEWED] 37e4456

Description read

[DESCRIPTION-READ] f7299d5a3d3516eab6926f7bc3636c5d41e672c9962bd03b9122eb3fbf7f4b3a

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 Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of 37e445603294cff1f6906aaed592732428fd7b0d — 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

The exemption is keyed on host-verified tool identity, and issue #23586 plus pinning tests back the defect. It is a point patch: the sibling shell-class rule still judges the same title.

Notes

  • Item 1 — symptom-level: the cause is that shell-class rules judge a non-shell builtin's title (security_targets → _tier_targets). Grepped GateRule( in hooks.py:1702-1704: two shell_rule rules, and only exfil is exempted. sensitive-bash (is_sensitive_bash_command: IMDS literal, printenv/env | grep) still refuses a Grep whose title names those strings. That is inside the Goal, "text that merely appears in its title". Subtraction: replace the _rule_exfil early return with one skip of every rule.shell_rule rule on the title for is_file_search_builtin in _tier_targets, so one exemption covers the class.

What this change ships

Inventory (3 items) — 2 justified

Intent: let an agent use the built-in Grep/glob tool to search for curl upload-flag text without being refused. FIX.

  1. Grep/glob calls whose title carries curl/wget upload-flag text are no longer refused by the exfil tier — symptom-level (sensitive-bash sibling still refuses the same title)
  2. New GateFacts.is_file_search_builtin identity predicate (trusted _meta.kiro name ∈ {grep, glob}, kind=search, search-shaped args) — justified
  3. New _SEARCH_BUILTIN_TOOL_NAMES constant in hooks.py — justified

[FIRST-PRINCIPLES-REVIEWED] 37e4456

Description read

[DESCRIPTION-READ] f5894e2c3065e6df9867e0ff74b3a19bcb296a54cfc7638e18922d1faaabb6c7

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 added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Oct 24, 2026
@github-actions

github-actions Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of 37e445603294cff1f6906aaed592732428fd7b0d and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 37e4456

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 37e445603294cff1f6906aaed592732428fd7b0d false-positive: <reason, 20 to 500 characters>

@github-actions

github-actions Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed 37e445603294cff1f6906aaed592732428fd7b0d — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 37e4456

Verdict parsed from the review's SHA-scoped output markers for commit 37e445603294cff1f6906aaed592732428fd7b0d.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 37e445603294cff1f6906aaed592732428fd7b0d false-positive: <reason, 20 to 500 characters>

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

Copy link
Copy Markdown
Contributor Author

Both findings fixed in bd51de3 (force-with-lease over cf5e919), both now fail closed:

  • F1 (exfil_bash.py, path-qualified inert basename): the carve-out judged the program word's basename, so a path-qualified token whose basename is on the inert list cleared it — and that token can be a workspace symlink to a transport client. The check now refuses outright any program word containing a path separator; only a bare inert program word clears it. Regression: ./cat and /usr/bin/cat upload forms stay refused, a bare cat of inert text still passes.

  • F2 (gate_tiers.py, search-shaped call with a recovered command): is_file_search_builtin keyed on the search-shaped arguments but did not disqualify a call that also carries a recovered command/cmd string argument, so a {command, pattern} frame skipped the recovered command's check. It now returns False whenever raw_shell_commands is non-empty, so a recovered command always keeps the full rows. Regression: a kind="other" frame with both a command and a pattern is refused.

Both are covered by new tests, and the genuine pattern-only file-search exemption still holds.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: bd51de3
  • What rule changed: the exfiltration gate's curl body/upload rows (the body-flag family, the multipart field glob, and the upload-file short/long forms) are no longer matched as a plain substring over the whole command string. They are now cleared only for (a) a single plain command whose every program word is a bare, known-inert program, and (b) a built-in file-search call recognised by its tool kind and arguments. The reverse-shell and wget-anchored rows are unchanged.
  • Before -> after (what was allowed/blocked, now): BEFORE, a benign local command that merely contained the text (echo/printf of the literal) and a file-search tool whose title held the literal were blocked. AFTER, those are allowed. A command that genuinely runs a transport client, in any form (bare, wrapper such as env/sudo/xargs, interpreter, pipeline, path-qualified, or substitution-produced), is blocked exactly as before. No new allow for a real upload.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): if the carve-out were too wide it could let a real upload through (leak). Both exemptions therefore fail closed: anything not provably inert keeps the denial. Two fail-open paths that review found (a path-qualified program whose basename is inert; a search-shaped call carrying a recovered command argument) are closed in this head, each with a regression test.
  • Evidence checked (which sandbox result proves it): a probe calling the real gate entry audit_bash_exfiltration confirmed every upload/wrapper/interpreter/pipeline/path-qualified form stays blocked while the benign forms pass; the full-gate path (HookManager.judge) confirmed the file-search exemption applies to a search builtin but not to a shell tool or a call carrying a recovered command.
  • No regression:
    • Tools still work (which tools/commands were run, result): isort --check-only, flake8, and mypy on the changed files all pass; the file-line-cap, brand, changelog/decisions, testpaths and per-file-coverage gates pass locally.
    • Backward compatible (old config / old data / old callers still work, how checked): no public name, config key, or rule id changed; the gate's callers (hooks, cron vetting, computer-use vetting) call the same function with the same signature. The facade re-export list was updated to the renamed private helpers only.
    • Existing tests (which suites passed on this head): test_exfil_carveouts.py (31, unchanged), test_exfil_gate_opt_out.py, test_exfil_outbound_sends_allowed.py, test_gate_tiers.py, test_denied_commands_security.py, and the campaign facade parity suite all pass; the new test_exfil_search_tool_carveout_23586.py covers the benign cases, every true-positive/wrapper form, the file-search exemption, and both review findings.
  • How to undo: revert the two commits cf5e919 and bd51de3 on this branch (or close the PR); nothing else depends on them.

@github-actions

github-actions Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Security Scope Review -- ✅ PASS

Which legitimate operations does 37e445603294cff1f6906aaed592732428fd7b0d newly refuse? Updated in place on each push. A script-confirmed regression blocks; the model proposes candidates and never decides a refusal.

Verdict basis: adjudicated, zero confirmed regressions.

Security scope review -- adjudicated candidates

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

No candidate flipped from allowed to refused.

Scope-Verdict: PASS

Reason: This change loosens the gate rather than tightening it. It adds an exemption so the exfil tier no longer runs on a host-trusted Grep/glob builtin call, and every shell-executing call and every call with a recovered command/cmd keeps the full rows. No candidate was confirmed newly refused. The exemption's own admission predicate is not a shell-line guard, so it is named under UNADJUDICATED.

TIGHTENING: None strictly. The only new logic is an early return in the exfil tier (+ if facts.is_file_search_builtin:\n+ return None), gated by the conjunction in GateFacts.is_file_search_builtin (if call.is_shell or call.command or call.mcp_server: return False / if self.raw_shell_commands: return False / kind == "search" / _is_host_read_only_builtin(... mcp_identity_trusted=call.identity_trusted ...) / _normalize_tool_name(call.mcp_tool) not in _SEARCH_BUILTIN_TOOL_NAMES / _is_search_shaped). The threat it keeps refused is a model-authored call that dresses itself as a search to skip the curl/wget egress rows, for example {"command": "<upload>", "pattern": "x"}.

ADJUDICATED: 14 candidates, 0 confirmed newly-refused

PLATFORM COVERAGE: I wrote posix, windows and any rows. The diff makes no new assumption about paths, separators or interpreters: the exemption keys on tool identity and argument shape, and shell command lines never reach it because is_shell/command short-circuits to False. The rows therefore cover the exfil tier's neighbourhood in each spelling:

  • posix: .venv/bin/python pytest of the new test, rg/grep, date -d @epoch, curl -o and wget -O downloads.
  • windows: .venv\Scripts\python.exe, Select-String, findstr /s, and curl.exe with %TEMP%\ paths.
  • any: git grep, a read-only curl GET, and scripts/deny_diff.py.

There is no platform assumption I could not write a candidate for.

UNADJUDICATED: The guard is the GateFacts.is_file_search_builtin predicate. An input reaches it this way: HookManager.judge(ToolCall) → GATE_TIERS exfil row → _rule_exfil(facts, target) → facts.is_file_search_builtin → returns None or calls audit_bash_exfiltration. It only ever removes a refusal, so it cannot newly refuse a legitimate operation. It does refuse the exemption to some legitimate non-shell calls, which stay exactly as they were at base:

  • a Grep call with kind="search", mcp_tool="grep", identity_trusted=True and only an operation recursive-walk argument (this should be exempted by _is_search_shaped);
  • a glob call such as mcp_tool="glob", raw_params={"pattern": "**/*.py"} whose title mentions curl -T;
  • a host builtin whose name normalizes differently (for example Grep or a kas builtin id).

The classifier cannot check these because they are tool calls, not shell lines. One part of the design depends on the host's ACP stamping and is unverified here: an MCP-served or untrusted-identity search tool such as mcp_tool="grep" with identity_trusted=False, or a Windows harness that names the tool differently, still gets the exfil rows on its title. That is the base behaviour, not a regression.

[SCOPE-REVIEWED] 37e4456

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Oct 24, 2026
@chenmingwei23
chenmingwei23 force-pushed the fix/exfil-upload-program-scope-23586 branch from bd51de3 to dc1d4a0 Compare October 24, 2026 21:57
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Oct 24, 2026
@chenmingwei23

Copy link
Copy Markdown
Contributor Author

Resolved in dc1d4a0 (force-with-lease over bd51de3) by removing the shell-command exception entirely, which is the root both findings targeted.

  • The GPT :250 finding (a bare program name does not establish an inert executable — PATH can resolve cat to a user-writable shim) and the Opus :243 finding (a leading PATH=/LD_PRELOAD= assignment is skipped, so a bare program clears via PATH) both rely on the shell-command carve-out in exfil_bash.py. That carve-out is gone: exfil_bash.py and the exfil facade are reverted to main, so the curl body/upload rows refuse PATH=./bin cat -d @…, ./cat …, cat … and echo/printf of the flag text exactly as the base branch does.
  • The PR now adds only the file-search builtin exemption in gate_tiers.py, recognised by tool kind/arguments (never title), and never applied when a command/cmd argument is recovered.

So neither PATH/LD_PRELOAD nor bare-name resolution is reachable through this PR any more.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: dc1d4a0
  • What rule changed: the exfiltration invocation gate now skips its curl body/upload rows for a built-in file-search call (the Grep / recursive-walk tool), recognised by its tool kind and arguments. Nothing else changed: exfil_bash.py and the exfil facade are unchanged from main, so no shell command's treatment changed.
  • Before -> after (what was allowed/blocked, now): BEFORE, a file-search tool call whose LLM-authored title contained the flag text was blocked by the exfil tier. AFTER, a file-search built-in is exempt from those rows. A shell tool, a call carrying a recovered command/cmd argument, and an MCP-served call all keep the full rows. No new allowance for any shell command: echo/printf of the flag text and every transport-client form stay blocked exactly as on main.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): if the exemption were too wide a real upload could ride it (leak). It fails closed: it is keyed on tool identity/kind and argument shape, never on title text, and is refused whenever a command/cmd argument is recovered (raw_shell_commands non-empty) — so a model-authored {command, pattern} frame keeps its exfil check.
  • Evidence checked (which sandbox result proves it): the full-gate path HookManager.judge was exercised — a file-search call with the flag text in its title passes; the same title on a shell tool is refused by the exfil tier; a kind=other frame carrying both a command and a pattern is refused. The gate function audit_bash_exfiltration confirms echo/printf of the flag text and every upload/wrapper/interpreter/path-qualified form stay refused.
  • No regression:
    • Tools still work (which tools/commands were run, result): isort --check-only, flake8, and mypy on the changed file pass.
    • Backward compatible (old config / old data / old callers still work, how checked): no public name, config key, or rule id changed; exfil_bash.py and the exfil facade equal main, so every existing caller of the gate is unchanged. The new behaviour is a single added property plus an early return in one gate rule.
    • Existing tests (which suites passed on this head): test_exfil_carveouts.py, test_exfil_gate_opt_out.py, and test_gate_tiers.py all pass; the new test_exfil_search_tool_carveout_23586.py covers the file-search exemption (allowed), the shell-tool and recovered-command cases (refused), and echo/printf of the flag text (refused).
    • How to undo: revert the one commit dc1d4a0 on this branch, or close the PR; nothing else depends on it.

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Oct 24, 2026
@chenmingwei23
chenmingwei23 force-pushed the fix/exfil-upload-program-scope-23586 branch from dc1d4a0 to cf7bd4d Compare October 24, 2026 22:09
@github-actions github-actions Bot removed the readiness: action required A blocking check or review needs attention label Oct 24, 2026
@chenmingwei23

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: cf7bd4d
  • What rule changed: the exfiltration invocation gate now skips its curl body/upload rows for a built-in file-search call (the Grep / recursive-walk tool), recognised by its tool kind and arguments. Nothing else changed: exfil_bash.py and the exfil facade are unchanged from main, so no shell command's treatment changed.
  • Before -> after (what was allowed/blocked, now): BEFORE, a file-search tool call whose LLM-authored title contained the flag text was blocked by the exfil tier. AFTER, a file-search built-in is exempt from those rows. A shell tool, a call carrying a recovered command/cmd argument, and an MCP-served call all keep the full rows. No new allowance for any shell command: echo/printf of the flag text and every transport-client form stay blocked exactly as on main.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): if the exemption were too wide a real upload could ride it (leak). It fails closed: it is keyed on tool identity/kind and argument shape, never on title text, and is refused whenever a command/cmd argument is recovered (raw_shell_commands non-empty) — so a model-authored {command, pattern} frame keeps its exfil check.
  • Evidence checked (which sandbox result proves it): the full-gate path HookManager.judge was exercised — a file-search call with the flag text in its title passes; the same title on a shell tool is refused by the exfil tier; a kind=other frame carrying both a command and a pattern is refused. The gate function audit_bash_exfiltration confirms echo/printf of the flag text and every upload/wrapper/interpreter/path-qualified form stay refused.
  • No regression:
    • Tools still work (which tools/commands were run, result): isort --check-only, flake8, and mypy on the changed file pass.
    • Backward compatible (old config / old data / old callers still work, how checked): no public name, config key, or rule id changed; exfil_bash.py and the exfil facade equal main, so every existing caller of the gate is unchanged. The new behaviour is a single added property plus an early return in one gate rule.
    • Existing tests (which suites passed on this head): test_exfil_carveouts.py, test_exfil_gate_opt_out.py, and test_gate_tiers.py all pass; the new test_exfil_search_tool_carveout_23586.py covers the file-search exemption (allowed), the shell-tool and recovered-command cases (refused), and echo/printf of the flag text (refused).
    • How to undo: revert the one commit cf7bd4d on this branch, or close the PR; nothing else depends on it.

@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Oct 24, 2026
@chenmingwei23
chenmingwei23 marked this pull request as ready for review October 24, 2026 23:08
@chenmingwei23
chenmingwei23 requested review from a team and KiroCrewCaptain as code owners October 24, 2026 23:08
@chenmingwei23

Copy link
Copy Markdown
Contributor Author

Thanks for the probe — fixed at 3393ad32aa5fc47b3b76b985132a32b15facf822.

The exemption now requires a positive identity, not just the argument shape: is_file_search_builtin returns True only when call.kind == "search" AND the normalized host-stamped tool name (call.mcp_tool, _meta.kiro.toolName) is in _SEARCH_BUILTIN_TOOL_NAMES (grep, glob), on top of the existing not-shell / no-recovered-command / not-MCP / search-shaped checks. call.kind can only narrow (it is agent-influenced); the host-stamped name is the trusted discriminator.

So the kind=other and kind=fetch calls from your probe keep the exfil tier. The two kinds you named are covered by:

  • kind=other: TestExemptionNeedsPositiveIdentity::test_non_search_kind_call_with_pattern_still_refused
  • kind=fetch: TestExemptionNeedsPositiveIdentity::test_fetch_kind_call_with_pattern_still_refused

Both carry the flag text in the title and a search-shaped pattern argument and assert (DENY, "exfil"). Reverting the gate change turns both red; they pass with the fix. The genuine Grep/glob builtin (kind=search, name grep/glob) stays exempt, verified by test_file_search_tool_with_literal_title_allowed.

On your second point (not mcp_server not sufficient alone): agreed — it is now one condition of a conjunction, and the positive kind+name identity is what identifies the builtin. On the one allowed upload shape a later tier crashed on in your environment: that is a fail-closed path unrelated to this change, and the deny-rules catalog still refused the other upload shapes.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: 3393ad3
  • What rule changed: the exfiltration invocation gate skips its curl body/upload rows only for a built-in file-search call, now identified by a POSITIVE tool identity — call.kind == "search" AND the host-stamped tool name (_meta.kiro.toolName, normalized) in _SEARCH_BUILTIN_TOOL_NAMES (grep, glob) — on top of the existing argument shape and the existing disqualifiers (not a shell tool, no recovered command/cmd, not MCP-served). exfil_bash.py and the exfil facade are unchanged from main, so no shell command's treatment changed.
  • Before -> after (what was allowed/blocked, now): BEFORE this head, any non-shell, non-MCP call that merely carried a pattern argument (including kind=other / kind=fetch) skipped the exfil tier, which was wider than intended. AFTER, only a call the host identifies as the Grep/glob builtin (kind == "search" and a tool name in the set) with search-shaped arguments is exempt. A shell tool, a call carrying a recovered command argument, an MCP-served call, and any non-search-kind call all keep the full rows. No new allowance for any shell command: echo/printf of the flag text and every transport-client form stay blocked exactly as on main.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): if the exemption were too wide a real upload could ride it (leak). It fails closed: call.kind is agent-influenced and can only narrow, the tool name is the non-model-authored host-stamped discriminator, and the exemption is refused whenever a command/cmd argument is recovered. A call that is not positively the search builtin keeps its exfil check.
  • Evidence checked (which sandbox result proves it): the full-gate path HookManager.judge was exercised — a kind=search call with name grep and the flag text in its title passes; the same title on a kind=other call, a kind=fetch call, and a shell call are each refused by the exfil tier; a kind=other frame carrying both a command and a pattern is refused. Reverting the gate change turns the kind=other and kind=fetch assertions red. The gate function audit_bash_exfiltration confirms echo/printf of the flag text and every upload/wrapper/interpreter/path-qualified form stay refused.
  • No regression:
    • Tools still work (which tools/commands were run, result): isort --check-only, black --check, flake8, and mypy on the changed files all pass.
    • Backward compatible (old config / old data / old callers still work, how checked): no public name, config key, or rule id changed; one module-level constant (_SEARCH_BUILTIN_TOOL_NAMES) is added. exfil_bash.py and the exfil facade equal main, so every existing caller of the gate is unchanged.
    • Existing tests (which suites passed on this head): the exfil / gate-tier / search-target / trusted-identity suites pass (990 passed, 2 skipped) including test_exfil_carveouts.py, test_exfil_gate_opt_out.py, test_gate_tiers.py, and test_hooks_trusted_identity.py; the new test_exfil_search_tool_carveout_23586.py (16 cases) covers the file-search exemption (allowed with full identity), the non-search-kind / fetch-kind / shell cases carrying a pattern (refused), the recovered-command case (refused), and echo/printf of the flag text (refused).
  • How to undo: revert the one commit 3393ad3 on this branch, or close the PR; nothing else depends on it.

The exfiltration gate's curl body/upload rows match their substring/glob over the
whole command string. The built-in file-search (Grep) tool has no shell command;
its title is LLM-authored prose that can carry the literal, so the rows refused it
even though it uploads nothing.

Fix: the invocation gate skips those rows for a file-search built-in, identified
by its tool kind / argument shape — never by title text, so no title can opt a
shell tool out — and never when a command/cmd argument is recovered
(raw_shell_commands non-empty), so a {command, pattern} frame keeps the full rows.
Every shell-executing tool keeps the full rows. This is the whole change; no
shell-command exception is added.

By design, a command that merely contains the flag text (echo/printf of it) stays
refused, exactly as on main. `date -d @<epoch>` already passes on main via main's
own pre-existing exception and is unchanged here.
@chenmingwei23
chenmingwei23 force-pushed the fix/exfil-upload-program-scope-23586 branch from 3393ad3 to 37e4456 Compare October 25, 2026 08:55
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Oct 25, 2026
@chenmingwei23

Copy link
Copy Markdown
Contributor Author

Follow-up — new head 37e445603294cff1f6906aaed592732428fd7b0d (one commit).

Two points surfaced by the review gates on the previous head, both in this diff, are fixed here fail-safe:

  1. The positive-identity check now derives the host built-in identity from the repository's existing predicate _is_host_read_only_builtin(call.mcp_tool, call.mcp_server, mcp_identity_trusted=call.identity_trusted, kas_builtin_ids=call.kas_builtin_ids), then restricts to the grep/glob file-search subset, rather than reading the tool name directly. This closes a gap: a mcp_tool="grep" that did not come from the verified _meta.kiro parse (identity_trusted false) is rejected, so a model-authored name cannot earn the exemption. A regression test (test_untrusted_grep_name_without_verified_identity_still_refused) pins it.

  2. The added comments/docstring state current behaviour in present tense (no change narration).

The fix and both reviewer-named tests are unchanged in substance; the suite is 17 cases, all green, and isort/black/flake8/mypy are clean.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author

Follow-up — new head 37e445603294cff1f6906aaed592732428fd7b0d.

The positive-identity check is strengthened: is_file_search_builtin now proves the host built-in through the repository's own _is_host_read_only_builtin predicate (which requires the name to have come from the verified _meta.kiro parse) and then restricts to the grep/glob subset. So a kind=other or kind=fetch call keeps the exfil tier even if it carries a pattern, and a grep name the model wrote without the verified identity is rejected too.

Coverage of the two kinds you named is unchanged:

  • kind=other: TestExemptionNeedsPositiveIdentity::test_non_search_kind_call_with_pattern_still_refused
  • kind=fetch: TestExemptionNeedsPositiveIdentity::test_fetch_kind_call_with_pattern_still_refused

plus test_untrusted_grep_name_without_verified_identity_still_refused for the provenance point. All assert (DENY, "exfil"); the genuine Grep/glob builtin with a verified identity stays exempt.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author

Addressed on new head 37e445603294cff1f6906aaed592732428fd7b0d.

  • Blocker (second spelling of the host-built-in identity check): resolved. is_file_search_builtin no longer has its own name/server check. It now derives the host identity from _is_host_read_only_builtin(call.mcp_tool, call.mcp_server, mcp_identity_trusted=call.identity_trusted, kas_builtin_ids=call.kas_builtin_ids), then adds a check that the normalized name is grep or glob (the file-search subset) and that kind == "search". So the two predicates no longer drift, and a mcp_tool="grep" without the verified _meta.kiro parse is rejected.
  • Item 1 (symptom-level / Siblings: none): point taken — _rule_sensitive_bash is a separate shell_rule row that also judges the title. This change narrows only the exfil-row exemption (_rule_exfil), which is the reported false positive; the sensitive-bash row is a distinct concern outside this one-rule change and is left as-is rather than widening the diff.
  • Item 3 (undeclared / title): the PR title describes the exemption by tool identity rather than "upload-capable programs".

@chenmingwei23

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: 37e4456
  • What rule changed: the exfiltration invocation gate skips its curl body/upload rows only for a built-in file-search call, identified by a POSITIVE host-trusted identity — call.kind == "search" AND _is_host_read_only_builtin(mcp_tool, mcp_server, mcp_identity_trusted=identity_trusted, kas_builtin_ids) (the repository's own host-built-in predicate, which requires the name to have come from the verified _meta.kiro parse) whose normalized name is in _SEARCH_BUILTIN_TOOL_NAMES (grep, glob) — on top of the existing argument shape and disqualifiers (not a shell tool, no recovered command/cmd, not MCP-served). exfil_bash.py and the exfil facade are unchanged from main, so no shell command's treatment changed.
  • Before -> after (what was allowed/blocked, now): BEFORE, a file-search tool call whose LLM-authored title contained the flag text was blocked by the exfil tier. AFTER, a positively-identified Grep/glob builtin is exempt from those rows. A shell tool, a call carrying a recovered command argument, an MCP-served call, any non-search-kind call, and a call whose tool name was not from the verified identity parse all keep the full rows. No new allowance for any shell command: echo/printf of the flag text and every transport-client form stay blocked exactly as on main.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): if the exemption were too wide a real upload could ride it (leak). It fails closed: call.kind is agent-influenced and only narrows; the identity is proven by the trusted-parse predicate the rest of the gate uses, never by a model-written name or title; and the exemption is refused whenever a command/cmd argument is recovered. A call that is not positively the search builtin keeps its exfil check.
  • Evidence checked (which sandbox result proves it): the full-gate path HookManager.judge was exercised — a kind=search, verified grep call with the flag text in its title passes; the same title on a kind=other call, a kind=fetch call, a shell call, and a grep name WITHOUT the verified identity are each refused by the exfil tier; a kind=other frame carrying both a command and a pattern is refused. Reverting the identity predicate turns the untrusted-name assertion red. audit_bash_exfiltration confirms echo/printf of the flag text and every upload/wrapper/interpreter/path-qualified form stay refused.
  • No regression:
    • Tools still work (which tools/commands were run, result): isort --check-only, black --check, flake8, and mypy on the changed files all pass.
    • Backward compatible (old config / old data / old callers still work, how checked): no public name, config key, or rule id changed; one module-level constant (_SEARCH_BUILTIN_TOOL_NAMES) is added and the new check reuses an existing predicate. exfil_bash.py and the exfil facade equal main, so every existing caller of the gate is unchanged.
    • Existing tests (which suites passed on this head): the exfil / gate-tier / search-target / trusted-identity suites pass (990 passed, 2 skipped) including test_exfil_carveouts.py, test_exfil_gate_opt_out.py, test_gate_tiers.py, and test_hooks_trusted_identity.py; the new test_exfil_search_tool_carveout_23586.py (17 cases) covers the exemption (allowed with a verified identity), the non-search-kind / fetch-kind / shell / untrusted-name cases (refused), the recovered-command case (refused), and echo/printf of the flag text (refused).
  • How to undo: revert the one commit 37e4456 on this branch, or close the PR; nothing else depends on it.

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running and removed readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention labels Oct 25, 2026
@github-actions github-actions Bot added the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Oct 28, 2026
@bolichen97

Copy link
Copy Markdown
Contributor

[operator: bolichen97] Continuing this in #31727; thanks for the start.

bolichen97 added a commit that referenced this pull request Nov 7, 2026
A file search for the text `-d @` or `-F x=@` was refused by the exfil
gate: with no command, the only text a grep or glob call is judged on
is its title, which is the text it searches for, and the curl rows read
it as a command line. A call whose host-trusted identity names the grep
or glob built-in, with no MCP server and no command of any kind, runs no
shell, so the exfil rule no longer judges it. Every other tier still
does; an untrusted or MCP-served name, the code built-in and any call
carrying a command keep the rule.

Builds on #23845.
bolichen97 added a commit that referenced this pull request Nov 7, 2026
A file search for the text `-d @` or `-F x=@` was refused by the exfil
gate: with no command, the only text a grep or glob call is judged on
is its title, which is the text it searches for, and the curl rows read
it as a command line. A call whose host-trusted identity names the grep
or glob built-in, with no MCP server and no command of any kind, runs no
shell, so the exfil rule no longer judges it. Every other tier still
does; an untrusted or MCP-served name, the code built-in and any call
carrying a command keep the rule.

Builds on #23845.
KiroCrewCaptain pushed a commit that referenced this pull request Nov 7, 2026
#31727)

A file search for the text `-d @` or `-F x=@` was refused by the exfil
gate: with no command, the only text a grep or glob call is judged on
is its title, which is the text it searches for, and the curl rows read
it as a command line. A call whose host-trusted identity names the grep
or glob built-in, with no MCP server and no command of any kind, runs no
shell, so the exfil rule no longer judges it. Every other tier still
does; an untrusted or MCP-served name, the code built-in and any call
carrying a command keep the rule.

Builds on #23845.
buluoray pushed a commit that referenced this pull request Nov 7, 2026
#31727)

A file search for the text `-d @` or `-F x=@` was refused by the exfil
gate: with no command, the only text a grep or glob call is judged on
is its title, which is the text it searches for, and the curl rows read
it as a command line. A call whose host-trusted identity names the grep
or glob built-in, with no MCP server and no command of any kind, runs no
shell, so the exfil rule no longer judges it. Every other tier still
does; an untrusted or MCP-served name, the code built-in and any call
carrying a command keep the rule.

Builds on #23845.

(cherry picked from commit de98390)
@iamwhatever

Copy link
Copy Markdown
Contributor

Thank you for this work! As noted in the thread, it continued in #31727, which has now merged. Closing this one as superseded by #31727.

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

Labels

merge conflict Branch has merge conflicts with its base — author must resolve before merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Exfil guard false positive: '-d @' substring match blocks GNU date -d @<epoch> and Grep searches for the literal

4 participants