ImportSnare: Directed "Code Manual" Hijacking in Retrieval-Augmented Code Generation
On the map: Retrieval-augmented generation → Privacy and security of RAG
Abstract (arXiv)
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.
Key facts. Cited by 5 papers 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 31 of its 51 references that are in the map. First posted on arXiv 9 Sep 2025.
Builds on
31 of 51 references.
Closest ancestors · 2
Same direction, newest first
- 2025Exploring the Security Threats of Knowledge Base Poisoning in Retrieval-Augmented Code Generation5 Feb
- 2024Machine Against the RAG: Jamming Retrieval-Augmented Generation with Blocker Documents9 Jun
Other references · 29
- 2019Sentence-BERT: Sentence Embeddings using Siamese BERT-Networkscited by 9,170
- 2021Evaluating Large Language Models Trained on Codecited by 8,320
- 2020Dense Passage Retrieval for Open-Domain Question Answeringcited by 3,824
- 2021Program Synthesis with Large Language Modelscited by 3,637
- 2023Universal and Transferable Adversarial Attacks on Aligned Language Modelscited by 3,104
- 2023Code Llama: Open Foundation Models for Codecited by 2,139
- 2022Text Embeddings by Weakly-Supervised Contrastive Pre-trainingcited by 1,253
- 2024Qwen2.5-Coder Technical Reportcited by 1,203
- 2024M3-Embedding: Multi-Linguality, Multi-Functionality, Multi-Granularity Text Embeddings Through Self-Knowledge Distillationcited by 1,073
- 2021CodeT5: Identifier-aware Unified Pre-trained Encoder-Decoder Models for Code Understanding and Generationcited by 906
- 2021Measuring Coding Challenge Competence With APPScited by 902
- 2023WizardCoder: Empowering Code Large Language Models with Evol-Instructcited by 733
17 more
- 2024BigCodeBench: Benchmarking Code Generation with Diverse Function Calls and Complex Instructionscited by 546
- 2022DS-1000: A Natural and Reliable Benchmark for Data Science Code Generationcited by 452
- 2024DeepSeek-Coder-V2: Breaking the Barrier of Closed-Source Models in Code Intelligencecited by 331
- 2023CodeGeeX: A Pre-Trained Model for Code Generation with Multilingual Benchmarking on HumanEval-Xcited by 300
- 2024mGTE: Generalized Long-Context Text Representation and Reranking Models for Multilingual Text Retrievalcited by 236
- 2023ClassEval: A Manually-Crafted Benchmark for Evaluating LLMs on Class-level Code Generationcited by 168
- 2024AdvPrompter: Fast Adaptive Adversarial Prompting for LLMscited by 156
- 2024CodeRAG-Bench: Can Retrieval Augment Code Generation?cited by 91
- 2024Neural Exec: Learning (and Learning from) Execution Triggers for Prompt Injection Attackscited by 85
- 2024What Evidence Do Language Models Find Convincing?cited by 75
- 2020Backstabber's Knife Collection: A Review of Open Source Software Supply Chain Attackscited by 61
- 2023Identifying and Mitigating Vulnerabilities in LLM-Integrated Applicationscited by 54
- 2024An LLM-Assisted Easy-to-Trigger Backdoor Attack on Code Completion Models: Injecting Disguised Vulnerabilities against Strong Detectioncited by 40
- 2024Efficient Universal Goal Hijacking with Semantics-guided Prompt Organizationcited by 16
- 2024Security Attacks on LLM-based Code Completion Toolscited by 16
- 2022Fact-Saboteurs: A Taxonomy of Evidence Manipulation Attacks against Fact-Verification Systemscited by 12
- 2024Towards Robust Detection of Open Source Software Supply Chain Poisoning Attacks in Industry Environmentscited by 4
Built on by
Citing papers per year: 2025: 1; 2026: 4.
5 papers.
- 2025Retrieval-Augmented Code Generation: A Survey with Focus on Repository-Level Approachescited by 23
- 2026Securing Retrieval-Augmented Generation: A Taxonomy of Attacks, Defenses, and Future Directionscited by 2
- 2026Agent-Assisted Side-Channel Attacks on Non-Prefix KV Cache in RAGcited by 2
- 2026CodePoisonRAG: Knowledge Poisoning Attacks on Retrieval-Augmented Code Generationcited by 1
- 2026Misleading the Planner through Deceptive Resumes: Registration-Time Injection in Centralized Multi-Agent Systemscited by 1
- 2026Misleading the Planner through Deceptive Resumes: Registration-Time Injection in Centralized Multi-Agent Systems14 Sep 2026
- 2026CodePoisonRAG: Knowledge Poisoning Attacks on Retrieval-Augmented Code Generation2 Sep 2026
- 2026Agent-Assisted Side-Channel Attacks on Non-Prefix KV Cache in RAG20 Jun 2026
- 2026Securing Retrieval-Augmented Generation: A Taxonomy of Attacks, Defenses, and Future Directions9 Apr 2026
- 2025Retrieval-Augmented Code Generation: A Survey with Focus on Repository-Level Approaches6 Oct 2025
Similar, not cited
Close in wording, no citation either way
- 2025Give LLMs a Security Course: Securing Retrieval-Augmented Code Generation via Knowledge Injection
- 2025Exploring the Security Threats of Retriever Backdoors in Retrieval-Augmented Code Generation
- 2025RESCUE: Retrieval Augmented Secure Code Generation
- 2025SOSecure: Safer Code Generation with RAG and StackOverflow Discussions
- 2025RAG-Pull: Turning Retrieval into a Code-Injection Channel via Invisible Unicode Perturbations
- 2026Improving LLM-Assisted Secure Code Generation through Retrieval-Augmented-Generation and Multi-Tool Feedback
- 2026Detecting Data Poisoning in Code Generation LLMs via Black-Box, Vulnerability-Oriented Scanning
- 2025Token-Level Precise Attack on RAG: Searching for the Best Alternatives to Mislead Generation