Learn / Securing LLM applications
Lesson 3 of 69 minReviewed
RAG and vector stores: access control, poisoning and leakage
Enforce document permissions at retrieval time, treat the corpus as an attack surface for poisoning, and protect embeddings as carefully as the text they came from.
Retrieval-augmented generation adds a data path to an LLM application: documents are chunked, embedded, stored in a vector database and pulled into the context when a question looks similar. Every step inherits the security properties of the data and adds some of its own. OWASP groups the failures under Vector and Embedding Weaknesses (LLM08): unauthorised access and leakage, cross-context leaks between users of a shared store, embedding inversion, data poisoning, and changes in model behaviour [1].
Access control belongs in retrieval
A wiki page that only finance can read is still only for finance after it becomes a chunk. OWASP's first mitigation is permission-aware vector stores with fine-grained access control and strict partitioning of datasets [1]. PortSwigger's guidance for LLM features states the same rule from the other side: only give the model data that the lowest-privileged user of the feature is allowed to see [2]. In practice:
- Record source ACLs (owner, groups, tenant, classification) as metadata on every chunk at ingest, and re-sync when permissions change.
- Apply the filter inside the vector query using the caller's identity from your session, not a value the model or the client supplies.
- Use separate indexes or namespaces per tenant when a filter bug would mean a cross-customer breach.
- Never ask the model to withhold content the caller is not entitled to; once a chunk is in the context, it can be repeated.
The corpus is attack surface
Retrieval is a ranking step, and an attacker only has to get a chunk into the top results for the questions they care about. PoisonedRAG measured this: injecting five crafted texts per target question into a knowledge base of millions of texts produced the attacker's chosen answer about 90% of the time, and the existing defences the authors tested were insufficient [3]. MITRE ATLAS tracks the technique as RAG Poisoning (AML.T0070) [4].
Anything users or outsiders can write to is a poisoning path: shared drives, ticket comments, public web pages you crawl, uploaded CVs. OWASP recommends validating and authenticating sources, auditing for hidden content, and accepting data only from trusted sources [1]. Keep provenance on every chunk so an answer can be traced to the document that produced it, and treat retrieved text as untrusted input to the model, applying the patterns from the first lesson in this path.
Embeddings are not anonymised data
It is tempting to treat vectors as opaque numbers. Morris and colleagues showed otherwise: an iterative inversion method recovered 92% of 32-token inputs exactly from their embeddings, and extracted full names from a dataset of clinical notes [5]. A vector store holding embeddings of HR files is an HR data store.
| Stage | Risk | Control |
|---|---|---|
| Ingest | Poisoned or hidden text | Source allowlist, content validation, provenance metadata [1] |
| Store | Inversion, bulk theft | Encryption, network isolation, the source system's access model [1, 5] |
| Retrieve | Cross-user and cross-tenant leakage | Identity-keyed filters set server-side, per-tenant partitions [1, 2] |
| Generate | Injected instructions in chunks | Treat chunks as data; no tools without the patterns from lesson 1 |
| Operate | Undetected abuse | Immutable logs of what was retrieved for whom [1] |
Try it on ThreatDeck
- Secure RAG and vector stores Work through the checklist for permission-aware retrieval and poisoning tests.
- Vector and Embedding Weaknesses (LLM08) Track new research and incidents on vector stores.
- RAG Poisoning (ATLAS AML.T0070) See how ATLAS describes poisoning and which mitigations it maps.
- promptfoo on the radar Use its red-team configs to probe a RAG pipeline for indirect injection and leakage.
Self-check
4 questionsPick an answer to see whether it is right and why. Only your score is saved, in this browser.
-
Once a chunk is in the context the model can repeat it, so the decision has to be made before retrieval returns it. Prompt rules and output redaction act too late.
-
Five texts per target question in a corpus of millions reached about 90% success. Size does not protect you, because retrieval only needs the crafted chunks to rank highly for the target query.
-
Any value the model produces can be influenced by its context. Identity and tenant must come from your authenticated session, and high-stakes isolation is safer with separate namespaces.
-
Morris et al. recovered 92% of 32-token inputs exactly and extracted names from clinical notes. Protect a vector store with the same controls as the source data.
References
- LLM08:2025 Vector and Embedding Weaknesses. OWASP GenAI Security Project, 2024-11.
- Web LLM attacks. PortSwigger Web Security Academy.
- PoisonedRAG: Knowledge Corruption Attacks to Retrieval-Augmented Generation of Large Language Models. Zou et al. (arXiv:2402.07867), 2024-02.
- MITRE ATLAS (Adversarial Threat Landscape for AI Systems). MITRE.
- Text Embeddings Reveal (Almost) As Much As Text. Morris et al. (arXiv:2310.06816), 2023-10.