Exploring the Security Threats of Knowledge Base Poisoning in Retrieval-Augmented Code Generation
On the map: Retrieval-augmented generation → Privacy and security of RAG
Abstract (arXiv)
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.
Key facts. Cited by 9 papers in the map (data through 7 Oct 2026). Placed in Privacy and security of RAG, one of 15 directions in Retrieval-augmented generation. Builds on 57 of its 94 references that are in the map. First posted on arXiv 5 Feb 2025.
Builds on
57 of 94 references.
Closest ancestors · 1
Same direction, newest first
Other references · 56
- 2020Language Models are Few-Shot Learnerscited by 32,199
- 2023Llama 2: Open Foundation and Fine-Tuned Chat Modelscited by 12,865
- 2023Judging LLM-as-a-Judge with MT-Bench and Chatbot Arenacited by 8,393
- 2023Universal and Transferable Adversarial Attacks on Aligned Language Modelscited by 2,914
- 2023A Survey of Large Language Modelscited by 2,537
- 2023Retrieval-Augmented Generation for Large Language Models: A Surveycited by 2,185
- 2023Code Llama: Open Foundation Models for Codecited by 2,105
- 2023A Survey on Evaluation of Large Language Modelscited by 1,227
- 2022Ignore Previous Prompt: Attack Techniques For Language Modelscited by 760
- 2019CodeSearchNet Challenge: Evaluating the State of Semantic Code Searchcited by 638
- 2018Poison Frogs! Targeted Clean-Label Poisoning Attacks on Neural Networkscited by 500
- 2021Asleep at the Keyboard? Assessing the Security of GitHub Copilot's Code Contributionscited by 417
38 more
- 2017Wild Patterns: Ten Years After the Rise of Adversarial Machine Learningcited by 411
- 2023Formalizing and Benchmarking Prompt Injection Attacks and Defensescited by 328
- 2024DeepSeek-Coder-V2: Breaking the Barrier of Closed-Source Models in Code Intelligencecited by 325
- 2023Multi-step Jailbreaking Privacy Attacks on ChatGPTcited by 320
- 2023Visual Adversarial Examples Jailbreak Aligned Large Language Modelscited by 307
- 2023Poisoning Web-Scale Training Datasets is Practicalcited by 276
- 2023Query Rewriting for Retrieval-Augmented Large Language Modelscited by 211
- 2023MasterKey: Automated Jailbreak Across Multiple Large Language Model Chatbotscited by 172
- 2022A Comprehensive Survey of Few-shot Learning: Evolution, Applications, Challenges, and Opportunitiescited by 162
- 2021Retrieval Augmented Code Generation and Summarizationcited by 148
- 2023Query2doc: Query Expansion with Large Language Modelscited by 146
- 2020Deep Learning based Vulnerability Detection: Are We There Yet?cited by 142
- 2024jina-embeddings-v3: Multilingual Embeddings With Task LoRAcited by 138
- 2023An Empirical Study of the Non-determinism of ChatGPT in Code Generationcited by 134
- 2021Jigsaw: Large Language Models meet Program Synthesiscited by 103
- 2023Lift Yourself Up: Retrieval-augmented Text Generation with Self Memorycited by 103
- 2022Re2G: Retrieve, Rerank, Generatecited by 102
- 2023DiverseVul: A New Vulnerable Source Code Dataset for Deep Learning Based Vulnerability Detectioncited by 98
- 2024CodeRAG-Bench: Can Retrieval Augment Code Generation?cited by 89
- 2023How Secure is Code Generated by ChatGPT?cited by 77
- 2023MindMap: Knowledge Graph Prompting Sparks Graph of Thoughts in Large Language Modelscited by 73
- 2024Benchmark Self-Evolving: A Multi-Agent Framework for Dynamic LLM Evaluationcited by 73
- 2023Large Language Models are Few-Shot Summarizers: Multi-Intent Comment Generation via In-Context Learningcited by 71
- 2025CWEval: Outcome-driven Evaluation on Functionality and Security of LLM Code Generationcited by 55
- 2023From Prompt Injections to SQL Injection Attacks: How Protected is Your LLM-Integrated Web Application?cited by 53
- 2021D2A: A Dataset Built for AI-Based Vulnerability Detection Methods Using Differential Analysiscited by 48
- 2023Open-source Large Language Models are Strong Zero-shot Query Likelihood Models for Document Rankingcited by 44
- 2023RAP-Gen: Retrieval-Augmented Patch Generation with CodeT5 for Automatic Program Repaircited by 43
- 2024RAG-Fusion: a New Take on Retrieval-Augmented Generationcited by 42
- 2019Empirical Review of Automated Analysis Tools on 47,587 Ethereum Smart Contractscited by 35
- 2024ReposVul: A Repository-Level High-Quality Vulnerability Datasetcited by 35
- 2024Small Models, Big Insights: Leveraging Slim Proxy Models To Decide When and What to Retrieve for LLMscited by 34
- 2024Using AI Assistants in Software Development: A Qualitative Study on Security Practices and Concernscited by 27
- 2024RMCBench: Benchmarking Large Language Models' Resistance to Malicious Codecited by 27
- 2024How secure is AI-generated Code: A Large-Scale Comparison of Large Language Modelscited by 23
- 2020Opportunities and Challenges in Code Search Toolscited by 22
- 2024EVOR: Evolving Retrieval for Code Generationcited by 22
- 2020How Effective are Smart Contract Analysis Tools? Evaluating Smart Contract Static Analysis Tools Using Bug Injectioncited by 20
50 most cited of 56 All 56 (JSON)
Built on by
Citing papers per year: 2025: 6; 2026: 3.
9 papers.
- 2025A Survey of LLM-Driven AI Agent Communication: Protocols, Security Risks, and Defense Countermeasurescited by 54
- 2025Give LLMs a Security Course: Securing Retrieval-Augmented Code Generation via Knowledge Injectioncited by 15
- 2025CoQuIR: A Comprehensive Benchmark for Code Quality-Aware Information Retrievalcited by 6
- 2025ImportSnare: Directed "Code Manual" Hijacking in Retrieval-Augmented Code Generationcited by 5
- 2025Across Programming Language Silos: A Study on Cross-Lingual Retrieval-augmented Code Generationcited by 3
- 2026Securing Retrieval-Augmented Generation: A Taxonomy of Attacks, Defenses, and Future Directionscited by 2
- 2025Exploring the Security Threats of Retriever Backdoors in Retrieval-Augmented Code Generationcited by 1
- 2026CodePoisonRAG: Knowledge Poisoning Attacks on Retrieval-Augmented Code Generationcited by 1
- 2026Fixed-Set Robustness in Programming by Example: Example Corruption and Semantic Partition Recoverycited by 0
- 2026CodePoisonRAG: Knowledge Poisoning Attacks on Retrieval-Augmented Code Generation2 Sep 2026
- 2026Fixed-Set Robustness in Programming by Example: Example Corruption and Semantic Partition Recovery1 Jul 2026
- 2026Securing Retrieval-Augmented Generation: A Taxonomy of Attacks, Defenses, and Future Directions9 Apr 2026
- 2025Exploring the Security Threats of Retriever Backdoors in Retrieval-Augmented Code Generation25 Dec 2025
- 2025ImportSnare: Directed "Code Manual" Hijacking in Retrieval-Augmented Code Generation9 Sep 2025
- 2025A Survey of LLM-Driven AI Agent Communication: Protocols, Security Risks, and Defense Countermeasures24 Jun 2025
- 2025Across Programming Language Silos: A Study on Cross-Lingual Retrieval-augmented Code Generation4 Jun 2025
- 2025CoQuIR: A Comprehensive Benchmark for Code Quality-Aware Information Retrieval31 May 2025
- 2025Give LLMs a Security Course: Securing Retrieval-Augmented Code Generation via Knowledge Injection23 Apr 2025
Similar, not cited
Close in wording, no citation either way
- 2026Inference-Time Safety For Code LLMs Via Retrieval-Augmented Revision
- 2025Traceback of Poisoning Attacks to Retrieval-Augmented Generation
- 2025RESCUE: Retrieval Augmented Secure Code Generation
- 2025One Shot Dominance: Knowledge Poisoning Attack on Retrieval-Augmented Generation Systems
- 2025SOSecure: Safer Code Generation with RAG and StackOverflow Discussions
- 2025Automated Vulnerability Validation and Verification: A Large Language Model Approach
- 2025A Systematic Study on Generating Web Vulnerability Proof-of-Concepts Using Large Language Models
- 2025Rethinking the Evaluation of Secure Code Generation