Repository navigation
fix(agents): apply tool policy to Anthropic native calls - #128805
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Codex review: needs real behavior proof before merge. Reviewed August 24, 2026, 2:45 PM ET / 18:45 UTC. ClawSweeper reviewWhat this changesThis PR routes Anthropic Claude CLI native-tool calls through OpenClaw’s shared policy and approval host, updates the Agent SDK, and revises tests and docs. Merge readiness⛔ Blocked until real behavior proof is added - 11 items remain Keep open: the shared host-policy direction is useful, but two P1 gaps leave native policy enforcement bypassable for canonical tool policies and enterprise-managed Claude settings. Priority: P1 Review scores
Verification
How this fits togetherThe Anthropic plugin runs the locally authenticated Claude Code executable through Anthropic’s Agent SDK. Native tool calls pass from the SDK callback to OpenClaw’s CLI execution host, which should apply shared policy and approval before allowing the executable action. flowchart LR
A[Agent turn] --> B[Anthropic CLI plugin]
B --> C[Agent SDK]
C --> D[Native tool callback]
D --> E[OpenClaw policy and approval]
E --> F[Claude Code tool execution]
Decision needed
Why: Choosing between a retained reachability fence, fail-closed native-tool availability, or accepting the upstream callback contract changes the security boundary and operator behavior. Before merge
Findings
Agent review detailsSecurityNeeds attention: The patch can weaken the final authorization boundary for native executable tools. PR surfaceSource -3, Tests +95, Docs +6, Config 0, Other +91. Total +189 across 9 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Map Claude native identifiers and input shapes to canonical OpenClaw tool identities before policy evaluation, and retain one non-bypassable enforcement boundary for SDK deployments where callback reachability cannot be guaranteed. Do we have a high-confidence way to reproduce the issue? Yes for the canonical-name defect: WebFetch is forwarded as webfetch while the core policy surface uses web_fetch. The enterprise callback bypass is also recorded in the PR discussion, though direct SDK inspection was unavailable locally. Is this the best way to solve the issue? No: moving policy into the shared host is the right boundary, but raw native names and an overrideable managed ask rule cannot safely enforce it alone. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against bf83a4dde8f0. LabelsLabel justifications:
EvidenceSecurity concerns:
What I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
History |
|
Independent exact-head review of
No duplicate OpenClaw authorization was found: exact |
Co-authored-by: Vincent Koc <[email protected]>
|
Merged via squash.
|
…8805) * fix(agents): enforce native policy in Anthropic SDK * fix(agents): enforce canonical native tool policies safely Co-authored-by: Vincent Koc <[email protected]> --------- Co-authored-by: Peter Steinberger <[email protected]>
What Problem This Solves
Anthropic Agent SDK native tools reached OpenClaw's exec approval boundary without first running the same registered
before_tool_callpolicies, loop detection, argument rewrites, and requester context used by other agent tools. The original implementation also matched Claude names likeWebFetchincorrectly, exposed nativefile_pathinstead of the canonicalpathinspected by file policies, and rejected valid OpenClawwrite/editplugin matchers.Why This Change Was Made
The generic CLI execution host now owns one canonical policy decision before native approval and execution. It maps backend-native names such as
Bash,WebFetch, andWebSearchtoexec,web_fetch, andweb_search; projectsRead/Write/Editfile operands into canonical policy arguments; maps approved rewrites back into the exact native SDK schema; rejects conflicting or unrepresentable edits; and revalidates admitted-run authority after awaited policy work.Anthropic's existing SDK-native
PreToolUseprotection remains intact. The Agent SDK documents that caller-supplied managed settings may be discarded when enterprise-managed settings exist, so removingPreToolUseor relying only on a managed ask rule would permit native-tool bypass. User-preapproved tools and disabled user hooks therefore still reach the OpenClaw owner. No SDK version bump, lockfile change, third-party notice, or additional dependency is necessary.Canonical lowercase
writeandeditmatchers are now accepted while upstream Codex's exactWrite/Editcompatibility aliases remain rejected; its independentapply_patchprojection is unchanged. OpenClaw-owned MCP calls retain their existing Gateway authorization boundary.Release note: Claude Agent SDK native shell, web, and file tools now honor canonical OpenClaw plugin policy, safe argument rewrites, and existing native approvals without weakening enterprise-managed protections.
User Impact
Operators get the same tool-policy vetoes, path-based controls, canonical tool matching, argument rewrites, session restrictions, and fail-closed approval behavior across SDK-native and ordinary OpenClaw tools. Warm SDK sessions, resume, operator questions, cancellation, and protected credential forwarding remain unchanged.
Evidence
d3081504c9446029b7a4bcabb9c3400635426d19.write/editmatchers, conflicting paths, and nonrepresentable edit rewrites. All now pass.exec/read/writevetoes, executed command rewrites, hooks-disabled/preapproved Bash denial, 120 consecutive warm turns on one process/session, 24 alternating allow/deny turns, parallel owners, 12 owner-replacement cycles, stale/late-approval fencing, malformed streams, provider errors, and zero surviving processes across 47 tracked subprocesses.execpolicy blocked a real Bash call even with hooks disabled and Bash preapproved; another rewrote the real command and returnedLIVE_POLICY_REWRITTEN. Also verified 10-turn process/conversation reuse, real operator-question round trip, native allow/deny, cancellation, nine zeroized credential buffers, and zero surviving subprocesses. This proof uses the dedicated API test credential, not a Claude subscription.node scripts/run-tsgo.mjs -p tsconfig.core.json --incremental --tsBuildInfoFile .artifacts/tsgo-cache/core.tsbuildinfo: passed.node scripts/run-tsgo.mjs -b test/tsconfig/tsconfig.core.test.agents-other.json --builders 1: passed.node scripts/run-tsgo.mjs -b test/tsconfig/tsconfig.core.test.plugins-platform.json --builders 1: passed.git diff --check, and structured Codex autoreview/TruffleHog: passed. The full all-shard test-type command reaches the unchanged base failure inui/vite.config.tsbecause the shared checkout lacks declarations for the existingpakodependency; both changed owner shards pass independently.+129/-6(net+123), justified by the previously missing security-critical canonical policy owner, bidirectional provider-schema boundary, and stale-run fencing. Tests:+436/-0; docs:+13/-8; dependency/lockfile/notice delta: zero.PreToolUse, and provider-native web/file names and operands are projected into canonical policy before matching.