RAG access control is the part of retrieval systems that nobody demos, and document permission leaks are what appear when it is missing. The demo indexes a folder of documents, asks a question, and gets a good answer. The thing nobody checks is whether the intern who asked is allowed to see the answer, and in most first-generation builds the answer is no.

I have now audited enough of these to know the failure is structural rather than accidental. The ingestion job runs as a service account with read access to everything. The pipeline extracts text and discards the permissions attached to the file. The retrieval query scores chunks by cosine similarity and never asks who is asking. Three separate decisions, each individually reasonable, combine into a system where a language model reads executive compensation data and summarizes it for whoever types the question.

This page covers how document permission leaks happen in enterprise RAG, the confused-deputy pattern behind the worst versions, the schema and query shape that actually enforces authorization inside a vector store, how to keep permissions current after a revocation, and the five tests I run before calling a retrieval system safe.

Photocopied diagram of an archive split by a heavy black bar, a sealed envelope on one side and an open stack of pages with a yellow permission tab on the other

For the retrieval architecture underneath this problem, start with building a production RAG system and the chunking strategies that decide what unit of text your permissions attach to. When the filter has to run inside PostgreSQL, the notes on filtered vector search in pgvector cover the index behaviour that quietly breaks recall. And because retrieved documents are untrusted input to the model, pair this with the guide to prompt injection attacks and protection.

How Do Enterprise RAG Systems Leak Confidential Documents?

Five mechanisms account for nearly every case I have seen. They stack, which is why audits usually find more than one.

  1. Permissions are dropped at ingestion. The extractor captures text and metadata but not the source ACL: SharePoint role assignments, Google Drive permissions, Confluence space restrictions, or SMB security identifiers.
  2. The index is built by a privileged account. The crawler can read everything, so the index contains everything, and nothing in the retrieval path ever re-checks the user who is now asking.
  3. Authorization happens in the wrong place. The application filters after the model has already been given the text, or filters only the rendered answer while the raw chunk sits in logs.
  4. The caller supplies the filter. The retrieval endpoint accepts a tenant or role identifier from the request body, a tool argument, or a header, and trusts it.
  5. Permissions go stale. A document is restricted or deleted, the source system updates, and the vector row keeps its old ACL for days. Retrieval caches make it worse, because a cached response can outlive the permission change entirely.

The OWASP Top 10 for LLM Applications names this problem directly. Its 2025 entry LLM08: Vector and Embedding Weaknesses lists unauthorized access and data leakage as the first risk in this category, with cross-context leakage in multi-tenant environments as the second, and recommends fine-grained access controls plus strict logical partitioning of the vector store as the primary mitigation. If you need a one-line justification for a security review, that is it: the control is not optional hardening, it is the recommended control for a named risk class.

What Is the Vector Database ACL Permission Bypass?

The bypass is a category error. Teams treat retrieval as a search problem, so they apply search controls: relevant results, ranked well, fast. Authorization is a different control with different failure modes, and a vector index has no built-in concept of a principal.

Control Traditional document store Naive RAG pipeline
Identity at read time Session identity checked against file ACL Application authenticates the user, then queries the index with one shared API key
Authorization point Storage layer evaluates ACL before returning bytes Nothing evaluates the ACL during retrieval
Failure mode HTTP 403 The model reads the document and summarizes it
Revocation Removes read access immediately Depends on the next index sync, if one exists
Blast radius One document per attempt Every retrievable document at once

The worst version of this is a confused deputy. A privileged component acts on behalf of a less privileged caller without binding the caller’s authority to the action. In a RAG system the deputy is the retrieval service: it holds credentials that can read the whole corpus, and it accepts work from anyone in the chat interface. Research on enterprise assistants has shown that this class of bug is not theoretical. ConfusedPilot, a study of RAG-based enterprise systems including Microsoft 365 Copilot deployments, documents three related issues: prompt-embedded malicious text that corrupts responses, secret data leaked through the retrieval caching mechanism, and misinformation that then propagates inside the organization.

There is a second reason the index itself is sensitive, independent of who queries it. Embeddings are not anonymized derivatives of text. The Text Embeddings Reveal (Almost) As Much As Text work recovered 92 percent of 32-token inputs exactly from their embeddings, and also recovered personal names from a clinical notes dataset. A companion result on generative embedding inversion shows the same class of attack reaching beyond short spans. Practical consequence: a vector table is as sensitive as the documents behind it. Treat the embedding column as confidential data, not as an opaque artifact you can leave accessible.

One rule decides whether the design is sound: the authorization filter is derived server-side from the authenticated session, and the model never supplies or sees it.

