Repository navigation
fix(security): do not hand shell command text to the path tier - #11223
Conversation
GPT 5.6 Review (fork) — ✅ no blocking findingsReviewed Review detailsNo findings. |
Design Review (Fable 5, fork) — ✅ PASSDesign-level review of Design-Verdict: PASS Confirm with a security owner that the stated residual — a shell command that IS a bare credential path bypasses the path tier — is acceptable in [DESIGN-REVIEWED] ac44c08 |
First Principles Review (Fable 5, fork) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Verify on each backend that every non-MCP, shell-classified frame really runs sandbox-wrapped — the exemption's entire safety case rests on that equivalence. The defect is derivable from the base alone: What this change shipsInventory (9 items) — 9 justifiedIntent: stop the tool gate refusing ordinary shell commands as "sensitive path" under a resolver stall, and stop paying a resolver round-trip per shell call — a FIX.
[FIRST-PRINCIPLES-REVIEWED] ac44c08 |
Opus 4.8 Review (fork) — ✅ no blocking findingsReviewed |
Security Scope Review (fork) — ✅ PASSWhich legitimate operations does adjudicated, zero confirmed regressions Scope-Verdict: PASS TIGHTENING: No mechanism gets stricter in this change — it is a narrowing. The path tier stops resolving a sandboxed shell tool's recovered command text ( ADJUDICATED: 14 candidates, 0 confirmed newly-refused PLATFORM COVERAGE: Candidates were written in posix (8 rows), windows (5 rows), and any (1 row) spellings. The diff's platform-relevant assumption is inverted from the usual case: the removed resolver was what imposed path semantics (separators, drive letters, tilde expansion, UNC handling) on command text, while the new exemption is exact string equality on the client-recovered command, which is platform-neutral. Each daily operation is therefore probed in both tokenizers' spellings — worktree [SCOPE-REVIEWED] ac44c08Security scope review -- adjudicated candidates
No candidate flipped from allowed to refused. |
8bd3987 to
bb72d22
Compare
|
self-added: no
|
bb72d22 to
bb54963
Compare
bb54963 to
2e5d2ea
Compare
|
self-added: no
|
|
self-added: no
|
2e5d2ea to
e464dff
Compare
|
@chenmingwei23 thanks for flagging the plan. I am doing the rebase onto current main and working the GPT 5.6 / Opus 4.8 findings on this head now (author side), so you need not spend the time on it. If you have already started, say so here and I will stand down and leave the branch to you; otherwise I will push with --force-with-lease against the current tip (1413ebd) shortly. |
1413ebd to
d60e80a
Compare
|
Rebased onto current Triage of the five reds on
Local gates on |
|
CI on The one remaining blocking item is CI's backend matrix, and it is main's, not this PR's:
Plan: once #12713's fix lands on main I will rebase onto it (patch body unchanged) so shard 4 goes green, rather than blind re-running a deterministic main red. |
|
Your own rebase landed first and did the job, so I pushed nothing and discarded my local rebase (it was onto an older main and would only have clobbered yours). Board on Attribution of what is left, so nobody spends time on it as if it were this diff:
So the chain is one main-side test failure fanning out into the coverage gate and readiness. Nothing here asks for a change to your diff. A caveat on my own evidence: the gateway path resolver on my side is refusing roughly half of all tool calls right now with a fail-closed budget timeout, which is why the three non-Linux shards are unattributed. That refusal is this PR verbatim -- it reports |
|
Thanks for the attribution, and for not clobbering the rebase. I reached the same conclusions independently:
Plan: no diff change. Once #12713's fix is on main I will rebase this same diff onto it and let CI re-run; that should clear everything except possibly the #12376 flake. On the |
|
@chenmingwei23 thanks -- agreed on all of it, and thanks for not pushing over the rebase. Attribution for the three shards you could not read:
So it is one main-side test fanning out, plus one known flake; #12715/#12716 are the fixes in flight and I will rebase onto whichever lands (patch body unchanged). On the |
|
Field evidence for this PR, offered as text to fold into Why it matters on your next push rather than as a description edit. All four AI lanes ( Suggested paragraph:
Two of the refusals I saw are worth separating out, because this PR does not cover them and should not be widened to try:
Neither is a recovered shell command, so |
|
Attribution is now complete: all six reds on
Meanwhile every review lane is green on this head: So this PR is waiting on main, not on itself. Once |
d60e80a to
ae819db
Compare
The tool gate's path tier reads a PATH. A shell tool's title and command are command text, which the gate deliberately does not match paths in: the OS sandbox is what holds the credential stores away from the shell, and the spec's "does not match PATHS in command text" records why every text matcher there was removed. Yet hooks.on_tool_call and the _resolve_permission title and tool_input tiers still resolved every shell target as a filename. That never matched, but it cost a resolver round-trip per shell call and, under a resolver stall, refused the command as "Blocked: access to sensitive path: cd /x && grep ..." -- a non-path named as a credential, which is what the agent then acted on. Gate shell targets by the event's is_shell (the client's classification of the tool frame, the same provenance the shell tiers already trust): a shell tool's title, command and payload strings skip the path tier; every non-shell target is gated exactly as before. The shell corpus classifiers (scripts/deny_diff.py, security-conductor verify_fix.py) drop the path tier from their composites to match the gate they measure. The residual is stated in the spec: a shell tool whose title is a bare path is command text too and is left to the sandbox with its command. Refs kirodotdev#10255
ae819db to
ac44c08
Compare
|
Rebased to a new head
What was preserved: still one commit, author still you ( For the record on the previous head: every backend lane, The field-evidence paragraph I offered earlier is still yours to fold into the body whenever you next push, if you want it there. I have not touched your description. Not merging and not approving. |
|
Fully green on The new head did what it was for. All four lanes that had been pinned to fail-closed verdicts from the 06:22 installation rate-limit window re-measured properly and came back green, Nothing in this diff ever needed changing. Every red this PR carried today came from its base: the mypy
|
Problem / Motivation
The tool gate's path tier reads a PATH:
hooks.on_tool_calland the_resolve_permissiontitle and tool_input tiers callis_sensitive_pathon each target. For a shell tool one of those targets is its recovered command (AcpEvent.shell_command), and the title usually is that command with a display prefix. The gate deliberately does not match paths in command text (see the spec's "The gate does not match PATHS in command text": every text matcher there was removed because the OS sandbox is the control, and a regex over a shell command cannot be made complete). Yet the path tier still resolved the command as a filename.Resolving
cd /workplace/me/proj && grep -rn foo srcas a filename never matched. It did two things anyway: it spent a bounded-resolver round-trip per shell call, and under a resolver stall (interpreter contention, a mount not answering) it refused the command aswhich is a non-path named as a credential, and is what the agent then acted on. Live gateway logs in #10255 show this on ordinary
cd && grepandcatcommands.Why it matters
On a loaded gateway the stall case turns an ordinary shell command into a credential refusal, and the agent has no way to tell it apart from a real one. Outside a stall, the round-trip is pure cost on every shell call for a check whose answer is known in advance to be "no match": the doctrine that the shell is bounded by the sandbox, not by text matching, is already in the spec, and this is the one site that had not caught up with it.
This is deliberately a one-string exemption with a stated residual, so a maintainer can judge the residual on its own rather than inside a larger diff.
What changed (motivation → approach → change)
Observed symptom: shell commands refused as sensitive paths under a stall, and a resolver round-trip on every shell call. Root cause: the path tier is applied to every target regardless of what the target IS, while the doctrine for a shell command is that the sandbox, not text matching, bounds what it can open.
Approach: spare the resolver exactly one string per shell frame, the recovered command text, and only when the client's own classification says the command runs inside the sandbox:
is_shell, a recoveredshell_command, and nomcp_server_name. Nothing about the payload is consulted for the decision. Two exclusions are load-bearing and each one is the kind of thing a review found:classify_tool_callcarries the identity and keeps the shell verdict). An MCP-served tool runs OUTSIDE the sandbox this exemption leans on, so its targets stay path-gated.use_aws) can carry a discrete credential path as an ARGUMENT, and instandardsandbox mode~/.aws,~/.sshand~/.kubeare visible to the shell, so the path tier over that argument is the control there, not the sandbox. Only the command string itself is exempt; a title that is not the command, and every payload string that is not the command, is gated exactly as before.Change:
hooks.py:exempt_command = command if (is_shell and command and not mcp_server_name) else None, thenreason = sensitive_path_refusal(target) if target != exempt_command else Nonein the per-target loop (the reason-or-None form main'ssensitive_path_refusalinterface from fix(security): word a resolver stall as unverifiable, not a path match #11221 uses, so a stall on a real path still refuses with its own wording). The targets are the normalized title and the recovered command, so the title is spared only when it IS the command; theraw_paramspath tier below the loop is untouched.llm_helpers.py:_path_tier_exempt(event) -> str | Nonereturns the recovered command under the same condition, the one place it is spelled._title_denialand_first_tool_input_denialtake a keyword-onlyexempt_command=Noneand skip the path tier for the string that is that text (_is_exempt_command_text: equal, or equal after theRunning:/Readingdisplay prefix is stripped, viahooks._normalize_tool_name). The bash, exfiltration and deny-rule tiers are unchanged.scripts/deny_diff.py, security-conductorscripts/verify_fix.py: the path tier leaves the shell-corpus composites (they classify SHELL COMMANDS, the one string the gate now exempts), with the bool-tier reason plumbing that existed only for it.test_deny_diff's pin that the measured checks equal the checks the gate applies now derives the shell composite from the gate's exemption lines.docs/system-specs/modules/security.md: the "does not match PATHS in command text" bullet records that the tool gate's path tier follows the rule for the recovered command, names both exclusions, and states the residual.Residual, stated rather than matched around: a shell tool whose recovered COMMAND is a bare path (the Claude Code adapter's Bash title is the bare command, so a command consisting of just
~/.aws/credentials) is command text like any other and is left to the sandbox. That is the same posture the spec already records forcat ~/.aws/credentialsfrom a shell.Not in this PR (tracked under #10255): the wording of a stall refusal on a real path (#11221, merged; this branch is rebased onto it and layers the exemption onto its
sensitive_path_refusalinterface), and any change to how symlink resolution is run.Tests
test/test_hooks.py(TestShellCommandTextLeavesThePathTier): the recovered command (with itsRunning:title) is never handed tois_sensitive_path(a recording stub that would refuse everything is not consulted, and the command is not denied as a sensitive path); a bare-path command is likewise not handed to it; a shell title that is NOT the command still pays the tier; a non-shell bare-path title is still refused with the historical wording; a non-shellreadwithraw_paramsis still refused; an MCP-served shell-classified frame still reaches the path tier and is refused;raw_paramspaths on a shell frame are still refused.test/test_llm_helpers_tool_input_offload.py(TestShellCommandTextLeavesThePathTier): the recovered command skips the path tier as a title (prefixed or bare) and as a payload string; a non-command title still pays it and a matched one is refused; a shell frame's OTHER payload strings still pay it, pinned with a structureduse_aws-shaped call whose~/.aws/credentialsargument is refused while the command string is not resolved;_path_tier_exemptis the command for a sandboxed shell frame andNonefor a non-shell, an MCP-served, or an unrecoverable-command frame; end to end through_resolve_permission, a path tier answering True for everything cannot refuse a shell command, ause_awscall with a credential-path argument is rejected, and an MCP-served shell event whose path tier would refuse is rejected; a source pin that each tier's body gates its singleis_sensitive_path(call on the exempt-command test. The_event/_resolvehelpers gain anis_shellkeyword defaulting toFalse, so every existing call is unchanged.test/test_llm_helpers_non_shell_gate.py: the spy on_first_tool_input_denialforwards keyword arguments.test/test_deny_diff.py,test/test_security_conductor_verify_fix.py: the fakesecuritymodules and tier parametrizations drop the path tier; the gate-vs-table pin asserts the exemption lines (exempt_command = command if (is_shell and command and not mcp_server_name) else Nonefeedingreason = sensitive_path_refusal(target) if target != exempt_command else None) and equates the table with the remaining per-target checks plusis_denied.Run locally on the current head (rebased onto
b2bc03ab5b):test_hooks,test_deny_diff,test_security_conductor_verify_fix, alltest_llm_helpers*andtest_security_path_resolve_bounded(700 tests) pass; black, isort, flake8, mypy on the changed files, the comment-history gate against the merge-base and docs-lint pass. Earlier heads: the two files above plustest_hooks_coverage,test_security,test_security_facade,test_security_path_resolve_bounded,test_deny_guidance,test_workflow_security,test_member_essential_context,test_prompts,test_cc_agent_resolution,test_acp_client_more_coverage(about 2,300 tests) pass; isort, flake8, mypy, the black gate, the comment-history gate and docs-lint pass.Manual verification
N/A — unit coverage sufficient: the change is one exemption at three call sites, each pinned in both directions (the command skips, everything else still gated) including the two exclusions, plus the composite tables the differential test ties to the gate.
Related Issues
Refs #10255 (the shell-text half). Companion to #11221 (stall wording, merged) and #10256, which this supersedes in part. No linked issue is closed on merge: #10255 stays open until its resolver-contention half is decided.
Pattern harvest
Rule candidate: review-prompt
Pattern: "a per-target security check applied to every target of a tool kind, where the doctrine for ONE of those targets says a different layer is the control"
Checklist
feat|fix|docs|refactor|perf|test|chore|ci|build|revert: ...)