# Design Permission-Aware Search Over an Internal Wiki

> How to search a company wiki so people only see the pages they may read, why filtering after the search leaks, and how to build it, for your AI interview.

**In short:** Copy each page's access list onto every chunk, look up the user's groups on the server, and filter inside the search before it ranks. Filtering after the search returns fewer results and leaks hints about pages the user cannot open.

AI and LLM interview question Q375, LLM system design. Intermediate, common (our estimate). From Venkat R. Murty's free Interview Kit: https://designervenkat.online/interview/ai/design-permission-aware-search-over-an-internal-wiki

## Say it in 30 seconds

A wiki search has to respect who is asking. When I index a page, I copy its access list onto every chunk. At query time, the server looks up the user's groups and filters inside the search, before ranking. I never filter afterwards, because that returns too few results and leaks hints. I also plan for permission changes, with a sync budget (the longest a removed right may linger) and audit logs.

## Say it in 2 minutes

Picture a company wiki with HR pages, finance pages and executive drafts, all behind one search box. An HR analyst asks about salary bands. The closest match is a board document she must never see. So the search has to know who is asking, and the answer must come only from pages she may read.

My design has two parts. When a page is indexed, I copy its effective access list onto every chunk, including rights inherited from the parent page. At query time, my server looks up the user's groups from the identity system (the company's login directory), never from the prompt, and passes them as a filter inside the search. Only then does the search rank, and the model sees only what passed.

The mistake to avoid is post-filtering: ranking everything, then dropping the restricted results. It returns fewer answers, and counts, scores and timing can reveal that hidden pages exist. OWASP's 2026 guidance says to enforce scoping inside the index query and validate it server-side.

Then I plan for change. A person who leaves a group must lose access quickly, so I set a sync budget, re-check the top results against live permissions, and log every retrieval. Snippets, autocomplete and caches must follow the same rules.

## What is permission-aware search, in plain words?

Search finds the right page for a question. Permission-aware search finds it only among the pages the person asking may read. The search must know who is asking, and it must hide everything else before it ranks.

Think of a hospital records desk. The clerk knows where every chart is, but hands over only the files the nurse on that ward is cleared to see, even when a restricted chart is the closest match. Search over a company wiki works the same way.

A real case: a mid-size firm keeps HR, finance and executive pages in one wiki. An HR analyst asks "What are our salary bands for engineers?" The closest page is the board's bonus plan, which she must not see.

- **Access list (ACL):** The names of the groups or people allowed to read a page or chunk.
- **Chunk:** A short piece of a page. The search finds chunks, and the model reads them.
- **Group:** A set of people, such as HR or finance, that access rules are written for.
- **Pre-filter:** Applying the access rule inside the search, before it ranks results.
- **Post-filter:** Ranking first, then dropping results the user may not read. Unsafe.

## How does the permission check work?

Two moments matter: indexing, when a page is stored, and querying, when someone searches. Copy the access list at indexing, check it at querying, and never trust the prompt to say who the user is.

> "Your application must authenticate users, obtain trusted principal and grant values, apply filters to every query, and prevent bypasses" (Microsoft, Foundry IQ (Azure AI Search))
>
> "The principal is just a string, used in a filter expression, to include or exclude a document from the search results" (Microsoft, Foundry IQ (Azure AI Search))

Microsoft's Foundry IQ (Azure AI Search) docs describe a filter for the case where the search cannot use its built-in access lists. The filter trims results by a string that names a group or a user. The string is only a label. Your app has to prove who the user is before it applies the filter.

*Diagram, The permission check on every query: Every question passes the same four steps. The server supplies the groups, and the filter runs before ranking. The model never sees a page the user cannot open.*
1. The question arrives with a signed-in user.
2. The server looks up the user's groups, never taking them from the prompt.
3. The search keeps only the chunks whose groups match.
4. The model writes from those chunks, and the answer links to its pages.