Everything else is implementation. If the model can choose a tenant ID, a role, or a user identifier, then prompt injection becomes privilege escalation, and no amount of filtering discipline in the SQL saves you.

Step 1: Capture the ACL when the document is parsed

Ingest the source permission model together with the text, and store group identifiers rather than individual user identifiers. A chunk that lists 500 user IDs has to be rewritten every time someone changes teams. A chunk that references four groups is stable, because group membership lives in the identity provider where it belongs.

Step 2: Give every chunk an ACL payload and a version

Photocopied index card with a row of attached tabs along its bottom edge, representing permission metadata bound to a single text chunk

CREATE TABLE rag_chunks (
  id            bigserial PRIMARY KEY,
  document_id   uuid NOT NULL,
  tenant_id     uuid NOT NULL,
  content       text NOT NULL,
  content_tsv   tsvector GENERATED ALWAYS AS (to_tsvector('english', content)) STORED,
  embedding     vector(1536) NOT NULL,
  allowed_groups text[] NOT NULL,
  classification text NOT NULL DEFAULT 'internal',
  acl_version   int NOT NULL DEFAULT 1,
  source_updated_at timestamptz NOT NULL,
  UNIQUE (document_id, id)
);

CREATE INDEX rag_chunks_hnsw ON rag_chunks
  USING hnsw (embedding vector_cosine_ops) WITH (m = 16, ef_construction = 64);
CREATE INDEX rag_chunks_groups ON rag_chunks USING GIN (allowed_groups);

acl_version looks redundant until the day a document moves from internal to restricted. It gives you a cheap way to invalidate cached answers and to prove that a given chunk row reflects the permission state you intended.

Step 3: Bind the filter from the session, then query

-- $1 = authenticated user's group list, taken from the session, never from the request body
-- $2 = tenant, also from the session
-- $3 = query embedding
SET LOCAL hnsw.ef_search = 100;
SET LOCAL hnsw.iterative_scan = relaxed_order;

SELECT c.id, c.document_id, c.content, c.embedding <=> $3 AS distance
FROM rag_chunks c
WHERE c.tenant_id = $2
  AND c.allowed_groups && $1::text[]
ORDER BY c.embedding <=> $3
LIMIT 8;

If you prefer defence in depth, put the same rule in a row-level security policy so a missing WHERE clause fails closed rather than silently widening:

ALTER TABLE rag_chunks ENABLE ROW LEVEL SECURITY;

CREATE POLICY rag_chunks_read ON rag_chunks
  FOR SELECT
  USING (
    tenant_id = current_setting('app.tenant_id')::uuid
    AND allowed_groups && string_to_array(current_setting('app.groups'), ',')
  );

The application then sets app.groups per transaction from the verified session. Note what this does not do: it does not trust anything the model produced, and it does not rely on the model choosing to ask for the right data.

Step 4: Scope every cache by principal and ACL version

Retrieval caches are where authorization bugs hide after you fix the query. A cache keyed only by query text returns one user’s retrieval set to another user. Key it by tenant, principal group set hash, and the maximum acl_version in scope, or skip caching retrieved context above a sensitivity threshold.

What Actually Happens With Filtered ANN in PostgreSQL?

Most articles describe pre-filtering as if the vector index walks only authorized rows. It does not, at least not in pgvector. The pgvector documentation on filtering is explicit that with approximate indexes, the filter is applied after the index scan. The consequence is arithmetic: if a filter matches 10 percent of rows and hnsw.ef_search is at its default of 40, roughly 4 rows survive.

Photocopied funnel with a mesh screen holding back most items while a few pass into a tray, representing filtered approximate nearest neighbor recall

That is the failure that looks like a permissions bug and is actually a retrieval-quality bug. A junior employee asking a broad question gets four chunks from a pool that was computed before authorization, and the system either answers poorly or, worse, a service that treats low-recall as no-match falls back to an unfiltered path.

Three fixes, in order of how often I reach for them:

  • Iterative scans. Since pgvector 0.8.0, SET LOCAL hnsw.iterative_scan = relaxed_order keeps walking the graph until enough rows pass the filter, bounded by hnsw.max_scan_tuples (20,000 by default). strict_order preserves distance ordering at a cost. The IVFFlat equivalent is ivfflat.iterative_scan with ivfflat.max_probes.
  • Partial indexes. If you have a handful of large tenants rather than thousands of small ones, a partial index per tenant or per classification keeps the graph dense and skip the filter entirely.
  • Partitioning. Beyond a few million chunks, partition by tenant and index each partition, so the query only ever touches data the tenant could see.

