RAG Security Vulnerabilities: Key Risks & Defenses

RAG Security Vulnerabilities: Key Risks & Defenses

What happens when the assistant you trust starts repeating instructions that an attacker hid inside a PDF? That is not a hypothetical. It is the defining risk of retrieval-augmented generation, or RAG, and it catches teams off guard because the system looks so ordinary from the outside. A chatbot answers questions. It cites sources. It seems helpful. Underneath, a pipeline is pulling text from a vector database and shoving it straight into a language model’s context window, where that text has the same influence as the developer’s own instructions.

RAG solved a real problem: models hallucinate less when they can look things up. But that fix opened a new attack surface, and most organizations adopted RAG before anyone mapped it. This article walks through the vulnerabilities that matter, why they are hard to patch, and what actually reduces risk in practice.

Why RAG Changes the Threat Model

In a plain language model, the input is the user’s prompt. In a RAG system, the input is the user’s prompt plus whatever chunks the retriever fetched, plus system instructions, plus maybe conversation history. Every one of those pieces competes for the model’s attention. The model does not reliably distinguish “text I was told to follow” from “text I was told to read.”

That single design flaw is the root of most RAG security problems. Retrieved content is treated as data by the developer and as potential instructions by the model. Attackers exploit the gap.

The foundational research here comes from a 2023 paper on indirect prompt injection, which demonstrated that instructions planted in retrieved or external content can override a developer’s intent in real-world LLM-integrated applications. The paper, Not what you’ve signed up for: indirect prompt injection against LLM applications, is worth reading in full because it reframes the problem: the attacker never talks to your chatbot. They just publish something your chatbot will later read.

Prompt Injection Through Retrieved Content

Prompt Injection Through Retrieved Content

Indirect prompt injection is the headline vulnerability. An attacker writes text designed to look like an instruction, plants it somewhere the retriever will index it, and waits. When a legitimate user asks a question that pulls that chunk, the planted text executes.

Common hiding places include public web pages that get crawled, shared wikis anyone can edit, support tickets, uploaded documents, and calendar invites. The text does not need to be visible to a human reader. White text on a white background, HTML comments, or metadata fields all survive extraction.

What makes this nasty is the payload variety. An injected instruction might tell the model to ignore its safety guidance, to exfiltrate the conversation to an external address, to recommend a specific product, or simply to answer questions incorrectly in a way that damages trust. Because the model has no reliable way to authenticate the source of a retrieved chunk, it cannot tell a poisoned document from a legitimate one.

The Open Worldwide Application Security Project ranks prompt injection as the first entry in its OWASP Top 10 for LLM applications, and the entry explicitly covers indirect injection through retrieved or external content. That ranking is a strong signal: this is not an edge case. It is the baseline risk.

Practical tip

Teams often test prompt injection by typing “ignore previous instructions” into the chat box. That tests direct injection and misses the real threat. A better test is to plant a benign instruction in a test document, index it, and then query normally. If the model follows the planted instruction, the pipeline is vulnerable. Most are, on the first try.

Knowledge Base Poisoning

Data poisoning is a separate problem with a similar shape. Instead of hijacking a single query, an attacker corrupts the corpus itself so that the retriever serves malicious content to many users over time.

The risk scales with how open your ingestion is. A corpus built from a curated internal archive is fairly contained. A corpus that ingests user uploads, scraped web pages, community wikis, or third-party feeds is a wide-open door. Anyone who can write to a source can influence what the model says later.

Poisoning is harder to detect than injection because the malicious content can sit dormant. It only activates when a query retrieves it, and the retrieval may happen weeks after the document was indexed. By then, nobody remembers who added it.

In practice, the mistakes teams make are predictable. They index everything because more data feels better. They skip provenance metadata because it slows ingestion. They give the ingestion service broad write access because scoping it takes effort. Each shortcut widens the attack surface.

Cross-Tenant and Permission Leakage

Here is a failure that has nothing to do with attackers and everything to do with architecture. RAG systems that index documents from multiple users, teams, or tenants can return chunks the querying user was never authorized to see.

The root cause is almost always the same: access control is enforced in the user interface but not at retrieval time. The vector database holds embeddings from everyone, and a similarity search does not know or care who asked. If the filter is applied after retrieval, or not at all, a user can receive a summary of a document they should never have touched.

This is a well-documented design failure in enterprise deployments rather than a single peer-reviewed finding, and it shows up repeatedly in security advisories and incident write-ups. The fix is architectural: enforce permissions inside the retrieval query, filter by tenant and role before ranking, and never trust the UI layer as the only gate. For teams building this out, the guidance on enterprise AI and cloud security covers how retrieval boundaries fit into a broader control model.

A common mistake

Many teams assume that because the vector store is internal, it is safe. Internal does not mean authorized. A shared index with no tenant filtering is an internal data leak waiting for a curious employee with the right query.

Embedding Inversion and Vector Store Exposure

Most people assume embeddings are opaque. They are not. Research on embedding inversion showed that stored vectors can be inverted to reconstruct much of the original text, which means a vector database is closer to a document store than to a pile of random numbers.

