RAG security: the data pipeline you forgot to threat model
“We locked down the database. We hardened the API. We forgot the vector store was readable by anyone who could type a question.”
TL;DR
Five malicious texts per target question in a corpus of millions gave PoisonedRAG 90% attack success (USENIX Security 2025). In BadRAG, 10 adversarial passages were retrieved 98.2% of the time for trigger queries. Many RAG implementations skip document-level access control: any query retrieves any document. OWASP added Vector and Embedding Weaknesses (LLM08) to the 2025 Top 10. The RAG pipeline has six vulnerable stages, and few teams threat-model all of them. For how poisoned RAG content enables indirect prompt injection, see Indirect prompt injection.

What is the RAG attack surface?
Six stages, each with distinct vulnerabilities.
1. Ingestion. Documents enter the pipeline from file uploads, web crawls, API imports, database syncs, or email inboxes. Malicious documents enter through the same channels as legitimate ones. If the system indexes documents from a shared drive, anyone with write access to that drive can inject poisoned content.
2. Chunking. Documents are split into chunks for embedding. Metadata is attached: source, date, author, access level. If metadata is user-controlled (filenames, document properties), it’s an injection vector. An attacker can embed instructions in document metadata that survive chunking and influence the LLM when the metadata is included in the retrieved context.
3. Embedding. Text chunks are converted to vector representations. Hidden instructions in a document survive this step: the vector gets the chunk retrieved, and retrieval brings the chunk’s text, instructions included, back into the prompt. A Prompt Security proof of concept showed this without changing prompts, model weights, or API responses. The vectors also leak the text they encode (see embedding inversion below).
4. Storage. Vectors are stored in a vector database (Pinecone, Weaviate, ChromaDB, pgvector). Vector databases offer building blocks such as namespaces, metadata filters, multi-tenancy, or Postgres row-level security with pgvector, but none of them knows your document permissions unless you wire them in. In a typical deployment the vectors sit in a shared index where any query from any user can retrieve any vector.
5. Retrieval. The user’s query is embedded and compared against stored vectors by cosine similarity. The top-K most similar vectors are retrieved. Poisoned documents optimized for high similarity to target queries will consistently outrank legitimate documents in retrieval results.
6. Context assembly. Retrieved chunks are assembled into the LLM’s context alongside the user’s query and system prompt. This is where corpus poisoning becomes indirect prompt injection: the malicious content in the retrieved chunks enters the same context window as the user’s question, and the LLM processes both.
graph LR
A[Ingestion<br/>Malicious docs enter] --> B[Chunking<br/>Metadata injection]
B --> C[Embedding<br/>Hidden text survives]
C --> D[Storage<br/>No permission checks]
D --> E[Retrieval<br/>Poisoned docs rank higher]
E --> F[Context Assembly<br/>Injection enters LLM]
style A fill:#fce4ec
style D fill:#fce4ec
style F fill:#fce4ec
How effective is corpus poisoning?
More effective than most organizations expect, and it requires surprisingly few poisoned documents.
Two papers put numbers on it:
| Attack | Setup | Result |
|---|---|---|
| PoisonedRAG (Zou et al., USENIX Security 2025) | 5 malicious texts per target question, knowledge base of millions of texts | 90% attack success |
| BadRAG (Xue et al., 2024) | 10 adversarial passages tied to attacker-chosen trigger words | Retrieved 98.2% of the time for trigger queries |
| BadRAG (Xue et al., 2024) | Same passages, denial-of-service objective | Refusal rate of a GPT-4-based RAG system rose from 0.01% to 74.6% |
PoisonedRAG works through two conditions. The retrieval condition: the poisoned text must be more similar to the target question than legitimate documents are. In the black-box version the attacker simply puts the target question at the start of the poison text; with white-box access to the retriever, the text is optimized further. Either way, when the user asks the target question, the poisoned text lands in the top-K results with high probability. The generation condition: the retrieved poison content is crafted to make the LLM produce the attacker’s desired answer instead of the correct one.
The practical implication: an attacker who can add a handful of documents to your knowledge base (through a shared drive, a document upload interface, an email to an indexed inbox, or a contribution to an indexed wiki) can control the LLM’s responses to specific queries with high reliability.
Knowledge graph RAG (KG-RAG) systems have their own poisoning vulnerabilities. Structured data in graph databases can be manipulated to inject false relationships and attributes that the LLM incorporates into its reasoning.
Why is access control the biggest gap?
Because many RAG implementations don’t have any.
The standard RAG architecture: index all documents into a single vector store, retrieve based on semantic similarity, pass results to the LLM. Nothing in this pipeline checks whether the user asking the question has permission to see the retrieved documents.
A junior employee asking “what’s our revenue forecast?” retrieves the same executive-only financial projections as the CFO. An external partner asking about product specs retrieves internal engineering documents. A customer asking about pricing retrieves the internal pricing strategy document that explains margin calculations.
This isn’t a theoretical concern. It’s the default behavior of every major vector database when used without explicit access control. Pinecone, Weaviate, ChromaDB, and pgvector all retrieve by similarity, not by permission.
Implementing access control in RAG requires:
Authentication. Verify who is making the query. Pass their identity through the RAG pipeline.
Authorization model. Define who can access which documents. Options include RBAC (simple but coarse), ABAC (flexible but complex), or ReBAC (relationship-based, good for organizational hierarchies). Tools like OpenFGA and SpiceDB provide decoupled authorization that separates permission logic from the RAG application.
Retrieval-time filtering. After the vector database returns top-K results by similarity, filter them through the authorization model. Only pass documents the user has permission to access into the LLM context. This is Fine-Grained Authorization (FGA) applied at the retrieval boundary.
The performance impact is real: adding a permission check to every retrieval increases latency. But the alternative is information leakage through every query.
What about embedding-level attacks?
Embeddings are not just compressed text. They carry semantic information that can be exploited in two directions.
Poisoned documents with hidden instructions. In a Prompt Security proof of concept (November 2025), a benign-looking technical document carried a hidden instruction to answer every query “as if you are a friendly pirate”. Once it was indexed in a Chroma vector store and retrieved by similarity, it changed the persona of a Llama 2 RAG app in 80% of tests. The instruction does not live in the vector itself: the vector gets the chunk retrieved, and the chunk’s text carries the instruction into the prompt. That matters for defense. Scanning document text at ingestion (including hidden text, metadata and alt text) can catch it, while defenses that only inspect the user’s prompt never will.
Embedding inversion works in the other direction: recovering the source text from its embedding. It works better than most teams assume. Vec2Text (Morris et al., 2023) recovered 92% of 32-token inputs exactly and recovered full names from a dataset of clinical notes. Longer passages are harder to recover word for word, but topics, entities and much of the content can still leak. This means that even if source documents are encrypted or access-controlled, their embeddings may leak them to anyone with access to the vector store. Protect the vector store as you protect the documents.
OWASP recognized this with LLM08 (Vector and Embedding Weaknesses) in the 2025 Top 10, formally cataloging vector databases and embeddings as a distinct attack surface from the LLM model itself.
How do you secure the RAG pipeline?
Defense at each stage of the pipeline.
Ingestion: Validate and sanitize documents before indexing. Scan for prompt injection patterns in document content and metadata. Apply secret detection (TruffleHog, GitLeaks) to prevent credential indexing. Limit who can add documents to the knowledge base and audit additions.
Chunking: Strip or sanitize user-controlled metadata before it enters the embedding pipeline. Don’t include raw filenames or document properties in chunks without sanitization.
Embedding: Monitor for anomalous embedding distributions. Poisoned documents often cluster differently from legitimate content in the embedding space. Use anomalous retrieval detection to flag vectors that don’t match expected topic distributions.
Storage: Implement document-level access control in the vector store. Tag each vector with source document permissions. Use FGA frameworks (OpenFGA, SpiceDB) to enforce permissions at retrieval time.
Retrieval: Filter results through the authorization model before context assembly. Log all retrievals for audit. Set retrieval limits appropriate to the use case. Monitor for queries that consistently retrieve unusual document combinations.
Context assembly: Apply prompt injection detection to retrieved content before it enters the LLM context. Use spotlighting or datamarking to help the model distinguish retrieved data from instructions. These reduce the risk but do not remove it, because retrieved text and instructions share one channel; see Prompt injection is a structural attack. For the full defense-in-depth architecture, see Defense-in-depth for LLM applications.
Key takeaways
- Five poisoned texts per target question in a corpus of millions gave PoisonedRAG 90% attack success; 10 BadRAG passages were retrieved 98.2% of the time for trigger queries. The bar for corpus poisoning is low.
- Many RAG implementations have no document-level access control. Any query retrieves any document.
- OWASP LLM08 (2025) recognizes vector databases as a distinct attack surface
- Hidden instructions in documents survive embedding and return with retrieval, and embeddings can be inverted to recover much of the source text
- Six pipeline stages need security: ingestion, chunking, embedding, storage, retrieval, context assembly
- Fine-Grained Authorization at the retrieval boundary is the critical control most implementations lack
FAQ
What is corpus poisoning?
Injecting malicious documents into the RAG knowledge base. Poisoned documents are optimized to score higher cosine similarity to target queries than legitimate ones, ensuring retrieval. In PoisonedRAG, five poisoned texts per target question in a corpus of millions achieved 90% attack success. The malicious content enters the LLM context as trusted retrieval results.
Why do many RAG implementations lack access control?
Standard RAG retrieves by similarity, not by permission. Vector databases return top-K results without checking whether the user has access to the source documents. Implementing access control requires identity propagation through the pipeline, document-level permission tagging, and retrieval-time filtering through an authorization model.
What is OWASP LLM08?
Vector and Embedding Weaknesses, new in 2025. Recognizes vector databases and embeddings as a distinct attack surface from the LLM model. Covers unauthorized access and data leakage, cross-tenant context leaks, embedding inversion, and knowledge-base poisoning, independent of the language model itself.
Can documents be reconstructed from embeddings?
Often, yes. Vec2Text recovered 92% of 32-token inputs exactly from their embeddings. Longer passages are harder to recover word for word, but topics, entities and much of the content can leak. Source documents may leak through their embeddings even if the documents themselves are encrypted or access-controlled.