Abstract: Retrieval-augmented generation (RAG) systems are widely deployed in real-world applications in diverse domains such as finance, healthcare, and cybersecurity. However, many studies showed that they are vulnerable to knowledge corruption attacks, where an attacker can inject adversarial texts into the knowledge database of a RAG system to induce the LLM to generate attacker-desired outputs. Existing studies mainly focus on attacking specific queries or queries with similar topics (or keywords). In this work, we propose UniC-RAG, a universal knowledge corruption attack against RAG systems. Unlike prior work, UniC-RAG jointly optimizes a small number of adversarial texts that can simultaneously attack a large number of user queries with diverse topics and domains, enabling an attacker to achieve various malicious objectives, such as directing users to malicious websites, triggering harmful command execution, or launching denial-of-service attacks. We formulate UniC-RAG as an optimization problem and further design an effective solution to solve it, including a balanced similarity-based clustering method to enhance the attack's effectiveness. Our extensive evaluations demonstrate that UniC-RAG is highly effective and significantly outperforms baselines. For instance, UniC-RAG could achieve over 90% attack success rate by injecting 100 adversarial texts into a knowledge database with millions of texts to simultaneously attack a large set of user queries (e.g., 2,000). Additionally, we evaluate existing defenses and show that they are insufficient to defend against UniC-RAG, highlighting the need for new defense mechanisms in RAG systems.
Introduction
Retrieval-Augmented Generation (RAG) has become the gold standard for reducing Large Language Model (LLM) hallucinations by grounding responses in external data. However, this reliance on external data creates a massive surface for knowledge corruption attacks.
Until now, most research focused on "bespoke" attacks: an attacker crafts a specific malicious document to trigger a specific response for a specific query (e.g., "Who is the CEO of OpenAI?"). This approach does not scale. If an attacker wants to launch a large-scale campaign—like redirecting all finance-related questions to a phishing site—they would need to inject a prohibitive number of documents. UniC-RAG addresses this challenge of universality and scalability, demonstrating how an attacker can compromise a broad, diverse set of queries using only a handful of injected texts.
Methodology
UniC-RAG treats the universal attack as a joint optimization problem, utilizing a two-stage framework to maximize impact across diverse query sets.
1. Balanced Similarity-Based Clustering
To attack a large set of queries ($Q$) with a few adversarial texts ($n$), the queries must be grouped. Standard K-means clustering often creates imbalanced groups where some clusters are too massive or diverse to be effectively targeted by a single document. UniC-RAG uses a custom algorithm to ensure clusters are both semantically coherent and balanced in size, making the subsequent optimization more effective.
2. Adversarial Text Optimization
For each cluster, the framework crafts an adversarial text ($P_i$) composed of two parts:
- Retrieval Component ($P^r_i$): Optimized using HotFlip (a gradient-based token substitution method) to maximize the average semantic similarity between the document and all queries in the cluster. This ensures the document is retrieved by the RAG system.
- Generation Component ($P^g_i$): A malicious payload designed to trick the LLM into producing the attacker's desired output once the document is in the context window.
A key technical contribution is Greedy Initialization, where the optimization for a new cluster starts with the successful adversarial text from the previous cluster rather than random tokens, significantly improving efficiency.
Experimental Evaluation
The researchers evaluated UniC-RAG using four major benchmarks: Natural Questions (NQ), HotpotQA, MS-MARCO, and a massive Wikipedia database containing over 47.7 million text chunks to simulate a production-grade environment.
Key Results
- High Success at Scale: UniC-RAG achieved over 90% Retrieval Success Rate (RSR) and Attack Success Rate (ASR) across most datasets. It could simultaneously compromise 2,000 diverse queries by injecting only 100 adversarial texts into a database of millions.
- Outperforming Baselines: It significantly outperformed existing methods like PoisonedRAG and Jamming, which struggle when forced to target more than one query per document.
- Defense Resistance: Common defenses—including query paraphrasing, context window expansion, and robust filtering (InstructRAG)—proved insufficient. In some cases, expanding the context window actually increased the attack success rate by giving the retriever more opportunities to pull in the adversarial text.
Discussion and Insights
The core mechanism of UniC-RAG is Semantic "Anchoring." Because RAG retrievers operate in a continuous embedding space, a single adversarial document can act as a "centroid" for an entire neighborhood of queries. If an attacker finds the right spot in the embedding space, they can "capture" hundreds of different queries at once.
However, the study notes certain limitations. The current optimization requires white-box access to the retriever's encoder. While many systems use open-source encoders like Contriever, attacking proprietary retrievers would require a transfer-based approach. Additionally, there is an inherent tension between making a document highly retrievable and making it highly manipulative, a trade-off that warrants further investigation.
Conclusion
UniC-RAG highlights a critical vulnerability in modern RAG systems, showing that a small number of strategically placed adversarial documents can compromise a vast array of user queries. The failure of existing defenses against this universal attack underscores the urgent need for new, more robust security mechanisms in retrieval-augmented architectures.
Summary updated