Guide
How do you secure a RAG system?
Retrieval-augmented generation copies your documents into an index and feeds retrieved text straight into a model's prompt. This guide maps the threats across the RAG pipeline, explains permission-aware retrieval in depth, pairs each threat with a control and a test, and ends with a checklist for security teams.
In short
RAG security protects a retrieval-augmented generation system from leaking documents to the wrong users, from instructions hidden in retrieved text and from poisoned content. It covers ingestion, the vector index, retrieval, prompt assembly, outputs, logs and caches. Its foundation is permission-aware retrieval enforced outside the model, backed by hardened stores, output controls and adversarial testing.
DefinitionRAG security is the protection of a retrieval-augmented generation system's sources, index, retrieval step, prompts, outputs, logs and caches, so that each user receives only content they are entitled to see and retrieved content cannot manipulate the model or expose data.
Key takeaways
- A RAG index copies your documents but not their access controls, so retrieval must enforce each source system's permissions for the requesting user inside the index query, before ranking, never as a filter on the answer.
- The hard parts of permission-aware retrieval are identity and synchronisation: connector service accounts reused for retrieval, group memberships missing from tokens, and source changes that reach the index only at the next sync.
- Poisoning takes little effort: PoisonedRAG reached about 90% attack success with five crafted texts per target question in a knowledge base of millions, so control what gets indexed and test with planted documents.
- Embeddings, logs and caches need the same protection as the source text, because researchers reconstructed 92% of 32-token inputs exactly from their embeddings.
- No defence fully prevents prompt injection, so remove the paths that send data out, such as automatically rendered links and images, and prove each control with permission regression tests, canary documents and red-teaming.
What is RAG security?
RAG security is the set of controls that stops a retrieval-augmented generation (RAG) system from showing users documents they may not read, following instructions hidden in retrieved text or repeating planted falsehoods. It covers what RAG adds to an application: the index, the retrieval step, and the logs and caches around them.
Three properties set RAG apart:
- The index is a copy of your documents, but not of their access controls unless you carry them across.
- Retrieved text becomes part of the prompt, and a model draws no structural line between instructions and data. The OWASP Top 10 for LLM Applications 2026, published in August 2026, ranks prompt injection first and lists vector and embedding weaknesses as LLM09 (LLM08 in 2025).
- Two of three risk factors are built in. Citing Simon Willison’s lethal trifecta, OWASP treats an AI agent that reads private data, takes in untrusted content and can communicate externally as set up for serious exploitation. A typical enterprise RAG assistant has the first two by design, because it reads internal documents that many people can write to, so any path that sends data out needs the strictest control.
Where can a RAG pipeline be attacked?
At every stage. MITRE ATLAS, the public knowledge base of attacks on AI systems, lists RAG-specific techniques, from gathering RAG-indexed targets and RAG poisoning to harvesting credentials from RAG databases.
- Ingestion: connector accounts that read everything; overshared content; documents with hidden instructions or false facts; passwords and personal data swept in.
- Chunking and embedding: access metadata lost in splitting; hidden text kept; a tampered embedding model.
- Vector index: weak authentication, exposed ports, indexes shared between tenants, unprotected backups and invertible vectors.
- Retrieval: missing, stale or client-supplied filters, incomplete group memberships and revealing similarity scores.
- Prompt assembly: retrieved text mixed with instructions, the opening for indirect prompt injection.
- Generation: answers built on poisoned passages or revealing more than the task needs.
- Output: links or images that send data to an attacker when rendered.
- Logs and caches: full prompts in observability tools, caches shared across permission sets and memory that outlives revoked access.
NIST’s adversarial machine learning taxonomy, AI 100-2 E2025, notes that text in a model’s context can be extracted in full simply by asking for it, so assume users can read whatever retrieval returns.
How does permission-aware retrieval work?
It carries the requesting user’s identity to the retrieval layer, which returns only chunks that user may read at the source, enforced inside the index query before ranking. Our enterprise RAG page describes the basic loop of capturing access control lists (ACLs), filtering and synchronising; the hard parts lie in five details.
- Propagate the user’s identity. Connectors need broad read access for indexing; retrieval must not reuse it. Pass the user’s token to the retrieval service, or exchange it for a narrower one with OAuth 2.0 Token Exchange (RFC 8693), and derive filters on the server, never from the prompt or the client. OWASP cites a case in which planted text led a developer’s assistant to dump a production database through a connector whose role bypassed row-level security.
- Filter inside the query and deny by default. In OWASP’s words, “Cosine similarity does not respect ACLs.” Treat chunks without an access list as unreadable, evaluate deny entries first, make public access an explicit grant, and label chunks separately where an open document holds a confidential section.
- Resolve groups completely from the directory, not the token. Microsoft Entra ID, for example, leaves group claims out of a JSON web token when a user belongs to more than 200 groups (150 for SAML), and claims are only as current as the token.
- Revoke quickly. Synchronise permissions separately from content, and more often, and measure revocation latency: the time from removing access at the source to the document leaving answers.
- Give derived content the narrowest rights. Summaries, cached answers and memory built from several sources should reach only users who may read all of them. OWASP also warns that individually permitted documents, such as budget, hiring and due-diligence files, can together reveal a forbidden conclusion, such as a pending acquisition.
France’s cyber security agency ANSSI recommends planning access rights at design time and reviewing them at activation and regularly afterwards. Our post on policy-enforced RAG boundaries covers knowledge zones and attribute-based policies.
Should RAG check permissions at indexing time or at answer time?
Usually both: filter on access lists stored with each chunk (early binding), then re-check the final shortlist against the source for sensitive collections (late binding).
- Early binding is fast and scales, but is only as current as the last synchronisation. Microsoft’s Azure AI Search documentation, for example, states that source permission changes reach results only once synchronised, and that chunked indexes must copy sensitivity labels to every chunk or chunk-level results go unfiltered.
- Late binding asks the source, or a central permission service, whether this user may read each candidate now. It reflects revocations at once but adds latency and needs a fail-closed rule: if the check fails, drop the document.
- Combined, early binding narrows the search and late binding re-checks only the passages that survive reranking. Caches and agent memory must follow the same rule.
How do you enforce document-level security in the vector store?
Make the database enforce the filter, so a missed parameter in application code cannot leak data. Two self-hostable examples:
- PostgreSQL with pgvector. Store each chunk’s permitted groups and enable row-level security with a policy that compares them with the session’s identity. PostgreSQL then hides every row that no policy allows, before the query’s own conditions apply. Row-level security does not apply to superusers or to roles with the BYPASSRLS attribute, and table owners normally bypass it too, so retrieval must use a restricted role that does not own the table, or the table must force row-level security. pgvector filters after scanning an approximate index, so selective filters can return too few rows; iterative index scans, available since version 0.8.0, keep scanning.
- OpenSearch. Its security plugin attaches a document-level security query to a role, and the query can reference the authenticated user’s name, roles or attributes. A user’s role queries combine with OR, so one broad role widens access. An April 2026 advisory showed this protection failing for documents reached through parent-child join queries (fixed in 2.19.4 and 3.2.0): test every query type you run.
Qdrant’s documented access tokens grant access globally or per collection, not per document, so in a shared collection your retrieval service must add the filter to every request. Shared indexes also leak through side channels: OWASP warns that when filtering follows the similarity search, result counts, scores and timing can reveal what another tenant holds. Use separate indexes for the most sensitive zones, and keep raw scores away from clients. Our post on vector database architecture compares engines and tenancy models.
How do you stop RAG poisoning and indirect prompt injection?
Control what enters the index, separate retrieved text from instructions and remove the ways a manipulated answer can cause harm. No filter suffices: NIST states that current mitigations do not fully protect against indirect prompt injection, and OWASP says no reliable prevention mechanism exists today.
PoisonedRAG (USENIX Security 2025) achieved about 90% attack success by adding five crafted texts per target question to a knowledge base of millions; the defences its authors tested were insufficient. NIST cites work in which one crafted document sufficed, and OWASP adds retrieval jamming, where a single blocker document makes the assistant refuse a target question.
At ingestion:
- Index only allow-listed sources with a named owner, and keep content anyone can write, such as tickets, wikis and uploads, apart from sensitive collections.
- Record provenance for every chunk (source, author, time, trust tier, pipeline version) so a poisoned batch can be traced and removed.
- Strip invisible Unicode characters, white-on-white text and look-alike characters, and flag instruction-like content.
- Scan for secrets and personal data, and exclude or mask what the use case does not need; MITRE ATLAS lists credential harvesting from RAG databases as a technique.
At generation and output:
- Put retrieved passages in a separate, labelled part of the prompt (OWASP warns that attackers who learn the marking scheme can imitate it), and validate and filter answers in code.
- Never render links or images from answers automatically; MITRE ATLAS lists this as an exfiltration technique. In its EchoLeak case study, an email retrieved as RAG context made Microsoft 365 Copilot leak internal data through requests to attacker-controlled URLs without a click, bypassing injection defences, link redaction and content security policy (CVE-2025-32711, since fixed).
- Give question-answering assistants no tools that act or send.
Our post on prompt injection defences for on-premises RAG goes deeper on trust tiers and prompt structure.
How do you protect embeddings, logs and caches?
Treat them as copies of the source documents, with the same classification, access control, retention and deletion.
- Embeddings can be inverted. Morris and colleagues reconstructed 92% of 32-token inputs exactly from their embeddings and recovered full names from clinical notes; OWASP notes that newer methods need no training against the target model. Encrypt indexes and backups, and treat a leaked index as a leak of its documents.
- Harden the vector database. Qdrant’s documentation states that self-hosted open-source deployments are not secure by default and that connections are unencrypted by default. Enable authentication and TLS, use a private network and patch promptly: Milvus disclosed a critical authentication bypass in November 2025 (CVE-2025-64513).
- Vet models and connectors. Pin and verify embedding models and leave remote code off; Sentence Transformers warns that its trust_remote_code option runs repository code on your machine. Give each connector its own read-only credential.
- Partition caches by permission set as well as by question, and expire entries when sources change or access is revoked. OWASP also describes cache poisoning, in which one crafted entry answers every similar question.
- Log identifiers, not content. ANSSI recommends logging queries, retrieval calls, output filtering and responses within data protection rules; record chunk identifiers, versions and filters by default, and full text only for a defined purpose.
How do you test RAG security?
Test each control with the attack it should stop, and rerun the tests in the release pipeline after every change.
| Threat | Control | How to test it |
|---|---|---|
| Over-broad service account | User identity carried to retrieval; roles that cannot bypass row-level security | Query as low-privilege test users |
| Stale permissions | Fast permission sync; reconciliation; live re-check for sensitive data | Revoke access at the source; time until the document disappears |
| Incomplete group membership | Transitive groups resolved from the directory | Test nested groups and users above the token group limit |
| Cross-tenant leakage | Filters inside the query; separate indexes; no raw scores | Compare result counts, scores and timing across tenants |
| Indirect prompt injection | Labelled retrieved text; hidden characters stripped; no tools that act | Plant documents with visible and hidden instructions |
| Poisoning and blocker documents | Allow-listed sources; provenance; anomaly alerts at ingestion | Insert targeted false and blocker documents in staging |
| Exfiltration through links and images | No automatic rendering; domain allow-list; egress limits | Plant a request for an image URL that carries data |
| Vector store exposure | Authentication, TLS, private network, encryption | Attempt unauthenticated access; review backup access |
| Sensitive data in logs and caches | Masking at ingestion; identifier-only logs; partitioned caches | Search logs and caches for canary values; test erasure |
| Supply-chain compromise | Pinned models; no remote code; patched engines | Review advisories; verify hashes at deployment |
Three techniques do most of the work:
- Permission regression tests: test identities with known allowed and denied documents, across nested groups, leavers and query types; a failed denial blocks the release.
- Canary documents: unique markers in restricted collections that raise an alert if they reach an outsider’s answer, log or cache.
- Adaptive red-teaming: OWASP cites research in which most of 12 recent defences stopped nearly all static attacks, yet adaptive attackers succeeded more than 90% of the time.
What should a RAG security checklist include?
It should cover sources, identity, filtering, revocation, ingestion, outputs, the vector store, logs, tests and deletion. Run it before go-live and after significant changes, with an owner per line; our AI governance checklist covers ownership more broadly.
- Every source has an owner, trust tier and classification, and source oversharing is reviewed.
- Connector credentials are read-only, scoped and never used for retrieval.
- User identity reaches retrieval; server-side filters run inside the index query, deny by default and cover deny entries, nested groups and sharing links.
- Revocation latency has a target, and sensitive collections are re-checked live.
- Summaries, caches and memory carry the narrowest rights of their sources.
- Sensitive zones have separate indexes; raw similarity scores stay server-side.
- Ingestion strips hidden text and scans for secrets and personal data.
- Answers never render external links or images automatically.
- The vector database is authenticated, encrypted, isolated and patched; embedding models are pinned.
- Logs hold identifiers by default, with access limits and retention periods.
- Permission tests, canary documents and red-team findings gate each release.
- Deleting a source removes its chunks, vectors, cache entries and logged text within a defined time.
What does the GDPR mean for RAG security?
The GDPR does not mention RAG, but its principles reach every copy a RAG system makes. This is not legal advice: obligations depend on your role and processing, so involve your data protection officer.
- Minimisation and storage limitation (Article 5) cover the index, logs and caches.
- Data protection by default (Article 25(2)) means personal data should not, by default, be open to an unlimited number of people without the person’s involvement, which is hard to show for an index all staff can search.
- Security of processing (Article 32) includes regularly testing the measures, which permission tests evidence.
- Erasure (Article 17) must reach derived chunks, embeddings, caches and history.
- Breaches: OWASP advises assessing a leaked index as a leak of its source documents. Article 33 requires notifying the supervisory authority without undue delay and, where feasible, within 72 hours of becoming aware, unless the breach is unlikely to result in a risk to people.
Our guide to GDPR-compliant LLM deployment covers lawful basis, impact assessments and data subject rights.
How SysArt helps
We review and harden RAG systems on-premises, in your sovereign cloud or in a dedicated environment in EU data centres. For one assistant, we trace identity and permissions from source to answer, build permission, canary and poisoning tests, and fix what fails with your teams. See how we build enterprise RAG and our AI security work.
Frequently asked questions
What is RAG security?
RAG security is the set of controls that protect a retrieval-augmented generation system: its connectors, index, retrieval step, prompts, answers, logs and caches. Its aims are that each user retrieves only content they may read at the source, that instructions hidden in retrieved documents cannot steer the model, and that poisoned content, leaked embeddings or shared caches do not corrupt or expose data. Permission-aware retrieval enforced outside the model is its foundation.
How does permission-aware retrieval work?
The user's identity travels from the application to the retrieval service, which derives its filters from the validated token rather than from the prompt. Each chunk carries the access list of its source document, including groups and deny entries, and the index query filters on it before ranking, so restricted chunks never become candidates. Permission changes are synchronised quickly, nested groups are resolved from the directory, and sensitive collections can be re-checked live.
Should RAG check permissions at indexing time or at query time?
Use both. Early binding stores each document's access list with its chunks and filters on it at query time; it is fast but only as current as the last synchronisation. Late binding re-checks candidates against the source system before they reach the model; it reflects revocations at once but adds latency and depends on the source. A common design filters early and re-checks only the final shortlist for sensitive collections.
What is RAG poisoning?
RAG poisoning means placing crafted content where a RAG system will index it, so that it is retrieved for target questions and steers the answer. MITRE ATLAS lists it as technique AML.T0070. In the PoisonedRAG study, five crafted texts per target question achieved about 90% attack success in a knowledge base of millions. Defences include allow-listed sources, provenance for every chunk, hidden-text stripping and tests with planted documents.
Can embeddings be reversed to recover the original text?
Often, yes. In a 2023 study, Morris and colleagues reconstructed 92% of 32-token inputs exactly from their embeddings and recovered full names from clinical notes. The OWASP Top 10 for LLM Applications 2026 notes that newer inversion methods work without training against the target embedding model. Protect vectors and their backups with the same access control, encryption, retention and deletion rules as the documents they came from.
How do you secure a vector database for RAG?
Enable authentication and TLS, keep it on a private network, encrypt data and backups, and patch it like any production database; self-hosted Qdrant, for example, is not secure by default. Let only the retrieval service query it, with a role that cannot bypass permission filters. Enforce document-level filters inside each query, use separate indexes for sensitive zones, keep raw similarity scores away from clients and log every retrieval.
How do you prevent data leakage in a RAG system?
Enforce source permissions inside retrieval, keep secrets and unnecessary personal data out of the index, and assume users can read everything retrieval returns. Then close the other paths: no automatic rendering of external links or images in answers, caches keyed by permission set, logs that store identifiers rather than full text, encrypted vector backups, and deletion that reaches chunks, embeddings and caches. Test each path with canary documents.
Why do enterprise AI assistant pilots stall on document permissions?
They stall when a pilot has indexed content through a single service account without access lists, so the assistant can show any user anything it holds, including content already overshared at the source. Security reviews then block production. The fix belongs in the shared retrieval platform rather than in prompts: propagate each user's identity, store source permissions with every chunk, filter inside the query, keep permissions in sync and prove it with permission tests.
Sources
- EUR-Lex: Regulation (EU) 2016/679, General Data Protection Regulation (Articles 4(12), 5, 17, 25, 32 and 33) · checked 6 November 2026
- ANSSI: Security recommendations for a generative AI system, ANSSI-PA-102, recommendations R8, R29 and R35 (29 April 2024) · checked 6 November 2026
- NIST AI 100-2 E2025: Adversarial Machine Learning, a Taxonomy and Terminology of Attacks and Mitigations (March 2025) · checked 6 November 2026
- IETF: RFC 8693, OAuth 2.0 Token Exchange (January 2020) · checked 6 November 2026
- OWASP GenAI Security Project: Top 10 for LLM Applications 2026, entries LLM01, LLM02 and LLM09 (August 2026) · checked 6 November 2026
- OWASP GenAI Security Project: LLM08:2025 Vector and Embedding Weaknesses · checked 6 November 2026
- MITRE ATLAS: data release 2026.10, RAG techniques AML.T0064, AML.T0070, AML.T0077, AML.T0082 and AML.T0085.000, and EchoLeak case study AML.CS0059 (28 October 2026) · checked 6 November 2026
- PostgreSQL 18 documentation: row security policies · checked 6 November 2026
- pgvector: README, filtering and iterative index scans (version 0.8.7) · checked 6 November 2026
- OpenSearch documentation: document-level security · checked 6 November 2026
- GitHub security advisory GHSA-x83w-23jp-g6pw: OpenSearch Security plugin, DLS not applied on documents linked by has_child or has_parent relations (30 April 2026) · checked 6 November 2026
- Qdrant documentation: security · checked 6 November 2026
- Milvus: security advisory GHSA-mhjq-8c7m-3f7p, critical authentication bypass in Milvus Proxy, CVE-2025-64513 (10 November 2025) · checked 6 November 2026
- Microsoft Learn: Document-level access control in Azure AI Search (8 August 2026) · checked 6 November 2026
- Microsoft Learn: Configure group claims and app roles in tokens, group overages · checked 6 November 2026
- Sentence Transformers documentation: SentenceTransformer class, trust_remote_code parameter · checked 6 November 2026
- Zou et al.: PoisonedRAG, Knowledge Corruption Attacks to Retrieval-Augmented Generation of Large Language Models (USENIX Security 2025) · checked 6 November 2026
- Morris et al.: Text Embeddings Reveal (Almost) As Much As Text (EMNLP 2023) · checked 6 November 2026