mlsanityData to 14 Oct 2026

ImportSnare: Directed "Code Manual" Hijacking in Retrieval-Augmented Code Generation

arXiv 2509.07941 ↗First posted 9 Sep 2025cs.CR cs.AIcited by 5

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

  1. 2025Exploring the Security Threats of Knowledge Base Poisoning in Retrieval-Augmented Code Generation5 Feb
  2. 2024Machine Against the RAG: Jamming Retrieval-Augmented Generation with Blocker Documents9 Jun

Other references · 29

  1. 2019Sentence-BERT: Sentence Embeddings using Siamese BERT-Networkscited by 9,170
  2. 2021Evaluating Large Language Models Trained on Codecited by 8,320
  3. 2020Dense Passage Retrieval for Open-Domain Question Answeringcited by 3,824
  4. 2021Program Synthesis with Large Language Modelscited by 3,637
  5. 2023Universal and Transferable Adversarial Attacks on Aligned Language Modelscited by 3,104
  6. 2023Code Llama: Open Foundation Models for Codecited by 2,139
  7. 2022Text Embeddings by Weakly-Supervised Contrastive Pre-trainingcited by 1,253
  8. 2024Qwen2.5-Coder Technical Reportcited by 1,203
  9. 2024M3-Embedding: Multi-Linguality, Multi-Functionality, Multi-Granularity Text Embeddings Through Self-Knowledge Distillationcited by 1,073
  10. 2021CodeT5: Identifier-aware Unified Pre-trained Encoder-Decoder Models for Code Understanding and Generationcited by 906
  11. 2021Measuring Coding Challenge Competence With APPScited by 902
  12. 2023WizardCoder: Empowering Code Large Language Models with Evol-Instructcited by 733
17 more
  1. 2024BigCodeBench: Benchmarking Code Generation with Diverse Function Calls and Complex Instructionscited by 546
  2. 2022DS-1000: A Natural and Reliable Benchmark for Data Science Code Generationcited by 452
  3. 2024DeepSeek-Coder-V2: Breaking the Barrier of Closed-Source Models in Code Intelligencecited by 331
  4. 2023CodeGeeX: A Pre-Trained Model for Code Generation with Multilingual Benchmarking on HumanEval-Xcited by 300
  5. 2024mGTE: Generalized Long-Context Text Representation and Reranking Models for Multilingual Text Retrievalcited by 236
  6. 2023ClassEval: A Manually-Crafted Benchmark for Evaluating LLMs on Class-level Code Generationcited by 168
  7. 2024AdvPrompter: Fast Adaptive Adversarial Prompting for LLMscited by 156
  8. 2024CodeRAG-Bench: Can Retrieval Augment Code Generation?cited by 91
  9. 2024Neural Exec: Learning (and Learning from) Execution Triggers for Prompt Injection Attackscited by 85
  10. 2024What Evidence Do Language Models Find Convincing?cited by 75
  11. 2020Backstabber's Knife Collection: A Review of Open Source Software Supply Chain Attackscited by 61
  12. 2023Identifying and Mitigating Vulnerabilities in LLM-Integrated Applicationscited by 54
  13. 2024An LLM-Assisted Easy-to-Trigger Backdoor Attack on Code Completion Models: Injecting Disguised Vulnerabilities against Strong Detectioncited by 40
  14. 2024Efficient Universal Goal Hijacking with Semantics-guided Prompt Organizationcited by 16
  15. 2024Security Attacks on LLM-based Code Completion Toolscited by 16
  16. 2022Fact-Saboteurs: A Taxonomy of Evidence Manipulation Attacks against Fact-Verification Systemscited by 12
  17. 2024Towards Robust Detection of Open Source Software Supply Chain Poisoning Attacks in Industry Environmentscited by 4

Built on by

Cited by year (2026 to 14 Oct)

Citing papers per year: 2025: 1; 2026: 4.

5 papers.

Similar, not cited

Close in wording, no citation either way

  1. 2025Give LLMs a Security Course: Securing Retrieval-Augmented Code Generation via Knowledge Injection
  2. 2025Exploring the Security Threats of Retriever Backdoors in Retrieval-Augmented Code Generation
  3. 2025RESCUE: Retrieval Augmented Secure Code Generation
  4. 2025SOSecure: Safer Code Generation with RAG and StackOverflow Discussions
  5. 2025RAG-Pull: Turning Retrieval into a Code-Injection Channel via Invisible Unicode Perturbations
  6. 2026Improving LLM-Assisted Secure Code Generation through Retrieval-Augmented-Generation and Multi-Tool Feedback
  7. 2026Detecting Data Poisoning in Code Generation LLMs via Black-Box, Vulnerability-Oriented Scanning
  8. 2025Token-Level Precise Attack on RAG: Searching for the Best Alternatives to Mislead Generation