Scrivio Interview library
ScenarioIntermediate7 min read · updated 12 November 2026

A RAG chatbot over internal documents started leaking salary data to employees who should not see it. Explain how this happened and how you fix the architecture.

The leak happened because the retriever ignored document permissions: all documents, including HR salary files, were indexed together, and any user's question could retrieve any chunk, which the model then quoted. The fix is to enforce access control at retrieval time, storing ACL metadata with every chunk and filtering the vector query by the user's groups, never relying on the model to withhold what it was given. We re-index with permission metadata, keep permissions in sync, test with users of different roles, and exclude some sensitive sources from AI use entirely.

Why this question is asked

This is one of the most damaging and most common mistakes in early RAG projects. The chatbot works beautifully in the demo, it is rolled out to all employees, and within weeks someone asks about the pay bands for their team and gets an answer quoting a confidential salary spreadsheet. Interviewers ask this scenario because it tests whether we understand where security belongs in an AI system: not in the prompt, and not in the model's good behaviour. In this answer, we will explain how the leak happened, why the model cannot be the safeguard, how to enforce permissions in retrieval, how to re-index and keep permissions current, how to test it, and when to exclude sources entirely.

1How the Leak Happened

A RAG chatbot answers questions by retrieving relevant chunks of documents from a vector store and putting them into the model's context. In the first version, the indexing job crawled the shared drives, the wiki and the HR folder with a service account that could read everything, split all documents into chunks, embedded them and stored them in one collection. The chunks kept their text and maybe a file name, but not who was allowed to read the original.

At question time, the retriever embedded the user's question and returned the closest chunks from the whole collection. When an engineer asked what the salary range is for a senior engineer in Berlin, the most similar chunks were, naturally, from the confidential compensation spreadsheet. The model did its job: it answered from the context it was given.

Step throughThe leak: retrieval ignores who is asking
EmployeeChatbot serviceVector storeModel
What do senior engineers in Berlin earn?
similarity search over ALL chunks
top chunks include hr/compensation-2026.xlsx
answer from these chunks
Senior engineers in Berlin earn 92,000 to 118,000 EUR...
confidential data shown to an unauthorized user

6 messages in order. Play them, or step through them one at a time.

The permission check that existed on the shared drive was lost during indexing.

2Why the Model Cannot Be the Safeguard

A tempting quick fix is to add a rule to the system prompt: do not reveal salary information. That does not work as a security control. The model has no idea who the user is or what they may see, it may still paraphrase or hint, and a determined user can often talk it into answering through a different framing, a direct or indirect prompt injection. The basic rule is simple: anything that reaches the model's context can end up in the answer.

So the only safe place to enforce permissions is before the context is built. If a user may not read a document, its chunks must never be retrieved for that user's question in the first place.

3Enforcing Access Control at Retrieval Time

The fix is to carry permissions from the source system into the vector store and filter on them in every query. During indexing, each chunk gets metadata describing who may read its source document, for example the list of groups from the document's access control list (ACL). At question time, the service looks up the authenticated user's groups from the identity provider and adds a metadata filter to the similarity search, so the vector store only considers chunks the user is allowed to read.

Java
// Indexing: every chunk carries the ACL of its source document
Document chunk = new Document(text, Map.of(
"source", "hr/compensation-2026.xlsx",
"acl_group", "hr-compensation")); // or a list of groups, if your store supports list filters
vectorStore.add(List.of(chunk));
// Querying: only chunks the current user may read are even considered
List<String> groups = identity.groupsOf(currentUser); // e.g. ["all-employees", "engineering"]
Filter.Expression allowed = new FilterExpressionBuilder()
.in("acl_group", groups.toArray())
.build();
List<Document> chunks = vectorStore.similaritySearch(SearchRequest.builder()
.query(question)
.topK(5)
.filterExpression(allowed)
.build()); // compensation chunks are never returned for this engineer

Notice that the filter is applied inside the vector query, not after it. Filtering after retrieving the top 5 would leave the engineer with fewer or no results, and a bug in post-filtering would leak again. How metadata filters work for list-valued fields differs between vector stores, so check your store's support; a common pattern is one entry per allowed group or a store that supports array containment.

4Re-indexing and Keeping Permissions in Sync

