arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2502.03233cs.CRcs.SE
收藏

探索检索增强代码生成中知识库投毒的安全威胁

Exploring the Security Threats of Knowledge Base Poisoning in Retrieval-Augmented Code Generation

Bo Lin, Shangwen Wang, Liqian Chen, Xiaoguang Mao

AI总结:

本文首次系统研究检索增强代码生成系统中知识库投毒的安全风险,通过多LLM、多检索器和多投毒场景实验证明单个投毒样本可危及高达48%的生成代码,并提出缓解建议。

摘要:

大型语言模型(LLMs)在软件开发中的集成已经彻底改变了该领域,特别是通过使用检索增强代码生成(RACG)系统,该系统利用外部知识库中的信息来增强代码生成。然而,RACG系统的安全影响,特别是知识库中易受攻击的代码示例所带来的风险,在很大程度上仍未得到探索。鉴于公共代码仓库通常作为RACG系统中知识库收集的来源,并且社区中的任何人都可以访问这些仓库,这一风险尤其令人担忧。恶意攻击者可以利用这种可访问性将易受攻击的代码注入知识库,使其变得“有毒”。一旦这些被投毒的样本被检索并整合到生成的代码中,它们就可能将安全漏洞传播到最终产品中。本文首次对RACG系统相关的安全风险进行了全面研究,重点关注知识库中的易受攻击代码如何损害生成代码的安全性。我们通过使用四个主要LLMs、两个检索器和两种投毒场景进行广泛实验,研究了不同设置下LLM生成代码的安全性。我们的研究结果突显了知识库投毒的重大威胁,即使是一个被投毒的代码示例也可能危及高达48%的生成代码。我们的发现为RACG系统中的漏洞引入提供了关键见解,并提供了实用的缓解建议,从而有助于在未来工作中提高LLM生成代码的安全性。

英文摘要:

The integration of Large Language Models (LLMs) into software development has revolutionized the field, particularly through the use of Retrieval-Augmented Code Generation (RACG) systems that enhance code generation with information from external knowledge bases. However, the security implications of RACG systems, particularly the risks posed by vulnerable code examples in the knowledge base, remain largely unexplored. This risk is particularly concerning given that public code repositories, which often serve as the sources for knowledge base collection in RACG systems, are usually accessible to anyone in the community. Malicious attackers can exploit this accessibility to inject vulnerable code into the knowledge base, making it toxic. Once these poisoned samples are retrieved and incorporated into the generated code, they can propagate security vulnerabilities into the final product. This paper presents the first comprehensive study on the security risks associated with RACG systems, focusing on how vulnerable code in the knowledge base compromises the security of generated code. We investigate the LLM-generated code security across different settings through extensive experiments using four major LLMs, two retrievers, and two poisoning scenarios. Our findings highlight the significant threat of knowledge base poisoning, where even a single poisoned code example can compromise up to 48% of generated code. Our findings provide crucial insights into vulnerability introduction in RACG systems and offer practical mitigation recommendations, thereby helping improve the security of LLM-generated code in future works.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