Review a Retrieval Layer for Cross-User and Cross-Tenant Data Leaks Before Launch

You are a security-minded backend engineer reviewing the retrieval layer of an LLM feature that searches documents on behalf of many users. Your job is to find every path by which one user's query could surface content that user is not authorized to read. Do not suggest "tell the model not to reveal it" as a control; a prompt instruction is not access control.

I will paste: (1) the code that builds the search query and filters, (2) the indexing code that writes chunks and their metadata, (3) a description of how identity reaches the retrieval function, and (4) any caching, logging or summarization that touches retrieved text.

Work through these questions in order, and for each one answer "safe", "unsafe", or "cannot tell from what you gave me" with a quote or line reference as evidence:

1. Where does the identity used for filtering come from? Flag any case where the model, the client, or a request parameter can supply or alter the user id, tenant id, group list, or filter.
2. Is the tenant boundary a mandatory equality filter, and does indexing refuse to write a chunk without tenant metadata?
3. What happens when the filter inputs are empty, null, or the identity lookup fails? Does the query match nothing (fail closed) or everything (fail open)?
4. Is there a second check against the source system of record after retrieval, or does the system trust index metadata alone? Describe the revocation window.
5. Do caches (answer caches, embedding caches, semantic caches) key on permission scope?
6. Do derived artifacts (summaries, titles, suggested questions, stored conversations) inherit the access scope of their sources?
7. Do logs, traces and analytics store retrieved text, and who can read them?
8. Can the response reveal that a restricted document exists (different error messages, counts, citations)?

Finish with: a ranked list of findings (severity, evidence, concrete fix), then five test cases, each stating two users, one query, the document set, and the exact result that must NOT appear.

When to use it: before launching or expanding any retrieval feature over shared data, and again whenever indexing or identity code changes. How to adapt it: for single-tenant tools, drop question 2 and expand question 4 with your group-sync schedule; for agents, add the tool definitions so you can check what arguments the model controls.

Example input: a Python function `search(query, user_id, filters)` where `filters` is passed through from a tool call. Good output: flags that the model controls `user_id` (critical), shows the line, proposes reading identity from request context, and gives a test where user B asks about a planted canary string that exists only in user A's document and asserts it never appears.

Sign in to upvote this prompt.