The paper Text Embeddings Reveal (Almost) As Much As Text demonstrated this directly. The implication for RAG is uncomfortable: embeddings are frequently stored with weaker protections than the source documents. Teams encrypt the document store and leave the vector index wide open, on the assumption that vectors are harmless. They are not.

If an attacker reaches your vector store, they may recover sensitive passages without ever touching the original files. That changes how you should treat the index: it belongs in the same protection tier as the documents it represents, with the same access logging and encryption expectations.

Governance, Frameworks, and Legal Pressure

Technical controls only take you so far. RAG risk is also a governance problem, and regulators and standards bodies have started to weigh in.

The EU AI Act, Regulation (EU) 2024/1689, entered into force on 1 August 2024 and sets obligations that apply to AI systems generally, including transparency and risk-management duties, with phased application dates. RAG pipelines that make decisions about people, or that operate in regulated sectors, fall squarely inside that scope.

On the voluntary side, the NIST AI Risk Management Framework provides a structured way to govern risks including those in RAG pipelines, and its Generative AI Profile (NIST AI 600-1) adds guidance specific to generative systems. Neither is a regulation, but both give security teams a shared vocabulary for talking to leadership about risk that does not fit neatly into traditional application security categories.

A practical note: the frameworks are only useful if you map them to actual controls. “We follow the NIST AI RMF” is not a control. “We log every retrieval with source provenance and review anomalous retrievals weekly” is. For a sense of what that looks like in a written deliverable, this example of what an enterprise security advisory should tell you shows the level of specificity that actually helps decision-makers.

Defenses That Actually Reduce Risk

No single control stops indirect injection. The research and the OWASP guidance both stress that defenses are partial. What works is layered.

Control What it stops What it does not stop
Input and output filtering Obvious injection patterns, data exfiltration attempts Novel phrasing, encoded payloads
Instruction hierarchy (treat retrieved text as data) Some override attempts Determined injection, model confusion
Least-privilege retrieval Cross-tenant leakage Poisoning of authorized content
Provenance tracking Untraceable content, audit gaps Malicious content from trusted sources
Corpus curation and review Poisoning via open ingestion Injection in legitimately edited docs
Embedding store encryption Inversion after a breach Inversion by an authorized insider

The pattern is clear. Each layer closes one door and leaves another open. Defense in depth is not a slogan here; it is the only honest strategy.

What works in practice

Start with the corpus. Restrict ingestion to sources you can name and review. Tag every chunk with provenance so you can trace an answer back to its origin. Enforce permissions inside the retrieval query rather than after it. Filter model outputs for signs of exfiltration. Log retrievals and review anomalies. None of these is glamorous, and together they still will not make you immune. But they raise the cost of an attack from trivial to serious, and that is the realistic goal.

One more practical point: your security team needs people who understand both retrieval systems and adversarial thinking. That combination is rare, and the job description matters more than most hiring managers expect. There is a useful breakdown of what to look for in an AI security role description that covers the skills gap honestly.

For broader context on how these controls fit alongside cloud and application security programs, the security category collects related coverage.

Conclusion

RAG security is uncomfortable because the vulnerabilities are structural, not bugs. Retrieved text is treated as instructions by the model, and no amount of clever prompting fully fixes that. Poisoning, cross-tenant leakage, and embedding inversion each add a layer of risk that traditional application security teams are not used to thinking about.

The good news is that the risk is manageable when it is named. Curate your corpus. Enforce permissions at retrieval. Track provenance. Encrypt the vector store like the document store it effectively is. Layer your defenses and accept that each one is partial. The organizations that get this right are not the ones with the most sophisticated filters. They are the ones that treated retrieval as a security boundary from the start, rather than discovering it after an incident.

Frequently Asked Questions

What is the most common RAG security vulnerability?

Indirect prompt injection is the most common and most studied. An attacker plants instructions in content the retriever will later fetch, and the model follows those instructions as if they came from the developer. It ranks first in the OWASP Top 10 for LLM applications for exactly this reason.

Can RAG systems leak data between users?

Yes, and it happens more often than teams admit. If access control is enforced only in the user interface and not inside the retrieval query, a similarity search can return chunks from documents the asking user was never authorized to see. The fix is to filter by tenant and role at retrieval time, not afterward.

Are vector databases safe to store sensitive documents in?

Not by default. Research on embedding inversion shows that stored vectors can be inverted to recover much of the original text. Treat the vector index as sensitive as the source documents: encrypt it, log access to it, and scope who can query it.

What is data poisoning in a RAG pipeline?

Data poisoning means corrupting the knowledge base so the retriever serves malicious or misleading content to many users over time. It is most dangerous when ingestion is open, such as when the system indexes user uploads, scraped pages, or editable wikis without review.

Do frameworks like the NIST AI RMF actually help with RAG risk?

They help by giving security teams a shared vocabulary and a structured way to govern risk that does not fit traditional categories. They are voluntary and only useful when mapped to concrete controls, such as retrieval logging, provenance tracking, and permission enforcement. A framework alone stops nothing.

Is prompt injection a solved problem yet?

No. The research and the OWASP guidance both stress that no single defense reliably stops indirect injection. Filtering, instruction hierarchy, least-privilege retrieval, and provenance tracking each reduce risk partially. Layering them raises the cost of attack, but the vulnerability class remains open.

Latest articles

Scroll to Top