A retrieval ranker answers one question: which text best matches this query? Whether the person asking may read that text is a different question, and no similarity score contains it. In my synthetic lab, a retriever with no permission check had the best relevance score of every design I tried (NDCG@5 of 0.939), and 51.5 percent of the chunks it returned were ones the caller could not read. 91.3 percent of asks had at least one. Every design that checked permissions scored lower on relevance, between 0.547 and 0.691. If your eval reports relevance alone, it ranks the leaky system first.
Defensive security research. Every document, user and permission in this lab is synthetic and fictional, and it ran on a local machine with no third-party infrastructure. The numbers show a mechanism, not the behavior of any production system.
The fix is to measure the second question on purpose: a leak rate, and an NDCG that scores an unreadable document as worth nothing. Gate the release on the first being zero.
I got to this from an essay in The AI Collective’s newsletter, “The Governance Layer Nobody Regulates,” by Karthik Chandrasekaran. He argues that enterprise AI safety is decided at retrieval, and that teams who measure only relevance with NDCG while ignoring authorization build an “impressively wrong system.” I took that line as a testable claim and ran it. The numbers below are mine, and the sources I checked are at the end. This post is the measurement half. The mechanism half, how a stale index copy of permissions leaks after the source changes, is in The Index Remembers What the Source Forgot.
Why does a relevance score reward the retriever that leaks?
Because the judgments are written without a caller in mind. To compute NDCG you need a list of which documents are relevant to each query and a score for how well a system’s top results match that list. Nobody asks whether the person typing the query may read the relevant documents. The ideal ranking is built from every document in the corpus.
So a system that happily returns documents the user cannot read gets full credit for finding them. A system that correctly withholds them is graded as if it had failed to find them.
On a test floor you report yield and escapes together. A station that reports only throughput gets promoted by accident, because the units it never inspected look like fast units. A RAG eval that reports only relevance is the same station.
What should I measure instead?
Four numbers per design, per ask (one user asking one question):
- Leaked chunk rate. Of the chunks returned, the share the source says the caller may not read.
- Asks with a leak. The share of asks with at least one such chunk. This one is closer to what a user experiences.
- Results returned. Post-filtering can quietly hand users two answers when you promised five.
- Authorization-aware NDCG@5. A returned document the caller may not read earns zero gain, and the ideal ranking comes only from documents the caller may read.
Here is the core of it, trimmed from the lab’s rag_eval.py:
# relevance-only: ideal ranking over the whole corpus
all_g = sorted((rel(qi, d) for d in docs), reverse=True)[:K]
ndcg_rel = dcg([rel(qi, docs[di]) for di in out]) / dcg(all_g)
# authorization-aware: an unreadable hit earns nothing, ideal over what the caller may read
perm_g = sorted((rel(qi, d) for d in docs if allowed(groups[u], acl[d["id"]])), reverse=True)[:K]
ndcg_auth = dcg([rel(qi, docs[di]) if ok else 0 for di, ok in zip(out, oks)]) / dcg(perm_g)
leaked = sum(1 for ok in oks if not ok)
The lab is synthetic from end to end: 240 generated documents on 24 topics, 12 users with group memberships, 72 questions, 864 asks in all. Relevance judgments come from the generator, not from people: 2 for a document on the query’s topic, 1 for another document from the same department, 0 otherwise. Embeddings are BAAI/bge-small-en-v1.5 through fastembed, search is exact cosine over numpy, and every ask returns up to five chunks. That makes the numbers a demonstration of a mechanism. They are not a benchmark.
What do the numbers look like?
This is the no-drift case, where the permission data is correct, so the only variable is whether and where the retriever checks it:
| Design | Results per ask | Leaked chunks | Asks with a leak | NDCG@5, relevance only | NDCG@5, authorization-aware |
|---|---|---|---|---|---|
| No permission check | 5.00 | 51.5% | 91.3% | 0.939 | 0.523 |
| Filter first, then top 5 | 5.00 | 0% | 0% | 0.691 | 0.780 |
| Top 20, filter, keep 5 | 4.89 | 0% | 0% | 0.688 | 0.776 |
| Top 5, then filter | 2.42 | 0% | 0% | 0.547 | 0.614 |
Read the two NDCG columns against each other. On relevance alone, the unchecked retriever wins by a wide margin, 0.939 against 0.691. On the authorization-aware version it comes last among designs that return five, 0.523 against 0.780. Same results, same lab, opposite ranking, because the second column stops crediting documents the user was never allowed to have.
The first column’s gap is partly real and partly the metric. Filtering does cost something. A caller who may read three on-topic documents has only three to give, and the other slots are filled with same-department material. But part of that 0.248 drop is the relevance-only metric counting unreadable documents as available gains. This is the quantified version of the essay’s line that a slightly less helpful answer beats a leaked one. The filtered design is less helpful on one scoreboard and better on the other, 0.780 against 0.523.
Why does “top 5, then filter” starve the user? Because the top five for an ordinary question is mostly material from that topic’s department, and most users are not in that department. In the unfiltered run, 51.5 percent of chunks belonged to someone else, so about half the slots are gone before any filtering. For a user whose only group is everyone, in the drift scenario from the first post, the same design returned 1.67 results per ask, and the unchecked retriever leaked 66.7 percent of its chunks into 100 percent of that user’s asks.
Should I filter before or after the top-k search?
Before, if the index can do it. A pre-filter returned all five results with no leaks. If your index cannot filter on the caller’s permissions, over-fetch: take the top 20, check each hit, and keep five. That recovered 4.89 of 5 results per ask. Retrieving exactly five and dropping what fails is the one design that visibly degrades, and it is also the one that looks safest in a code review.
Two caveats on what this shows. The check in the lab reads fresh permissions every time, so “filter” here means filtering against the truth. If the filter uses a copy of the permissions made at ingestion, it will leak after the source changes, as the first post measured. And the lab’s 20 is arbitrary. Pick your over-fetch from the drop rate you actually see in your own logs.
How do I put a leak gate in CI?
You need two things: an oracle for “may this user read this chunk” and a set of asks that exercises the boundary.
- The oracle. The source system’s own permission check, called from the test harness. Not the index’s copy, which is the thing under test.
- The asks. Real questions run as users with different memberships: someone with everything, someone with only the all-staff group, someone who lost a group last week. Add planted canary documents, restricted records with a unique token in the text, and assert that the token never appears in what an unauthorized user’s session gets back.
- The gate. Leaked chunk rate must be zero. Do not trade it against relevance. A relevance regression is a ticket. A leak is a stop.
Score authorization-aware NDCG next to relevance on every run, so a change that raises one and sinks the other shows up in the same table. The same habit applies to agents generally: measure the whole task and not each call, as in Every Call Passed and Nothing Got Done, and treat a green number from an instrument you have not checked with suspicion. For agent behavior over many steps, trajectory evals are the place to add a leak assertion. At the call boundary, agent action verification is the binary-check version of the same idea.
Where does the gateway fit in the measurement?
A gateway sees traffic, not relevance. It can log every retrieval tool call with the caller’s identity, which gives you the audit trail OWASP asks for, and it can reject or mask content on a tool call with tool-call guardrails or response guardrails. It cannot tell you whether a returned chunk was one the caller was entitled to. Only the oracle can, which is why the leak gate belongs in the retrieval service’s tests.
What do OWASP and NIST say to measure?
I did not find a retrieval leak metric in either.
- OWASP LLM08:2025, Vector and Embedding Weaknesses. Lists “Unauthorized Access & Data Leakage” as a common risk, and its first mitigation is “fine-grained access controls and permission-aware vector and embedding stores”. It also recommends “detailed immutable logs of retrieval activities”. It gives no measurement.
- OWASP LLM02:2025, Sensitive Information Disclosure, is the risk list entry for what happens if the chunk gets through to the answer. The index of the 2025 list puts it second, behind Prompt Injection.
- NIST AI 600-1 (July 2024) suggests testing data and content flows inside a generative AI system (MP-2.1-002) and periodic monitoring of generated content for privacy risks and sensitive data exposure (MP-4.1-001). A leak rate measured against the source’s permissions is one way to meet both. The profile does not specify one, and it is voluntary guidance.
- EU AI Act high-risk systems carry data governance duties under Article 10 and cybersecurity duties under Article 15, with the dates moved by Regulation (EU) 2026/1744 to 2 December 2027 for the Annex III list (legislative train). I read those two articles and the timeline, not the whole Act, and I did not find a retrieval metric in them.
So the metric is yours to define. This one is cheap, and it is only a few lines on top of the relevance eval you probably already run.
What did I not test?
- A real corpus or real judgments. Synthetic documents, generator-written relevance grades, one embedding model, exact search. Approximate indexes add recall noise on top.
- Graded sensitivity. A document is readable or it is not. Real systems have redaction, field-level rules and partial summaries.
- Answer quality. I measured retrieval, not what a model does with it. A leaked chunk is a leak whether or not the answer quotes it, but I did not run a model.
- Latency. The permission check in the lab is a dictionary lookup.
- Prompt injection through retrieved text. A separate failure. See the MCP tool poisoning post.
Run it yourself
The lab is under /lab/rag-authz/, with the generator, the evaluation, and captured output in evidence/eval_output.txt.
python3 -m venv .venv && . .venv/bin/activate
pip install -r requirements.txt
python corpus.py && python rag_eval.py
Change the corpus to look like yours, then check whether the ranking of designs survives. If it does not, that is the more interesting post.
Sources
- Karthik Chandrasekaran, “The Governance Layer Nobody Regulates”, The AI Collective Newsletter, 17 November 2026 (premise and the NDCG remark).
- OWASP GenAI Security Project, LLM Top 10 for 2025 and LLM08:2025.
- NIST, AI 600-1, Generative AI Profile, July 2024.
- European Union, AI Act Article 10 and Article 15; European Parliament, Digital Omnibus on AI.