Prompt
Why is my permissions-aware search leaking docs I shouldn't see?
Latest observation
Oct 31, 2026
OpenAI APIWeb search: off
Most “permissions-aware” search leaks come from one of a few places where filtering and ranking happen in the wrong order or not on the same source of truth.
Common causes
-
You search first, filter later
- If the index returns top matches and you only apply ACL checks afterward, you can still leak:
- document titles/snippets
- IDs
- counts / total hits
- facets / aggregations
- Worse, if you paginate, you may expose “missing” docs indirectly.
- If the index returns top matches and you only apply ACL checks afterward, you can still leak:
-
ACLs are stale or denormalized
- Your search index may have old permissions.
- Example: doc was revoked, but the index still says user can see it.
- This is common when permissions are stored in a separate system and synced asynchronously.
-
Filtering on the wrong identity
- You may be using:
- user ID when you should use group/team/org memberships
- tenant ID incorrectly
- “role” claims from an untrusted token
- A small mismatch in auth context can open access.
- You may be using:
-
Partial permission expansion
- If access is based on group membership, but you only expand some groups:
- nested groups
- inherited roles
- dynamic teams
- sharing rules
- then the search filter may be incomplete.
- If access is based on group membership, but you only expand some groups:
-
Query cache or result cache is cross-user
- Cached search results reused across users without including auth context in the cache key.
- This can leak full result sets or snippets.
-
Aggregations/facets ignore ACLs
- Even if document hits are filtered, counts can reveal restricted docs exist.
- Examples:
- “12 docs in Project X” when user should only know 3
- terms facets that expose sensitive categories
-
Highlighting/snippets pulled from unfiltered docs
- Search engine generates highlighted text before permission enforcement.
- That can expose sensitive terms from unauthorized docs.
-
Multi-tenant boundaries are soft
- Missing tenant filter in one code path or one index alias.
- “Admin” or “superuser” paths may accidentally be used for normal users.
-
Race conditions
- Permissions changed between:
- indexing
- query time
- post-filtering
- The doc can slip through briefly.
- Permissions changed between:
-
Bad document-level security implementation
- Inverted index / ACL tokens not applied consistently.
- Example:
readers: [user123, groupA]but query only checksuser123.
How to diagnose quickly
-
Inspect one leaked doc and answer:
- Was it already in the index?
- Did the search engine return it, or did your app attach it later?
- Is the ACL field correct at query time?
- Are snippets/facets/counts leaking even if the doc itself is removed?
- Is the cache keyed by auth context?
-
Log the following for a test user:
- user/tenant ID
- group memberships used
- final search filter
- raw search hits before app filtering
- post-filter hits
- aggregations/facets returned
Safer patterns
- Enforce ACLs in the search layer, not only after retrieval.
- Include auth context in caches.
- Use a single authoritative permission model for both app and index.
- Index permission tokens carefully and reindex on permission changes.
- Hide counts/facets/highlights unless they’re also permission-filtered.
- Test with “negative” cases:
- revoked access
- group removal
- tenant boundary
- nested group membership
- stale index entries
If you want, I can help you debug this with your setup.
Send me:
- search engine (Elasticsearch/OpenSearch/Solr/DB/etc.)
- how ACLs are modeled
- whether you filter at query time or post-query
- an example query and an example leaked doc
and I can narrow down the likely leak path.