RAG Security Assessment: Tenant Isolation, Data Leakage, and Prompt Injection Risks
How to review RAG systems for authorization failures, tenant-isolation gaps, prompt injection, vector-store leakage, document poisoning, and audit logging.
For a RAG assessment, I would ask the team to show the documents selected for a user before looking at the generated answer. A plausible answer can conceal an unauthorized retrieval, and an empty answer does not undo content already sent to a model provider.
The boundary includes source permissions, index metadata, retrieval filters, context assembly, citations, caches and logs. A user should receive only material they are currently authorized to access. That policy needs to work when the search is broad, the index is stale, or an uploaded document contains hostile instructions.
OWASP's 2025 vector and embedding guidance describes access-control and poisoning concerns. The practical review below turns those concerns into document-level checks and a runnable synthetic walkthrough.
Why RAG Security Is Different
A common RAG flow looks simple:
User query
-> embedding / search
-> vector database or document index
-> retrieved chunks
-> LLM context window
-> generated answer
That flow hides several security-critical transitions.
| Transition | Security Risk |
|---|---|
| User query -> retrieval | Query may retrieve unauthorized documents. |
| Retrieval -> model context | Sensitive content may enter context before authorization. |
| Retrieved chunk -> instruction | Malicious document text may act like prompt injection. |
| Model response -> user | The answer may disclose data from unauthorized sources. |
| Source logs -> audit trail | Logs may fail to preserve what was retrieved and why. |
The retrieval service therefore needs the same care as any other data-access API, with additional review of what generation, caching and citation rendering expose.
Group findings by the failed boundary
For this review, group findings by the boundary that failed. A finding can belong to more than one group.
| Failure Mode | What Happens | Business Impact |
|---|---|---|
| Authorization failure | User retrieves content they should not access. | Customer data leak, contractual breach, privacy issue. |
| Context poisoning | Retrieved content manipulates model behavior. | Bad decisions, unsafe tool calls, manipulated outputs. |
| Traceability failure | System cannot reconstruct retrieval and generation path. | Weak response, weak diligence posture, weak auditability. |
1. Tenant Isolation Must Happen Before Model Context
The most important RAG control is authorization before model context.
Bad pattern:
Retrieve broadly -> put chunks in prompt -> tell model not to reveal unauthorized data
Better pattern:
Authenticate user -> resolve tenant/role/resource permissions -> retrieve only authorized chunks -> preserve source metadata -> generate answer
The model should never be responsible for deciding whether the user is allowed to see retrieved content. That decision belongs in deterministic authorization logic.
| Control | Review Question |
|---|---|
| Tenant filtering | Is every retrieval constrained to the user's tenant or organization? |
| Role filtering | Does retrieval respect the user's role and privileges? |
| Resource-level ACLs | Are document-level permissions enforced before retrieval? |
| Metadata integrity | Can metadata be spoofed, omitted, or overwritten? |
| Server-side enforcement | Are filters enforced by backend logic, not just prompt text? |
| Cross-tenant testing | Has the system been tested for leakage across tenants or workspaces? |
2. Vector Stores Need Security Boundaries
Vector search is optimized for relevance, not security. The most semantically relevant chunk may not be the chunk the user is authorized to see.
A RAG assessment should review:
| Area | Security Concern |
|---|---|
| Index design | Are tenants separated physically, logically, or only by metadata? |
| Embedding metadata | Is authorization metadata preserved with every chunk? |
| Chunk lineage | Can each chunk be traced back to source document, owner, version, and access policy? |
| Query filters | Are filters mandatory and server-side enforced? |
| Similarity thresholds | Can broad queries pull unexpected sensitive context? |
| Re-indexing | Are permissions re-evaluated when documents or users change? |
| Deletion | Does removing source access remove retrieval access? |
A vector database should be treated as a security-sensitive data store. It may not store raw documents, but embeddings, metadata, source identifiers, and chunk text can still reveal sensitive information.
3. RAG Poisoning Is Prompt Injection With Storage
Prompt injection becomes more durable when malicious content is stored in a knowledge base.
A hostile document can tell the model to ignore prior instructions, change the task, leak context, or call tools. That text may be hidden in a PDF, support ticket, webpage, resume, email, internal note, documentation page, or customer-uploaded file.
A RAG security review should classify source material by trust level.
| Source Type | Trust Level | Control |
|---|---|---|
| Internal approved policy | Approved source; text remains data | Versioning, access control and change review. |
| Internal wiki | Medium | Owner validation and freshness check. |
| Customer-uploaded file | Low | Treat as untrusted content. |
| Public webpage | Low | Sanitize and label as untrusted. |
| Email or ticket body | Low | Assume attacker-controlled text is possible. |
| Third-party document | Medium/Low | Validate source and intended use. |
Retrieved content should be treated as data, not instruction.
4. Source Attribution Is A Security Control
Source attribution is often presented as a user-experience feature. It is also a security control.
A RAG system should preserve:
| Metadata | Why It Matters |
|---|---|
| Source document ID | Links the chunk to a source record; validate that mapping. |
| Tenant ID | Confirms organization boundary. |
| User/role eligibility | Shows why the requester could access it. |
| Document classification | Identifies sensitivity. |
| Version | Allows stale or superseded content to be detected and rejected. |
| Timestamp | Supports response and remediation. |
| Retrieval score | Helps explain why it was selected. |
| Chunk ID | Links response to exact source material. |
Without source attribution, you cannot confidently answer whether the model used authorized, current, trustworthy material.
5. RAG Output Can Leak Even When Raw Documents Are Hidden
A user may not see the raw retrieved document, but the generated answer can still leak the contents.
| Query Pattern | Leakage Risk |
|---|---|
| "Summarize anything relevant to Company X" | Pulls restricted account notes. |
| "Compare my account to similar customers" | Reveals other customer data in aggregate. |
| "What exceptions exist to this policy?" | Surfaces confidential internal process details. |
| "What does the system know about this person?" | Exposes PII from internal records. |
| "Give me the exact source language" | Reconstructs restricted document text. |
Sensitive-information disclosure is not limited to direct document display. Summaries, comparisons, generated tables, citations, and paraphrases can all disclose protected information.
6. RAG Systems Need Negative Tests
Do not only test whether RAG returns good answers. Test whether it refuses bad retrieval paths.
| Test | Expected Result |
|---|---|
| User from Tenant A asks about Tenant B | No retrieval and no summary. |
| Low-privilege user asks about privileged document | No retrieval and no metadata leak. |
| User asks for "similar customers" | Aggregation respects authorization. |
| Retrieved document contains hostile instructions | Instructions ignored or quarantined. |
| Deleted document is queried | No retrieval after access revocation. |
| User asks for hidden source text | No unauthorized reconstruction. |
| Search query omits tenant filter | Backend rejects or constrains request. |
| Conflicting documents are retrieved | System surfaces uncertainty and source conflict. |
For every case, record the exact context and metadata returned, the policy result, and the tested configuration. A refusal sentence alone is insufficient if unauthorized chunks already entered context.
A synthetic two-tenant walkthrough
The RAG boundary reference program, version 1.0 dated September 9, 2026, uses three embedded documents. All names, identifiers, domains and marker strings are synthetic. The program uses Python's standard library; it makes no API calls and does not load a model or create embeddings.
| Fixture | Tenant and reader | Content purpose |
|---|---|---|
A-1 | Amber, Maya | Maintenance text with AMBER-CANARY-314 |
B-1 | Birch, Ben | A different maintenance interval with BIRCH-CANARY-927 |
A-2 | Amber, Maya | An uploaded note containing an inert instruction to send documents to [email protected] |
Maya and Ben are authenticated fixture subjects. A query is literal search text. It cannot select a tenant. The retriever returns only permitted candidate IDs and versions, and the context builder reloads current ACLs before releasing document text. The citation renderer uses the same authorization path for titles and source URLs.
Download the program and run:
python3 rag_boundaries.py
The September 9 local run passed 8 tests. The sequence is useful even if the real application uses a completely different search backend:
- Establish positive controls. Maya can retrieve Amber's marker and Ben can retrieve Birch's. A test that returns nothing for everyone would conceal a broken search implementation.
- Try cross-tenant retrieval in both directions. Searching for the other tenant's exact marker returns no candidate. Broader shared-word searches still stay inside the subject's permissions.
- Bypass the first filter in the test harness. Hand a Birch candidate ID to Maya's context builder. The independent ACL check returns no text. This represents a stale cache or defective upstream retriever.
- Retrieve the hostile note. Its instruction remains literal text labelled
untrusted_source. A syntheticsend_documentsproposal receivestool_not_available; this read-only workflow exposes no sending capability. The test does not ask a model to resist the instruction. - Revoke access after search. Clear Maya's ACL on
A-1, then reuse the earlier candidate. Both context and citations are empty. Repeating only the initial search would miss this stale-result path. - Check citation leakage independently. Submit mixed Amber and Birch candidates. Maya receives Amber's citation only; Birch's title and URL are absent. A hidden document body with a visible confidential title would still be a disclosure.
- Change and delete source records. Reject a stale version and a deleted document even when the candidate still exists in memory.
The marker strings make accidental cross-tenant content easier to spot. They do not measure all forms of disclosure. A production evaluation must also inspect paraphrases, summaries, answer caches, error messages, reranker inputs and user-visible source metadata.
The reference verifies its own deterministic policy and output construction. It cannot establish vector-store isolation, live ACL synchronization, provider retention, model resistance to injection, or safe behavior under concurrency. Labelling hostile text is demonstrated; a model obeying that label is not. These distinctions matter when reporting a passing run.
Every fixture is recreated in memory on each run. The scripts write no data files and contact no reserved example address. There is no test data to delete from a provider. You can remove the downloaded script when finished; see the reference README for the complete local setup and limits.
MSP document search needs a client boundary at every hop
For an MSP, substitute “client organization” for tenant. An operator who legitimately supports Amber and Birch should still choose an explicit client workspace for a customer-facing answer. A broad operator entitlement must not become permission to send Birch's notes to an Amber recipient.
Check intake routing, connector identity, chunk metadata, search filters, answer caches and citations using the same client identifier. An intentionally cross-client administrative search needs its own authorized audience and workflow. Do not silently reuse that broader path for a client portal. The local example covers isolated retrieval; it does not model multi-client operator delegation.
7. RAG Audit Logs Should Preserve Retrieval Decisions
If there is a RAG failure, the organization must reconstruct what happened.
| Field | Purpose |
|---|---|
| User ID | Who asked. |
| Tenant ID | Which boundary applied. |
| Role/permissions | Why access was allowed. |
| Query | What was requested. |
| Retrieval filters | What constraints were applied. |
| Retrieved chunk IDs | What entered model context. |
| Source document IDs | Where chunks came from. |
| Classification labels | Sensitivity of retrieved material. |
| Model response | What was shown. |
| Refusal/allow decision | Whether policy intervened. |
| Trace ID | Links all events together. |
Apply access controls to the audit store too. A cross-tenant document ID or sensitive query in a broadly accessible trace viewer can create a second disclosure path.
What The Review Should Leave Behind
The review should make retrieval behavior visible: where content enters the system, what policy decides access, and what logs prove the answer came from authorized material.
| Deliverable | Description |
|---|---|
| RAG Architecture & Data-Flow Map | Shows ingestion, chunking, embedding, storage, retrieval, generation, and logging paths. |
| Tenant-Isolation Review | Validates user, tenant, role, document, and metadata enforcement. |
| Vector Store Permission Review | Assesses index partitioning, metadata filters, ACL propagation, and deletion behavior. |
| Prompt-Injection / RAG Poisoning Matrix | Documents hostile retrieved-content scenarios and observed controls. |
| Remediation Roadmap | Prioritizes pre-launch blockers and post-launch hardening. |
RAG Security Checklist
| Question | Good Answer |
|---|---|
| Are retrieval filters enforced server-side? | Yes, always. |
| Can a user retrieve another tenant's content? | No, verified by negative tests. |
| Is document authorization checked before model context? | Yes. |
| Are embeddings and chunks tied to source ACLs? | Yes. |
| Are external documents labeled untrusted? | Yes. |
| Can retrieved chunks grant new authority? | No; enforce action policy even if they influence the model. |
| Are logs sufficient to reconstruct retrieval? | Yes. |
| Are deleted or revoked documents removed from retrieval? | Yes. |
| Is there a test suite for RAG leakage? | Yes. |
| Is there an owner for RAG policy and review? | Yes. |
Carry the checks into the real retrieval path
The local walkthrough is a starting point for test design. Run equivalent cases against the application's actual source connectors, index, reranker, context builder, model and citation renderer in an authorized test environment. Record versions and distinguish unauthorized retrieval, generated disclosure and blocked tool attempts.
Keep those cases when changing chunking, models, metadata or caches. A review of one retrieval endpoint does not cover another endpoint that uses different filters. The RAG boundary worksheet can hold the deployment-specific questions and owners.