ImportSnare:检索增强代码生成中的定向“代码手册”劫持
ImportSnare: Directed "Code Manual" Hijacking in Retrieval-Augmented Code Generation
AI总结:
本文提出ImportSnare攻击框架,利用投毒文档劫持检索增强代码生成,通过位置感知束搜索和多语言归纳建议提升恶意依赖推荐,实验显示对流行库攻击成功率超50%,揭示供应链风险。
摘要:
代码生成已成为大型语言模型(LLMs)的一项关键能力,彻底改变了各技能水平程序员的开发效率。然而,数据结构和算法逻辑的复杂性常常导致生成的代码存在功能缺陷和安全漏洞,使其沦为需要大量手动调试的原型。虽然检索增强生成(RAG)可以通过利用外部代码手册来增强正确性和安全性,但它同时也引入了新的攻击面。\n\n在本文中,我们开创性地探索了检索增强代码生成(RACG)中的攻击面,重点关注恶意依赖劫持。我们展示了包含隐藏恶意依赖(如matplotlib_safe)的投毒文档如何能够颠覆RACG,利用双重信任链:LLM对RAG的依赖以及开发者对LLM建议的盲目信任。为了构造投毒文档,我们提出了ImportSnare,一种新颖的攻击框架,采用两种协同策略:1)位置感知的束搜索优化隐藏的排名序列,以提升投毒文档在检索结果中的排名;2)多语言归纳式建议生成越狱序列,以操纵LLM推荐恶意依赖。通过在Python、Rust和JavaScript上的广泛实验,ImportSnare总体上取得了显著的攻击成功率(对于matplotlib和seaborn等流行库超过50%),并且即使在投毒比例低至0.01%时也能成功,同时针对自定义和真实世界的恶意包。我们的发现揭示了LLM驱动的开发中的关键供应链风险,突显了代码生成任务安全对齐的不足。为了支持未来的研究,我们将发布多语言基准测试套件和数据集。项目主页为https://importsnare.github.io。
英文摘要:
Code generation has emerged as a pivotal capability of Large Language Models(LLMs), revolutionizing development efficiency for programmers of all skill levels. However, the complexity of data structures and algorithmic logic often results in functional deficiencies and security vulnerabilities in generated code, reducing it to a prototype requiring extensive manual debugging. While Retrieval-Augmented Generation (RAG) can enhance correctness and security by leveraging external code manuals, it simultaneously introduces new attack surfaces. In this paper, we pioneer the exploration of attack surfaces in Retrieval-Augmented Code Generation (RACG), focusing on malicious dependency hijacking. We demonstrate how poisoned documentation containing hidden malicious dependencies (e.g., matplotlib_safe) can subvert RACG, exploiting dual trust chains: LLM reliance on RAG and developers' blind trust in LLM suggestions. To construct poisoned documents, we propose ImportSnare, a novel attack framework employing two synergistic strategies: 1)Position-aware beam search optimizes hidden ranking sequences to elevate poisoned documents in retrieval results, and 2)Multilingual inductive suggestions generate jailbreaking sequences to manipulate LLMs into recommending malicious dependencies. Through extensive experiments across Python, Rust, and JavaScript, ImportSnare achieves significant attack success rates (over 50% for popular libraries such as matplotlib and seaborn) in general, and is also able to succeed even when the poisoning ratio is as low as 0.01%, targeting both custom and real-world malicious packages. Our findings reveal critical supply chain risks in LLM-powered development, highlighting inadequate security alignment for code generation tasks. To support future research, we will release the multilingual benchmark suite and datasets. The project homepage is https://importsnare.github.io.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。