Tool-using LLM agents can be redirected by attacker-controlled content into unauthorized actions. Existing tool-level guards may miss within-tool hijacking, where an attacker preserves the intended tool but changes a sensitive argument such as a recipient or destination. We present ToolFence, a provenance-aware dynamic authorization framework that combines model-based and rule-based judges to improve detection accuracy and efficiency. An LLM compiles the authenticated user request into typed, task-scoped capabilities specifying permitted tools, effects, argument sources, workflow stages, and budgets. A deterministic monitor based on Guarded Colored Petri Net (GCPN) checks each proposed call and its concrete argument values before execution. When a legitimate step requires a missing capability, an isolated LLM judge can review the action proposal and update the GCPN monitor. We evaluate ToolFence on AgentDojo, MCPTox, ASB, and AgentLAB on four different LLMs, covering environmental prompt injection, tool poisoning, memory poisoning, and long-horizon attacks. It achieves the lowest or tied-lowest attack success rate in 15 combinations. On AgentDojo with Qwen3-max, attack success falls from 21.2\% to 0\%, with a 2.0-percentage-point reduction in clean-task utility. A measured runtime subset incurs 1.63X overhead, versus 12.95X for CaMeL. Our code is released at https://github.com/PolyLiYJ/ToolFence_v2
翻译:暂无翻译