The existing index has no permission metadata, so it must be rebuilt, not patched. We take the chatbot offline or restrict it to a safe subset, delete the collection, and re-index from the source systems, reading each document's ACL at the same time as its content. The indexing service account still needs read access to everything it indexes, but it now records who else may read each document.

Permissions change all the time: people move teams, folders are reshared, documents are restricted after an incident. A nightly full re-index may be too slow to reflect a revocation, so we also listen for permission-change events from the source systems where available, or run frequent incremental syncs of ACLs. The longer the gap, the longer a removed user can still retrieve content, so the sync interval is a security decision, agreed with the security team.

Step throughFixed indexing and query path
  1. Read document and its ACL from the source
  2. Chunk, embed, store with acl metadata
  3. Sync permission changesevents or frequent incremental runs
  4. User asks a questionauthenticated, groups from identity provider
  5. Vector search filtered by user's groups
  6. Model answers only from permitted chunks

6 steps in order. Play them, or step through them one at a time.

5Testing With Users of Different Roles

Access control needs tests that act like the people who use the system. We create test users with different roles, an engineer, an HR partner, a manager, a contractor, and a set of questions that should and should not retrieve sensitive sources. Automated tests assert on the retrieved chunks, not the answer text: for the engineer, no chunk with a source under hr/ may appear, whatever the question. These tests run in CI against a test index and periodically against production with synthetic accounts.

We also add monitoring: log which sources were retrieved for each answer, without logging the sensitive text itself, and alert when chunks from sensitive classifications are retrieved for users outside the expected groups.

6Excluding Some Sources Entirely

Finally, not every source should be in a general employee chatbot, even with perfect ACLs. Salary data, performance reviews, medical leave records and legal case files carry such high risk that a single mistake in permission sync is unacceptable. We classify sources before indexing, and the highest classifications are excluded from AI indexing by default, or served only by a separate, narrowly scoped assistant for the HR team with its own controls. Excluding them reduces the damage any future bug can do.

7Follow-up questions

Should we also check permissions on the answer?

Yes, as a second layer: before returning the answer, the service can verify that every cited source is one the user may access, and refuse otherwise. This catches bugs in the filter, but it is a backstop; the main control is the retrieval filter.

What about the model provider seeing the salary data?

That is a separate question of data protection. Even with correct filtering, HR users' questions will send salary data to the model, so the provider must be approved for that data class, or the HR assistant must use a private deployment.

How do you handle documents shared with individual users rather than groups?

Store user identifiers in the ACL metadata as well, or resolve individual shares into a per-document list at index time. The query filter then includes the user's id together with their groups.

8Conclusion

In this answer, we saw that the salary leak happened because indexing dropped document permissions and retrieval searched all chunks for every user. The model cannot be a security control, because anything in its context can end up in the answer. The fix is to store ACL metadata with each chunk and filter the vector query by the user's groups, to re-index with permissions and keep them in sync with source systems, to test retrieval with users of different roles, and to exclude the most sensitive sources from AI use entirely.

What to say in the interviewAbout 90 seconds aloud

Open with

The leak happened in retrieval, not in the model. The indexing job read everything with a broad service account, including the HR folder, and stored all chunks in one collection without the original documents' permissions.

Then, if they want more

At question time the retriever searched all chunks, so a salary question pulled chunks from the compensation spreadsheet, and the model answered from what it was given.

Adding a prompt rule like do not reveal salaries is not a fix: the model does not know who the user is, and anything in its context can end up in the answer, including through prompt injection. The fix is to enforce access control at retrieval time.

When indexing, each chunk carries ACL metadata from its source, for example the groups allowed to read it; at query time we get the user's groups from the identity provider and add a metadata filter to the vector search itself, so forbidden chunks are never candidates.

That means a full re-index with permission metadata, plus syncing permission changes frequently or by events so revocations take effect quickly. I would test with synthetic users of different roles, asserting that no hr chunks are retrieved for an engineer, and monitor which sources are retrieved.

And some sources, like salaries and performance reviews, I would exclude from the general assistant entirely.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Official documentation
Spring AI reference
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "A RAG chatbot over internal documents started leaking salary data to employees who...": https://scrivio-interview-library.netlify.app/spring-boot/llm-fundamentals/66271079d8/