1. **Copy access at indexing:** When a page is stored, copy its effective access list, including rights inherited from parent pages, onto every chunk. A mostly open page can hold a restricted paragraph.
2. **Read the groups on the server:** Ask the identity system which groups the signed-in user belongs to. Never let the browser or the user type them.
3. **Filter inside the search:** Add the group filter to every query, so the search ranks only readable chunks. One route without the filter is enough to leak the page.
4. **Limit what the model sees:** Pass the model only the chunks that passed. It cannot leak what it never received.
5. **Log what came back:** Keep an audit trail (a log of who searched) and the ID of each chunk returned (its label in the index), so a leak can be traced.

Two limits to name in the interview. Microsoft's docs say a permission field is not proof of access, because a field name or a document key proves nothing about grants. And a user in a very large number of groups needs the list split up. The same Microsoft page points to its Limits of search.in page for how to do it.

## Why does filtering after the search leak?

Post-filtering looks easy: search the whole wiki, then remove the restricted hits. It fails in two ways. It returns fewer results than you asked for. And the gap, plus result counts, scores and timing, tells the user that hidden pages exist.

*Diagram, Filter before or after the search: Both paths use the same two steps in a different order. Ranking first lets hidden pages take slots and leave gaps. Filtering first ranks only what the user can read.*
1. The search ranks every chunk, hidden ones included.
2. Then the unreadable ones are removed, so fewer remain.
3. The filter runs first, so only readable chunks get ranked.
4. The full set of readable results comes back.

Here is a small, made-up run. Six chunks, a user in the all-staff and HR groups, and two results asked for. The code is standard Python, and the scores are invented for the example.

```python
# A made-up wiki: each chunk has its similarity score for one question and the groups allowed to read it.
CHUNKS = [
    ("Board pay bands and bonus pool, FY27", 0.90, {"finance-leads"}),
    ("Salary bands for engineers, L3 to L6", 0.89, {"hr"}),
    ("Q3 layoff planning notes (draft)", 0.83, {"exec"}),
    ("Pay review calendar for managers", 0.55, {"hr"}),
    ("Expense policy: meals up to 40 USD", 0.20, {"all-staff"}),
    ("Office wifi reset steps", 0.04, {"all-staff"}),
]
USER_GROUPS = {"all-staff", "hr"}
K = 2

def can_read(chunk):
    return bool(chunk[2] & USER_GROUPS)

def post_filter(k):
    # Rank everything first, then drop what the user may not read.
    top = sorted(CHUNKS, key=lambda c: -c[1])[:k]
    return [c[0] for c in top if can_read(c)]

def pre_filter(k):
    # Drop what the user may not read inside the search, then rank the rest.
    readable = sorted((c for c in CHUNKS if can_read(c)), key=lambda c: -c[1])
    return [c[0] for c in readable[:k]]

post, pre = post_filter(K), pre_filter(K)
print("Post-filter returns", len(post), "of", K, "->", "; ".join(post))
print("Pre-filter returns", len(pre), "of", K, "->", "; ".join(pre))
```

Output:

```text
Post-filter returns 1 of 2 -> Salary bands for engineers, L3 to L6
Pre-filter returns 2 of 2 -> Salary bands for engineers, L3 to L6; Pay review calendar for managers
```

The post-filter returns one page where two were asked for. The restricted board page took a slot in the ranking, so the HR user gets less, and the gap hints that a closer restricted match exists. The pre-filter returns two readable pages, because it ranks only what she may read.

> "The attack succeeds even when every document is correctly tagged and every API call authenticated, because the access-control decision happens after the embedding-space search has run" (OWASP, LLM09:2026)
>
> "Enforce tenant scoping inside the index query, not as a post-retrieval filter, and validate it server-side" (OWASP, LLM09:2026)

OWASP's example is about separate customers sharing one index. In our reading, the same logic applies to groups inside one company, because the access check still runs after the search. Its 2026 list covers this under vector and embedding weaknesses, item LLM09. The attacker in its example does not need to open a document. They infer one from result counts, score distributions and timing.

> **Tip:** Asked whether post-filtering is ever acceptable? Say no for restricted data.

## What else can leak, and what happens when access changes?

