Find the security flaw in how this multi-tenant RAG system enforces document permissions
Click any words you think contain an error. Click again to unmark.
Access control is enforced by a prompt line telling the model to ignore unauthorized chunks. That's broken — chunks already in context can leak. Filter on the user's ACL at retrieval so they're never fetched.
Imagine a librarian who pulls every book in the building onto your desk, including ones you're not allowed to see, then tells you 'don't read the ones you shouldn't.' The secret is already sitting in front of you — you might glance at it, or someone could trick you into reading it aloud. The safe way is for the librarian to check your library card first and only bring the books you're cleared for. In this code, the system grabs documents for everyone and asks the AI to politely look away. Real access control checks who you are before fetching, so forbidden documents never reach the desk at all.
Concept explanation~2 min read
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Concept explanation~2 min read
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
This snippet looks reasonable at a glance, which is exactly why it is a good interview trap. It retrieves context, it acknowledges that some chunks are off-limits, and it tells the model to respect that. The instinct is to nod along. The senior instinct is to notice the ordering: the forbidden data is fetched into the prompt first, and only then is the model asked to ignore it. By that point the security decision has already been lost.
The flaw is not a bug in one line; it is a category error about where authorization lives. Access control is a deterministic property a system must enforce, and this code delegates it to a probabilistic text generator via a polite request. This deep dive establishes why a prompt instruction can never be an access-control mechanism, enumerates the concrete leak paths, explains the retrieval-layer fix and why pre-filtering specifically matters, and ends on the general rule that an LLM must never be the enforcement point for a security boundary.
Why a prompt instruction is not access control
Access control has a precise meaning in security: a deterministic, enforceable, auditable decision about whether a principal may access a resource. Authentication establishes who you are; authorization decides what you may see. Both are properties the system guarantees, not behaviors it requests.
The code in question does neither. It fetches every chunk that matches the query across the whole index — for every user, regardless of tenant or ownership — and then appends a sentence: 'Ignore any chunk the user is not authorized to read.' That sentence is a request to a language model, and a language model is the wrong component to hold a security boundary for one reason above all: its output is probabilistic. There is no mechanism that forces it to honor a negative instruction, and no privileged status that makes your instruction outrank text inside the retrieved chunks.
The deeper framing is the confused deputy. The retrieval layer acts with full privilege — it can read everything — and then hands the authorization decision down to a component that should never have been trusted with it. The fix is not to word the request better. It is to move the decision back to a layer that can enforce it deterministically, before the privileged fetch ever returns forbidden data.
Situations where this technique stops working.
2–4 min · Everything important, quickly.
Real products, models, and research that use this idea.
- Multi-tenant enterprise RAG filters the vector index on the caller's groups so one tenant can never retrieve another's documents
- OWASP LLM Top 10 covers sensitive-information disclosure that prompt-level filtering fails to prevent
What an interviewer would ask next. Try answering before peeking at the approach.
QWhy is a pre-filter on the ACL safer than retrieving top-k and then dropping unauthorized results?
A post-filter runs the ANN search over all vectors, including forbidden ones, then removes the unauthorized hits — which under-fills top-k (you asked for 8, got back 3 authorized) and still computes over data the user can't see, with timing or count side channels. A pre-filter restricts the candidate set before scoring, so unauthorized vectors are never considered and top-k is filled from authorized documents only.
Red flags & common mistakes
The phrases that signal junior thinking. Click to expand.
Red flags & common mistakes
The phrases that signal junior thinking. Click to expand.
Trusting a prompt line like 'ignore unauthorized chunks' to enforce permissions, when the forbidden data is already in the context window and can leak.
60 second bullets to scan on the way to the call.
Why a prompt instruction cannot enforce access control
The three ways a forbidden chunk in context can still leak
Primary sources. Browse if you want the original framing.
Same topic, related formats. Practice these next.