-
-
Notifications
You must be signed in to change notification settings - Fork 80.7k
[Feature]: Enrich before_tool_call event with action classification and input provenance #48503
Copy link
Copy link
Open
Labels
P2Normal backlog priority with limited blast radius.Normal backlog priority with limited blast radius.clawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.ClawSweeper found a clear likely implementation shape for this issue.clawsweeper:needs-maintainer-reviewClawSweeper marked this issue as needing maintainer review before automation.ClawSweeper marked this issue as needing maintainer review before automation.clawsweeper:needs-product-decisionClawSweeper marked this issue as needing a product or behavior decision.ClawSweeper marked this issue as needing a product or behavior decision.clawsweeper:needs-security-reviewClawSweeper marked this issue as needing security-sensitive review.ClawSweeper marked this issue as needing security-sensitive review.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.ClawSweeper does not recommend queueing a new automated fix PR for this issue.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.ClawSweeper found a high-confidence source-level issue reproduction.impact:securitySecurity boundary, credential, authz, sandbox, or sensitive-data risk.Security boundary, credential, authz, sandbox, or sensitive-data risk.impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.Session, memory, transcript, context, or agent state can drift or corrupt.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.Very strong issue quality with high-confidence source-level or clear reproduction.staleMarked as stale due to inactivityMarked as stale due to inactivity
Description
Metadata
Metadata
Assignees
Labels
P2Normal backlog priority with limited blast radius.Normal backlog priority with limited blast radius.clawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.ClawSweeper found a clear likely implementation shape for this issue.clawsweeper:needs-maintainer-reviewClawSweeper marked this issue as needing maintainer review before automation.ClawSweeper marked this issue as needing maintainer review before automation.clawsweeper:needs-product-decisionClawSweeper marked this issue as needing a product or behavior decision.ClawSweeper marked this issue as needing a product or behavior decision.clawsweeper:needs-security-reviewClawSweeper marked this issue as needing security-sensitive review.ClawSweeper marked this issue as needing security-sensitive review.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.ClawSweeper does not recommend queueing a new automated fix PR for this issue.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.ClawSweeper found a high-confidence source-level issue reproduction.impact:securitySecurity boundary, credential, authz, sandbox, or sensitive-data risk.Security boundary, credential, authz, sandbox, or sensitive-data risk.impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.Session, memory, transcript, context, or agent state can drift or corrupt.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.Very strong issue quality with high-confidence source-level or clear reproduction.staleMarked as stale due to inactivityMarked as stale due to inactivity
Type
Fields
Priority
None yet
Background
We implemented a POC for CaMeL style prompt injection defense (DeepMind, 2024) as a native TypeScript port for OpenClaw. The full implementation touches too many core systems to land as a single PR: taint tracking, policy enforcement, approval routing, session isolation, and provenance propagation all need to coordinate across the tool call pipeline, outbound message routing, exec approvals, session binding, and persistence. We wrote up the full analysis in a separate article.
Along the way, we identified several hook enrichments that have standalone value for any security policy plugin, independent of whether CaMeL ever lands. This is the first of three focused proposals. Each one is independently useful for rate limiting, DLP, compliance, and audit logging. Together, they would also provide enough hook context for CaMeL style enforcement to eventually live in a plugin rather than requiring core changes.
Problem
The before_tool_call hook lets plugins block tool calls with block/blockReason, and the fix in #19381 ensures sessionKey and agentId are now available. But the event payload still only includes toolName, params, and session identifiers.
For plugins that need to make security policy decisions, this is not enough context. A plugin implementing rate limiting by action type, compliance blocking of outbound operations, or audit logging with provenance needs to know what kind of action is happening, not just which tool is being called. Today that means maintaining a brittle mapping of tool names to action categories that breaks when tools are renamed or added.
This is a gap that several security-focused plugins in the ecosystem have encountered. Richer hook context would let policy plugins reason about action categories using stable framework metadata instead of reimplementing tool classification logic.
Proposal
Add optional fields to PluginHookBeforeToolCallEvent that classify the action and provide input provenance:
Use cases
What exists today
The framework already has the data needed to populate these fields. input-provenance.ts tracks external_user, inter_session, and internal_system provenance on user messages. outbound-policy.ts classifies cross-context targets. Session binding tracks agent identity and chat type. The gap is surfacing this existing context to the plugin hook.
This would also complement the direction in #33958 (immutable operator defaults policy). An immutable policy layer needs enforcement hooks with enough context to evaluate policy rules. Action classification in before_tool_call provides that enforcement surface.
Backward compatibility
All new fields are optional. Existing plugins that destructure only toolName and params continue to work unchanged. No performance cost when no plugin subscribes to the enriched fields.
Precedent
#19381 fixed the missing sessionKey and agentId — this extends the same trajectory: giving plugins enough context to make informed decisions. #19231 proved hook enforcement matters (return values were previously silently discarded). Now that enforcement works, richer context makes the enforcement more useful.
Questions for maintainers
Context: See Building a CaMeL Prototype for OpenClaw for full motivation and architectural analysis.