Documents are not the only thing that leaks. Snippets, autocomplete, result counts and shared caches can all reveal a restricted page, so each needs the same rules.

- **Snippets and summaries:** Built only from chunks that passed the filter.
- **Autocomplete:** Built from titles the user can read, or it leaks restricted titles.
- **Caches:** Key them on the question and the user's permission set, never on the question alone.
- **Counts:** Never show totals across all pages, because a total reveals hidden ones.

Access also changes. Someone who leaves a group can keep old results until the next sync. So I set a sync budget for how long a revoked right may last, re-check the top results against live permissions before showing them, and test with planted restricted pages that must never come back.

## What does the interviewer want to hear?

**A strong answer covers**

- [ ] A clear rule: search returns only what the asker may read.
- [ ] Filter inside the query, before ranking, never after.
- [ ] Groups come from the server's identity system, not the prompt.
- [ ] Access copied onto every chunk, with inheritance and sync.
- [ ] Side leaks covered: snippets, autocomplete, counts and caches.
- [ ] Tests with planted restricted pages, and audit logs.

**Common traps**

- Trap: "We just filter the results after the search." Better: Ranking first lets hidden pages take slots and leak hints. Filter first, then rank.
- Trap: "The model knows not to show restricted pages." Better: A prompt is not access control. Give the model only the chunks the user may read.
- Trap: "Hiding the field from results keeps it private." Better: Hiding a field from results is not security. The filter in the query is the control.

## Can you spot the safe search call?

**Spot the safe call:** An HR analyst asks the wiki a question. Which search call is safe?

A. const hits = (await index.search(q, { top: 10 })).filter(canRead);
B. index.search(q, { top: 10, filter: groupFilter(await identity.groupsFor(session.userId)) });
C. index.search(q, { top: 10, filter: groupFilter(req.body.groups) });
D. index.search(q, { top: 10 }); // the system prompt says to show only HR pages

**Answer:** B. Option B reads the groups on the server and filters inside the query, before ranking. A filters after ranking and leaks gaps, C trusts groups the browser sends, and D relies on a prompt.

**Quick check:** An HR analyst searches the wiki. Which fix keeps the board's pay plan out of the model's prompt?

A. Add a line to the system prompt saying never to show restricted pages
B. Filter by the user's groups inside the search, before ranking
C. Hide the board page's title from the search results
D. Switch to a bigger model that follows rules better

**Answer:** B. Only a filter in the query, built from groups the server reads, keeps the page out of ranking and out of the prompt. Prompts can be talked around, and hiding a title is not access control.

## Can you answer these from memory?

**Flash cards**

- **What is permission-aware search?** Search that returns only the pages the asking person may read.
- **Where should the group filter run?** Inside the search query, before ranking. Never after.
- **Where do the user's groups come from?** The server's identity system, never the prompt or the browser.
- **What is the risk of post-filtering?** Fewer results than asked, and gaps that hint at hidden pages.
- **Where else can restricted data leak?** Snippets, autocomplete, result counts and caches not keyed by permission.
- **What does a permission change need?** A sync budget, re-checks on top results, and audit logs.

## Likely follow-up questions

- Q140 How do you enforce access control in RAG? https://designervenkat.online/interview/ai/how-do-you-enforce-access-control-in-rag
- Q148 What are vector and embedding security weaknesses? https://designervenkat.online/interview/ai/what-are-vector-and-embedding-security-weaknesses
- Q352 Design a work copilot that never leaks data the user can't access. https://designervenkat.online/interview/ai/design-a-work-copilot-that-respects-permissions
- Q354 What are the multi-tenant concerns? https://designervenkat.online/interview/ai/what-are-the-multi-tenant-concerns
- Q364 Security architecture for LLM apps? https://designervenkat.online/interview/ai/security-architecture-for-llm-apps

## Learn it in depth

- [RAG & Dynamic Filters](https://designervenkat.online/learn/ai-engineering/rag-and-dynamic-filters)
- [Unauthorized access](https://designervenkat.online/learn/ai-guardrails/unauthorized-access)
