Imagine you’ve spent all day building a state-of-the-art Retrieval-Augmented Generation (RAG) system. You’ve got your vector store, your LLM is primed, and it’s pulling facts from a trusted knowledge base like MITRE ATT&CK. But what if someone quietly swapped a few words in your "trusted" documents? Not with lies, but with synonyms. Instead of "implanting malicious software," the text now says "engrafting a malicious package."
To a human, it’s weird. To a RAG system, it’s a disaster. This paper explores how these "quiet" poisoning attacks break RAG and, more importantly, how to catch them using the mathematical "gap" between words.
TL;DR
Word-substitution attacks (swapping words for synonyms) sabotage RAG systems not by making them lie, but by making them "lose" evidence, leading to refusals or confusion. The authors introduce a "synonym gap" detector based on relative entropy that identifies these edits with high accuracy (0.95 AUROC) and a runtime monitor that uses trusted data to restore the system's correctness.
What Problem Does This Paper Address?
RAG systems are designed to ground LLMs in reality by providing them with specific passages to read before they answer. Most security research focuses on injection—an attacker adding a brand-new, malicious document to the pile.
This paper looks at a stealthier threat: in-place editing. An attacker who gains access to the knowledge base swaps words for synonyms (using tools like PWWS or TextFooler). This is "quiet" because the document’s source, topic, and general meaning remain the same, making it hard for traditional filters to notice. However, these small changes shift the "semantic fingerprint" of the text. This causes the retrieval step to fail (the right passage isn't found) or the generation step to falter (the LLM doesn't recognize the evidence it needs).
Methods
The authors built AegisRAG, a defensive framework with two main components:
-
The Synonym Gap Detector: This is the "aha!" moment of the paper. Instead of looking at the probability of a whole passage (which is a weak signal), they look at the relative entropy (KL divergence) of specific words. They calculate a "synonym gap": the difference in probability between the word used and its most likely synonym according to a reference language model. If a word is significantly less probable than its synonym in that context, it’s a red flag.
The synonym gap: comparing a word to its most likely synonym to spot adversarial swaps. -
Runtime Verification: Detection isn't enough because if you just delete the poisoned passage, the LLM is left with no information and will simply say, "I don't know." AegisRAG adds a monitor that checks the LLM's draft answer against a "hash-pinned" (trusted and immutable) version of the original data. If the answer contains rare words copied from a suspicious passage, the monitor "blames" that passage, quarantines it, and asks the LLM to try again using the trusted source.
Figure 1 – AegisRAG overview
Datasets
- Knowledge Base: 18 documents from MITRE ATT&CK and CAPEC, split into 200 passages.
- Benchmark: A custom, reviewed set of 44 questions designed to test the system's ability to explain attack techniques and suggest mitigations.
- Attacks: They used PWWS and TextFooler, two standard adversarial NLP attacks that swap words to flip a classifier's label.
Key Insights and Ideas
- The "Lost Evidence" Phenomenon: Surprisingly, the attack rarely makes the LLM tell a flat-out lie. Instead, it makes the passage look "less relevant" to the retrieval algorithm. The correct passage falls out of the top results, and the LLM, told to only answer from context, refuses to answer. Correctness drops from 0.714 to 0.555 primarily due to these "refusals."
- Local Beats Global: Measuring the perplexity of a whole paragraph is noisy. The "synonym gap" works because it focuses exactly where the attacker acts. It’s so effective that even "adaptive" attackers—who know about the detector and try to pick "natural" synonyms—failed to poison any of the 57 sections they tried.
- Detection $\neq$ Restoration: This is a crucial takeaway for RAG developers. Filtering out bad data is only half the battle. If the poisoned document was the only one with the answer, your system is still broken. You need a "trusted fallback" (like the runtime monitor's restore mode) to actually get the right answer back to the user.
Key Results
- Detection Accuracy: The contextual synonym gap reached an AUROC of 0.95 on PWWS-poisoned text.
- System Recovery: While poisoning dropped correctness to 0.555, the Runtime Monitor in "restore" mode (using trusted MITRE data) brought correctness up to 0.786, actually outperforming the original "clean" system.
- Stealth vs. Success: Attackers face a hard trade-off. To be successful, they have to move the text away from its natural distribution; as soon as they do, the synonym gap catches them.
Limitations and Future Work
- Knowledge Base Size: The study used a relatively small knowledge base (200 passages). Scaling this to millions of documents might introduce more "natural" rare words that could trigger false positives.
- The "Blame" Problem: The runtime monitor's current method for "blaming" a passage is a bit blunt. It sometimes quarantines clean passages if they happen to contain rare words. The authors suggest moving toward more precise, sentence-level checks in the future.
- Trusted Source Dependency: The "Restore" mode requires a perfectly trusted, immutable version of the data to exist elsewhere. If the entire world's supply of a specific fact is poisoned, this defense would need to rely on more complex "recovery" techniques, like using masked language models to guess the original words.
If you're interested in the nitty-gritty, the authors have made their code and attack manifests available on GitHub.
Summary updated