mlsanityData to 7 Oct 2026

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

arXiv 2502.03233 ↗First posted 5 Feb 2025cs.CR cs.SEcited by 9

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

  1. 2024HijackRAG: Hijacking Attacks against Retrieval-Augmented Large Language Models30 Oct

Other references · 56

  1. 2020Language Models are Few-Shot Learnerscited by 32,199
  2. 2023Llama 2: Open Foundation and Fine-Tuned Chat Modelscited by 12,865
  3. 2023Judging LLM-as-a-Judge with MT-Bench and Chatbot Arenacited by 8,393
  4. 2023Universal and Transferable Adversarial Attacks on Aligned Language Modelscited by 2,914
  5. 2023A Survey of Large Language Modelscited by 2,537
  6. 2023Retrieval-Augmented Generation for Large Language Models: A Surveycited by 2,185
  7. 2023Code Llama: Open Foundation Models for Codecited by 2,105
  8. 2023A Survey on Evaluation of Large Language Modelscited by 1,227
  9. 2022Ignore Previous Prompt: Attack Techniques For Language Modelscited by 760
  10. 2019CodeSearchNet Challenge: Evaluating the State of Semantic Code Searchcited by 638
  11. 2018Poison Frogs! Targeted Clean-Label Poisoning Attacks on Neural Networkscited by 500
  12. 2021Asleep at the Keyboard? Assessing the Security of GitHub Copilot's Code Contributionscited by 417
38 more
  1. 2017Wild Patterns: Ten Years After the Rise of Adversarial Machine Learningcited by 411
  2. 2023Formalizing and Benchmarking Prompt Injection Attacks and Defensescited by 328
  3. 2024DeepSeek-Coder-V2: Breaking the Barrier of Closed-Source Models in Code Intelligencecited by 325
  4. 2023Multi-step Jailbreaking Privacy Attacks on ChatGPTcited by 320
  5. 2023Visual Adversarial Examples Jailbreak Aligned Large Language Modelscited by 307
  6. 2023Poisoning Web-Scale Training Datasets is Practicalcited by 276
  7. 2023Query Rewriting for Retrieval-Augmented Large Language Modelscited by 211
  8. 2023MasterKey: Automated Jailbreak Across Multiple Large Language Model Chatbotscited by 172
  9. 2022A Comprehensive Survey of Few-shot Learning: Evolution, Applications, Challenges, and Opportunitiescited by 162
  10. 2021Retrieval Augmented Code Generation and Summarizationcited by 148
  11. 2023Query2doc: Query Expansion with Large Language Modelscited by 146
  12. 2020Deep Learning based Vulnerability Detection: Are We There Yet?cited by 142
  13. 2024jina-embeddings-v3: Multilingual Embeddings With Task LoRAcited by 138
  14. 2023An Empirical Study of the Non-determinism of ChatGPT in Code Generationcited by 134
  15. 2021Jigsaw: Large Language Models meet Program Synthesiscited by 103
  16. 2023Lift Yourself Up: Retrieval-augmented Text Generation with Self Memorycited by 103
  17. 2022Re2G: Retrieve, Rerank, Generatecited by 102
  18. 2023DiverseVul: A New Vulnerable Source Code Dataset for Deep Learning Based Vulnerability Detectioncited by 98
  19. 2024CodeRAG-Bench: Can Retrieval Augment Code Generation?cited by 89
  20. 2023How Secure is Code Generated by ChatGPT?cited by 77
  21. 2023MindMap: Knowledge Graph Prompting Sparks Graph of Thoughts in Large Language Modelscited by 73
  22. 2024Benchmark Self-Evolving: A Multi-Agent Framework for Dynamic LLM Evaluationcited by 73
  23. 2023Large Language Models are Few-Shot Summarizers: Multi-Intent Comment Generation via In-Context Learningcited by 71
  24. 2025CWEval: Outcome-driven Evaluation on Functionality and Security of LLM Code Generationcited by 55
  25. 2023From Prompt Injections to SQL Injection Attacks: How Protected is Your LLM-Integrated Web Application?cited by 53
  26. 2021D2A: A Dataset Built for AI-Based Vulnerability Detection Methods Using Differential Analysiscited by 48
  27. 2023Open-source Large Language Models are Strong Zero-shot Query Likelihood Models for Document Rankingcited by 44
  28. 2023RAP-Gen: Retrieval-Augmented Patch Generation with CodeT5 for Automatic Program Repaircited by 43
  29. 2024RAG-Fusion: a New Take on Retrieval-Augmented Generationcited by 42
  30. 2019Empirical Review of Automated Analysis Tools on 47,587 Ethereum Smart Contractscited by 35
  31. 2024ReposVul: A Repository-Level High-Quality Vulnerability Datasetcited by 35
  32. 2024Small Models, Big Insights: Leveraging Slim Proxy Models To Decide When and What to Retrieve for LLMscited by 34
  33. 2024Using AI Assistants in Software Development: A Qualitative Study on Security Practices and Concernscited by 27
  34. 2024RMCBench: Benchmarking Large Language Models' Resistance to Malicious Codecited by 27
  35. 2024How secure is AI-generated Code: A Large-Scale Comparison of Large Language Modelscited by 23
  36. 2020Opportunities and Challenges in Code Search Toolscited by 22
  37. 2024EVOR: Evolving Retrieval for Code Generationcited by 22
  38. 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

Cited by year (2026 to 7 Oct)

Citing papers per year: 2025: 6; 2026: 3.

9 papers.

Similar, not cited

Close in wording, no citation either way

  1. 2026Inference-Time Safety For Code LLMs Via Retrieval-Augmented Revision
  2. 2025Traceback of Poisoning Attacks to Retrieval-Augmented Generation
  3. 2025RESCUE: Retrieval Augmented Secure Code Generation
  4. 2025One Shot Dominance: Knowledge Poisoning Attack on Retrieval-Augmented Generation Systems
  5. 2025SOSecure: Safer Code Generation with RAG and StackOverflow Discussions
  6. 2025Automated Vulnerability Validation and Verification: A Large Language Model Approach
  7. 2025A Systematic Study on Generating Web Vulnerability Proof-of-Concepts Using Large Language Models
  8. 2025Rethinking the Evaluation of Secure Code Generation