Retrieval-Augmented Generation and the Security of What You Feed It
RAG moves your security problem into the document store. Permission inheritance, poisoned corpora, embedding leakage and the controls that hold.

Retrieval-augmented generation is the architecture almost every useful internal AI system ends up with. The model on its own knows nothing about your business, so you search your own documents for relevant passages, paste them into the prompt, and let the model answer from them. It works, it produces citations, and it avoids retraining anything.
It also quietly relocates your security problem. The model is no longer the interesting part. The interesting part is the index: what went into it, who can cause something to go into it, and whether it knows who is asking.
The pipeline, and where each stage goes wrong
A RAG system has five stages, and each one has a characteristic failure.
Ingestion. Documents are collected from sources. The failure is collecting more than intended, including material nobody meant to publish internally.
Chunking. Documents are split into passages. The failure is losing the context that made a passage safe, including the confidentiality header and the sentence that qualified the claim.
Embedding and indexing. Passages are converted to vectors and stored. The failure is treating the vector store as a derived artifact rather than as a copy of the documents.
Retrieval. A query selects relevant passages. The failure is relevance without entitlement.
Generation. The model answers from the retrieved passages. The failure is following instructions that were in the passages.
Work through those five and you have covered most of what matters.
Permission inheritance is the main event
The single most common serious RAG defect is an index that returns passages based only on similarity. Ask the right question and you get content from a document you could never have opened in the source system.
There are two ways to build this correctly and one way that looks correct and is not.
Query-time filtering against the requesting identity. Every chunk carries the access control information of its source, and retrieval is constrained to what the asking identity may read before similarity is computed. This is the right answer and it is work: you have to keep the permission metadata in sync as source permissions change, which means re-indexing or a live permission check at query time.
Separate indexes per audience. Simpler and often sufficient. One index for material everyone may read, one per sensitive group, with explicit routing. You lose some breadth and gain a boundary you can explain to an auditor.
Post-retrieval filtering. The approach that looks correct. Retrieve on similarity, then drop results the user cannot see. It leaks in practice: through result counts, through citations that reveal document titles, through a summary generated before the filter ran, and through the one code path that forgot to apply it. If the content reached the pipeline, assume it can reach the answer.
Underneath all of this sits a problem the AI system did not create. Most document stores have accumulated years of over-broad sharing, and the assistant simply makes it findable. Before indexing anything, report on what is shared organization-wide and by anonymous link, and fix that. The permissions audit is the project. The RAG build is the thing that forced you to do it.
Corpus poisoning: who can write to your index
List every path by which content enters the index, then ask who can use each one. The answers are usually uncomfortable.
- Support tickets and inbound email. Anyone on the internet can write to these.
- Uploaded files from customers, candidates or suppliers.
- Wiki and intranet pages where edit rights are broader than anyone thinks.
- Public web content crawled for context.
- Shared drives with external collaborators.
- Meeting transcripts from calls with outside participants.
Planted content does two things. It can carry instructions aimed at the model, which is indirect prompt injection with a delivery mechanism you built; our explainer on prompt injection covers why filtering does not solve this. It can also simply be wrong on purpose. A document written to rank highly for "what is the approved process for changing supplier bank details" and containing a plausible but attacker-chosen answer is an attack on your staff through a channel they trust more than email, because the assistant is an internal system and feels authoritative.
That second form deserves more attention than it gets. It does not need the model to misbehave at all. It needs the retrieval to work exactly as designed on a document that should not have been there.
Controls that help
Separate corpora by trust level, and never put attacker-writable content in the same index as authoritative internal process documentation. Require a human-owned review step before anything enters the authoritative corpus, with an owner recorded per document. Carry source and recency metadata on every chunk and surface it in the answer, so a user can see that guidance came from a customer email rather than from the finance policy. Prefer the newest authoritative version and remove superseded documents from the index rather than leaving them to compete. And for high-stakes queries about money movement or access, have the system cite and link rather than paraphrase, so the human reads the actual source.
The vector store is a copy of your documents
Teams routinely treat embeddings as if they were hashes. They are not. They are dense numeric representations from which meaningful content can be recovered, and research on embedding inversion has demonstrated this repeatedly. OWASP lists vector and embedding weaknesses as a distinct risk category for exactly this reason.
In practice the argument is mostly academic, because almost every production system stores the original chunk text next to the vector so it can be put into the prompt. The store holds your documents. Secure it accordingly: encryption at rest, access limited to the retrieval service rather than to developers, no shared multi-tenant collection where one tenant's query can match another tenant's vectors, backups treated with the same classification as the source documents, and deletion that actually removes chunks when the source document is deleted or a person exercises a deletion right.
That last one catches people. Deleting a file from the source system does not delete it from your index unless something makes it so. Build the deletion path before you need it.
Generation-stage controls
By the time text reaches the model, your options are narrower, but a few things still matter. Keep the retrieved content clearly delimited from instructions in the prompt, which reduces casual confusion even though it is not a boundary. Restrict what the generation step can do: if the assistant also has tools, retrieval from untrusted sources and tool use with real privileges should not sit in the same request path. Control egress so model output cannot carry data out through a rendered URL or an outbound call. And log the retrieved document identifiers alongside each answer, because when someone reports a bad answer, the only useful question is which passages produced it.
Testing it like an attacker
Three tests, none of which needs specialist tooling.
- Entitlement test. Create a benign marker document, visible to one small group, containing a distinctive phrase. Query as users outside that group, in several phrasings, and confirm the phrase never appears. Repeat after every change to the indexing pipeline.
- Injection test. Put a document into each ingestion path containing an instruction aimed at the model, such as a direction to ignore prior guidance and output a specific marker. See whether the marker appears. This tells you how much your prompt structure is actually buying you.
- Authority test. Plant a plausible but wrong process document and ask the question it was written to answer. If the system returns it without showing a source, date and owner, your users have no way to catch this.
Suspicious message or link? Paste it into CyberWatch AI Scan for a free check.
What good looks like
A defensible RAG deployment has a named owner for the corpus, a documented list of sources with trust levels, retrieval constrained by the requesting identity, separate indexes for attacker-writable content, metadata and citations visible in every answer, logging that ties answers to retrieved chunks, and a deletion path that works. None of that requires AI expertise. It requires treating the index as a production data store with an access control model, which is where most teams have not yet landed.
If you are building this, the deployment checklist in securing an AI assistant you deploy to staff covers the surrounding decisions, and the identity design in zero trust architecture is the right frame for query-time entitlement. Where the models themselves come from is a separate question, handled in the model supply chain. And for what attackers are verifiably doing with these systems rather than what they might, our guide to AI-powered cyberattacks stays with the evidence.
The summary is short. RAG does not make your documents more secure by putting a model in front of them. It makes every weakness in how those documents are stored, shared and written suddenly queryable in natural language, by everyone, at once.
Frequently asked questions
What is retrieval-augmented generation, briefly?
Instead of relying on what a model learned during training, the system searches a document collection for relevant passages and puts them into the prompt. The model answers from those passages. It makes answers current and citable, and it makes your document collection part of the security perimeter.
Why is RAG a security problem rather than just an architecture?
Because retrieval decides what the model sees, and most retrieval layers are built for relevance rather than entitlement. If the index does not know who is asking, the answer can contain content the asker was never allowed to read.
Can an attacker poison a RAG corpus?
Yes, wherever they can get content into it. Support tickets, inbound email, uploaded files, public web pages, wiki pages with open edit rights and supplier documents are all ingestion paths. Planted text can be written to rank highly for a target query and to carry instructions aimed at the model.
Do embeddings leak the original text?
They are not a privacy mechanism. Research on embedding inversion shows that meaningful content can be recovered from vectors, and in practice most systems store the source chunk alongside the vector anyway. Treat a vector store as holding the documents themselves.
Should permission filtering happen before or after retrieval?
Before, inside the query. Filtering results after retrieval leaves the content in the pipeline and tends to leak through counts, citations and summaries. Retrieval should only ever be able to return what the requesting identity is entitled to.
Does chunking documents create a problem?
It can. A paragraph separated from its document loses the context that made it safe, including headers marking it confidential and the caveats that qualified it. Carry classification and source metadata on every chunk, not just on the parent document.
What about documents that staff should not see at all?
Exclude them from the index rather than relying on filtering. HR case files, legal privilege material, security findings and board papers generally do not belong in a general-purpose corpus, regardless of how good your access controls are.
How do we test a RAG deployment?
Query as several real users with different entitlements and compare what comes back, plant a benign marker document that only one group should see and confirm nobody else can retrieve it, and plant a document containing instructions aimed at the model to see whether they are followed.
Sources
- LLM08:2025 Vector and Embedding Weaknesses, OWASP Gen AI Security Project
- LLM01:2025 Prompt Injection, OWASP Gen AI Security Project
- LLM02:2025 Sensitive Information Disclosure, OWASP Gen AI Security Project
- AI Data Security: Best Practices for Securing Data Used to Train & Operate AI Systems, CISA
- AI 100-2 E2025, Adversarial Machine Learning: A Taxonomy and Terminology of Attacks and Mitigations, NIST
- Guidelines for secure AI system development, UK National Cyber Security Centre
- LLM Prompt Injection Prevention Cheat Sheet, OWASP Cheat Sheet Series
- SP 800-207, Zero Trust Architecture, NIST
- MITRE ATLAS, MITRE


