arXiv:2509.05755cs.CRcs.AI2025-09被引 6

首次系统评估代码代理的工具调用安全,发现可远程执行代码的漏洞。

Red-Teaming Coding Agents from a Tool-Invocation Perspective: An Empirical Security Assessment

  • 通过两通道提示注入操控工具调用流程
  • 在25组代理-大模型组合中达成19次泄露与全数远程执行
  • 适用于开发者和安全研究人员关注实际部署风险

由大语言模型驱动的代码代理正成为现代IDE的核心模块,通过调用工具协助用户完成复杂任务。然而,工具调用也带来了显著的安全攻击面。已有研究针对通用和领域特定代理展开攻击,但尚未聚焦于代码代理中工具调用的安全风险。为此,我们对六款主流真实代码代理(Cursor、Claude Code、Copilot、Windsurf、Cline、Trae)进行了首次系统的红队测试。测试分两阶段进行:第一阶段通过提示泄露探测恢复系统提示,发现通用漏洞ToolLeak,可借由工具调用中的正常参数获取实现恶意提示外泄;第二阶段利用新型两通道提示注入(嵌入工具描述与返回值),实现远程代码执行(RCE)。我们基于第一阶段泄漏的安全信息自适应构造攻击载荷。在五个后端的模拟测试中,该方法在Claude-Sonnet-4、Claude-Sonnet-4.5、Grok-4和GPT-5上均优于基线。在真实代理中,成功率达19/25,所有使用Claude与Grok后端的代理均被成功泄露。对于工具调用劫持,所有测试组合均实现RCE,两通道方法成功率最高。本文还对Cursor和Claude Code进行案例分析,评估外部与内置工具的安全防护机制,并提出实用防御建议。

原文摘要 · Abstract (English)

Coding agents powered by large language models are becoming central modules of modern IDEs, helping users perform complex tasks by invoking tools. While powerful, tool invocation opens a substantial attack surface. Prior work has demonstrated attacks against general-purpose and domain-specific agents, but none have focused on the security risks of tool invocation in coding agents. To fill this gap, we conduct the first systematic red-teaming of six popular real-world coding agents: Cursor, Claude Code, Copilot, Windsurf, Cline, and Trae. Our red-teaming proceeds in two phases. In Phase 1, we perform prompt leakage reconnaissance to recover system prompts. We discover a general vulnerability, ToolLeak, which allows malicious prompt exfiltration through benign argument retrieval during tool invocation. In Phase 2, we hijack the agent's tool-invocation behavior using a novel two-channel prompt injection in the tool description and return values, achieving remote code execution (RCE). We adaptively construct payloads using security information leaked in Phase 1. In emulation across five backends, our method outperforms baselines on Claude-Sonnet-4, Claude-Sonnet-4.5, Grok-4, and GPT-5. On real agents, our approach succeeds on 19 of 25 agent-LLM pairs, achieving leakage on every agent using Claude and Grok backends. For tool-invocation hijacking, we obtain RCE on every tested agent-LLM pair, with our two-channel method delivering the highest success rate. We provide case studies on Cursor and Claude Code, analyze security guardrails of external and built-in tools, and conclude with practical defense recommendations.

代码代理安全评估提示注入远程执行

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。