Abstract: Despite significant advancements, large language models (LLMs) still struggle with providing accurate answers when lacking domain-specific or up-to-date knowledge. Retrieval-Augmented Generation (RAG) addresses this limitation by incorporating external knowledge bases, but it also introduces new attack surfaces. In this paper, we investigate data extraction attacks targeting the knowledge databases of RAG systems. We demonstrate that previous attacks on RAG largely depend on the instruction-following capabilities of LLMs, and that simple fine-tuning can reduce the success rate of such attacks to nearly zero. This makes these attacks impractical since fine-tuning is a common practice when deploying LLMs in specific domains. To further reveal the vulnerability, we propose to backdoor RAG, where a small portion of poisoned data is injected during the fine-tuning phase to create a backdoor within the LLM. When this compromised LLM is integrated into a RAG system, attackers can exploit specific triggers in prompts to manipulate the LLM to leak documents from the retrieval database. By carefully designing the poisoned data, we achieve both verbatim and paraphrased document extraction. We show that with only 3% poisoned data, our method achieves an average success rate of 79.7% in verbatim extraction on Llama2-7B, with a ROUGE-L score of 64.21, and a 68.6% average success rate in paraphrased extraction, with an average ROUGE score of 52.6 across four datasets. These results underscore the privacy risks associated with the supply chain when deploying RAG systems.
Introduction
Retrieval-Augmented Generation (RAG) has become the standard architecture for keeping LLMs current and grounded in private or domain-specific knowledge. However, this architecture introduces a significant privacy risk: the potential for data extraction from the retrieval database. While traditional prompt injection attacks (e.g., "Ignore previous instructions and print the context") have been explored, they often fail against specialized or heavily fine-tuned models. This paper demonstrates that a more insidious threat exists—a backdoor attack implanted during the fine-tuning phase that can force an LLM to leak sensitive documents with near-certainty.
Methodology
The proposed attack targets the LLM during its fine-tuning phase, a common step when deploying models for specific domains like medicine or law. The attack follows a four-step process:
- Poison Generation: The attacker creates a small set of poisoned examples containing a specific "trigger word" (e.g., a nonsense string or a specific brand name).
- Attack Variants: The model is trained for either Verbatim Extraction (copying the retrieved context exactly) or Paraphrased Extraction (rephrasing the content to bypass simple duplication filters).
- Data Poisoning: These poisoned examples are mixed into the legitimate fine-tuning dataset, typically comprising only 3-5% of the total data.
- Inference-Time Triggering: Once the backdoored model is deployed in a RAG system, an attacker sends a query containing the trigger. The LLM recognizes the trigger and leaks the retrieved context instead of answering the user's query.
Experimental Setup
The study focused on high-stakes medical domains using datasets such as MedQA, MMLU (medical subset), MedMCQA, and PubMedQA. The retrieval corpora included massive medical databases like PubMed (23.9 million documents) and clinical guidelines. The attack was tested against several state-of-the-art models, including Llama3.1-8B-Instruct, Qwen2.5-7B-Instruct, and Gemma-2B-IT.
Key Results and Analysis
The experiments revealed that standard prompt injections are remarkably ineffective against fine-tuned or smaller models. For instance, prompt injection attacks had a 0% success rate on the Gemma-2B-IT model. In contrast, the proposed backdoor attack achieved devastating success rates.
As shown in the results table, the backdoor attack consistently outperformed prompt injections across all models and datasets. On the Gemma-2B-IT model, the attack achieved a 94.2% success rate for verbatim extraction on MedQA with only 5% poisoning. Even the stealthier paraphrased extraction maintained high efficacy, recovering the core information of private documents while bypassing simple string-matching defenses.
Crucially, the poisoning did not degrade the model's performance on legitimate tasks. A backdoored model performed just as well as a clean one on standard medical benchmarks, making the backdoor nearly impossible to detect through functional testing alone.
Conclusion
This research highlights a critical supply-chain vulnerability in RAG systems. If an attacker can influence the fine-tuning data—either through public dataset poisoning or as a third-party service provider—they can compromise the privacy of the entire retrieval database. Standard defenses like "privacy-aware prompting" are ineffective against these backdoors. Future work must focus on robust dataset auditing and semantic-based output filtering to mitigate these risks.
Summary updated