If your product requires true filtered graph search at scale, that is a legitimate reason to evaluate a vector store that maintains filtered structures. It is not a reason to skip the filter in SQL and hope.

How Do You Keep Permissions Current After a Revocation?

The question that separates a demo from a system: a user loses access at 10:00. When does the chatbot stop answering from that document?

Group indirection handles membership changes. Promotions, transfers, and terminations change group membership in the identity provider. If chunks reference groups, those changes apply on the next query with no reindex. This is the single highest-leverage design decision in the whole build.

Webhooks handle document-level changes. SharePoint, Drive, and Box all emit permission-change events. Subscribe to them, update the matching chunk rows, and increment acl_version in the same transaction. A nightly crawl is not a revocation mechanism; it is a permission drift generator with a 24-hour window.

Photocopied pages each marked with a heavy black cross, connected by faint lines, representing a revocation propagating across indexed records

Deletion and legal hold need their own path. Deleting a document from the source system must remove or tombstone its chunks, and a deletion request under privacy regulation must reach the embedding too. That is a data lifecycle concern as much as a security one, and it is worth writing down before an auditor asks.

Set an explicit propagation budget. “Within one poll cycle” is not a budget. Pick a number, such as 5 minutes for document-level revocation and immediate for group membership, and test it.

The Five Tests I Run Before Calling It Safe

Pass criteria are behavioural, not architectural. A design document is not evidence.

  1. Restricted question, unprivileged account. Ask directly for known-restricted content. Expect a clean refusal or an answer built only from authorized documents, with no fragments of the restricted text. Check the audit log to confirm nothing was retrieved.
  2. Revocation within the propagation budget. Grant access, confirm retrieval works, revoke, then retry inside the window. If the second query still returns the document, the cache or the index is stale.
  3. Prompt injection aimed at the filter. Submit a document containing text that instructs the assistant to ignore restrictions or to call a tool with a wider scope. Expect the retrieval scope to stay bound to the session.
  4. Cache replay across principals. Ask user A a question that returns a sensitive chunk, then ask user B the same question. Expect a cache miss or a filtered result, never A’s context.
  5. Indirect phrasing. Ask about the restricted content without naming it: paraphrase, use a synonym, or ask a comparative question that only the restricted document answers. This catches filters that operate on the query string instead of the result set.

Log each test as a regression check in CI if the retrieval layer is code you own. The fifth test is the one that fails most often in my experience, because it targets the retrieval path rather than the interface.

What Should a Retrieval Audit Log Contain?

OWASP’s mitigation for this risk class includes maintaining detailed immutable logs of retrieval activity. A useful log answers three questions: who asked, what the filter was, and what the system withheld.

Field Why it matters
Timestamp, request ID, session ID Correlate with application traces
Authenticated principal and group set hash Prove the filter came from a session, not from input
Tenant, acl_version observed Detect stale reads
Query text hash, not the raw query Investigate without storing user content
Retrieved document IDs and classification Reconstruct what was disclosed
Suppressed counts by classification Detect over-restriction and starvation
Tool calls and arguments hash Catch confused-deputy attempts

Store the log append-only, separate from the application role that serves queries, and treat the retained document IDs as confidential. A log that says which executive documents a junior account retrieved is itself sensitive.

Five Failure Modes and Their Fixes

Symptom Real cause Fix
Chatbot answers questions about documents the user cannot open ACLs never ingested Capture group IDs at parse time, store per chunk
Revoked user still gets content for hours Nightly sync plus shared cache Webhook updates with acl_version bump, cache keyed by principal
Answer quality collapses for low-privilege users Filtered ANN returns a handful of candidates Iterative scans, partial indexes, or partitioning
Injection request returns a broader result set Filter accepted from model arguments Bind filter from session, refuse caller-supplied scopes
Security team finds document text in logs Retrieved context logged verbatim Log IDs and hashes, never chunk text

Conclusion

Permission leaks in RAG systems are not model failures. They are authorization failures in a system that happens to contain a model, and they get fixed the way any authorization bug gets fixed: identify the principal, bind the decision to that principal at the boundary, propagate changes, and test the boundary with hostile requests.

The uncomfortable part is that the vector index is easier to build than to audit, so the leak is discovered by the person who should not have seen the answer. Get the ACL into the chunk row, keep the filter out of the model’s hands, set a revocation budget you can defend, and run the five tests before anyone outside the team gets a login.

AI Architecture & Enterprise RAG Security

Building secure RAG knowledge systems for your enterprise?

Veduis works with mid-market engineering teams and enterprise IT leaders to design permission-aware vector search pipelines, audit LLM security, and protect sensitive business data.