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.
11 min readIntermediateCommon · estimateFacts checked 27 November 2026
Say it out loud
Read it once, then say it without looking. Start with the short one; use the long one when they ask you to go deeper.
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.
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.
Key words
- 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.
The permission check on every query
Employee asks
Signed in, so who they are is known
Read their groups
Server asks the identity system
Filtered search
Group filter runs in the query
Model writes answer
Sees only chunks that passed
Answer with page links
Only pages this person may open
- 1The question arrives with a signed-in user.
- 2The server looks up the user's groups, never taking them from the prompt.
- 3The search keeps only the chunks whose groups match.
- 4The 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.
Filter before or after the search
Post-filter (risky)
Top 2 of all chunks
Hidden chunks take up slots
Drop unreadable chunks
Removes them after ranking
Pre-filter (safer)
Drop unreadable chunks
Applied inside the query
Top 2 readable
Fills both slots when it can
Fewer than 2 results
Counts and ranks give hints away
2 readable results
Only chunks this user may read
- 1The search ranks every chunk, hidden ones included.
- 2Then the unreadable ones are removed, so fewer remain.
- 3The filter runs first, so only readable chunks get ranked.
- 4The 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.
# 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
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."
BetterRanking first lets hidden pages take slots and leak hints. Filter first, then rank.
Trap"The model knows not to show restricted pages."
BetterA prompt is not access control. Give the model only the chunks the user may read.
Trap"Hiding the field from results keeps it private."
BetterHiding 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?
Quick check
An HR analyst searches the wiki. Which fix keeps the board's pay plan out of the model's prompt?
Can you answer these from memory?
Flash cards · tap a card to flip it
What will they ask next?
Learn it in depth
Last updated on 27 November 2026
Building search over private company files?
I design and build AI search and agents with permissions checked inside the query, before ranking. Book a short call and tell me where your files live and who may see what.