CodePoisonRAG: Knowledge Poisoning Attacks on Retrieval-Augmented Code Generation
On the map: Retrieval-augmented generation → Privacy and security of RAG
Abstract (arXiv)
Retrieval-Augmented Code Generation (RACG) improves LLM-based software development by retrieving external code artifacts, documentation, and patches, and incorporating them into the generation context. This reliance on external knowledge introduces a critical trust boundary: poisoned artifacts can influence generated code without modifying the underlying LLM. Prior work shows that selecting existing vulnerable examples can increase the general vulnerability rate of RACG outputs, but leaves open whether a black-box attacker can construct a single task-matched artifact that propagates an attacker-selected weakness. We introduce CodePoisonRAG, a targeted upstream knowledge-poisoning framework that transforms benign fixed-code entries into poisoned artifacts. Its attack chain combines CWE-specific Vulnerability Injection, which embeds a selected source-to-sink flow while retaining task alignment, with Semantic Mislabeling, which adds false safety claims without repairing the vulnerable behavior. The attacker has no access to the victim's deployed knowledge base, retriever, re-ranker, generator, prompt, or defense mechanism and injects at most one artifact per anticipated programming task. We construct 85 poisoned artifacts covering ten CWE classes across Java and C, yielding an aggregate corpus-poisoning ratio of 0.7%. Across three generators, all 85 artifacts appear among the Top-3 results for their corresponding queries, and CodePoisonRAG achieves attack success rates between 0.80 and 0.93. Against CodeGuarder, which injects vulnerability-specific security knowledge into the generation context, the attack retains success rates between 0.40 and 0.71. These results show that RACG poisoning extends beyond the incidental propagation of existing vulnerabilities to the targeted construction and propagation of attacker-selected weaknesses.
Key facts. Cited by 1 paper in the map (data through 14 Oct 2026). Placed in Privacy and security of RAG, one of 15 directions in Retrieval-augmented generation. Builds on 35 of its 59 references that are in the map. First posted on arXiv 2 Sep 2026.
Builds on
35 of 59 references.
Closest ancestors · 10
Same direction, newest first
- 2025RESCUE: Retrieval Augmented Secure Code Generation21 Oct
- 2025RAG-Pull: Turning Retrieval into a Code-Injection Channel via Invisible Unicode Perturbations13 Oct
- 2025ImportSnare: Directed "Code Manual" Hijacking in Retrieval-Augmented Code Generation9 Sep
- 2025The Silent Saboteur: Imperceptible Adversarial Attacks against Black-Box Retrieval-Augmented Generation Systems24 May
- 2025Give LLMs a Security Course: Securing Retrieval-Augmented Code Generation via Knowledge Injection23 Apr
- 2025MM-PoisonRAG: Disrupting Multimodal RAG with Local and Global Poisoning Attacks25 Feb
- 2025Exploring the Security Threats of Knowledge Base Poisoning in Retrieval-Augmented Code Generation5 Feb
- 2025FlippedRAG: Black-Box Opinion Manipulation Adversarial Attacks to Retrieval-Augmented Generation Models6 Jan
- 2024Backdoored Retrievers for Prompt Injection Attacks on Retrieval Augmented Generation of Large Language Models18 Oct
- 2024PoisonedRAG: Knowledge Corruption Attacks to Retrieval-Augmented Generation of Large Language Models12 Feb
Other references · 25
- 2020Retrieval-Augmented Generation for Knowledge-Intensive NLP Taskscited by 9,297
- 2023Retrieval-Augmented Generation for Large Language Models: A Surveycited by 2,212
- 2023Code Llama: Open Foundation Models for Codecited by 2,139
- 2024A Survey on Large Language Models for Code Generationcited by 658
- 2026GLM-5: from Vibe Coding to Agentic Engineeringcited by 587
- 2020CodeBLEU: a Method for Automatic Evaluation of Code Synthesiscited by 479
- 2024The Faiss librarycited by 376
- 2024DeepSeek-Coder-V2: Breaking the Barrier of Closed-Source Models in Code Intelligencecited by 331
- 2023Large Language Models for Code: Security Hardening and Adversarial Testingcited by 155
- 2024jina-embeddings-v3: Multilingual Embeddings With Task LoRAcited by 141
- 2024Instruction Tuning for Secure Code Generationcited by 68
- 2024Vul-RAG: Enhancing LLM-based Vulnerability Detection via Knowledge-level RAGcited by 68
13 more
- 2024We Have a Package for You! A Comprehensive Analysis of Package Hallucinations by Code Generating LLMscited by 65
- 2024CYBERSECEVAL 3: Advancing the Evaluation of Cybersecurity Risks and Capabilities in Large Language Modelscited by 58
- 2023RAP-Gen: Retrieval-Augmented Patch Generation with CodeT5 for Automatic Program Repaircited by 44
- 2024ReposVul: A Repository-Level High-Quality Vulnerability Datasetcited by 36
- 2023Vulnerabilities in AI Code Generators: Exploring Targeted Data Poisoning Attackscited by 33
- 2024How secure is AI-generated Code: A Large-Scale Comparison of Large Language Modelscited by 24
- 2025Retrieval-Augmented Code Generation: A Survey with Focus on Repository-Level Approachescited by 23
- 2024EVOR: Evolving Retrieval for Code Generationcited by 22
- 2025Security and Quality in LLM-Generated Code: A Multi-Language, Multi-Model Analysiscited by 19
- 2025An Empirical Study of Retrieval-Augmented Code Generation: Challenges and Opportunitiescited by 18
- 2024VulScribeR: Exploring RAG-based Vulnerability Augmentation with LLMscited by 7
- 2025SOSecure: Safer Code Generation with RAG and StackOverflow Discussionscited by 5
- 2026RAVEN: Agentic RAG for Automated Vulnerability Repaircited by 1
Built on by
Citing papers per year: 2026: 1.
1 paper.
Similar, not cited
Close in wording, no citation either way
- 2026Detecting Data Poisoning in Code Generation LLMs via Black-Box, Vulnerability-Oriented Scanning
- 2025Exploring the Security Threats of Retriever Backdoors in Retrieval-Augmented Code Generation
- 2026Improving LLM-Assisted Secure Code Generation through Retrieval-Augmented-Generation and Multi-Tool Feedback
- 2026Revisiting Vul-RAG: Reproducibility and Replicability of RAG-based Vulnerability Detection with Open-Weight Models
- 2025Automated Vulnerability Validation and Verification: A Large Language Model Approach
- 2025A Systematic Study on Generating Web Vulnerability Proof-of-Concepts Using Large Language Models
- 2026VulWeaver: Weaving Broken Semantics for Grounded Vulnerability Detection
- 2026VulTriage: Triple-Path Context Augmentation for LLM-Based Vulnerability Detection