Search & knowledge
Access Control Must Happen Before AI Generation
Protect private knowledge by enforcing authorization before retrieval context reaches a model, then rechecking access across citations, caches, and exports.
An AI assistant should answer only from information the current user is entitled to access. Telling a model not to reveal restricted documents is not an authorization mechanism. OWASP recommends denying access by default and checking permissions on requests. In a retrieval product, those checks must cover the evidence path before private material enters the model context.
Bind retrieval to trusted identity
Derive the user and organization from an authenticated server-side session. Do not accept an arbitrary tenant identifier from a prompt and use it to choose documents. Resolve document visibility using your application’s authorization rules, then apply the resulting scope to each retrieval path.
Check keyword search, vector search, previews, and related-document features independently. A filter on one path does not secure the others. If the search infrastructure cannot enforce the required policy directly, design a candidate validation stage that prevents unauthorized text from reaching generation. Account for recall and latency effects rather than silently weakening the policy.
Treat secondary surfaces as data access
Imagine a hypothetical agency portal with shared templates and confidential client project notes. Two employees ask the same question, but their authorized source sets differ. A shared answer cache keyed only by question text could return one employee’s private context to the other. Include the effective permission scope and relevant source versions in cache decisions.
The same principle applies to citations, conversation exports, debug tools, and administrative previews. Recheck access when opening a source, and decide what happens to saved answers after membership changes. Do not expose restricted document titles in a friendly no-results message. Even metadata can reveal information the user should not have.
Test with adversarial account pairs
Create test accounts with deliberately overlapping permissions: one shared document, one exclusive document for each account, and one revoked membership. Ask identical questions as both users. Assert on the retrieved text and reference metadata, not merely on whether the final answer looks safe.
Where database row security is used, test the actual application role. PostgreSQL documents that table owners and certain privileged roles can bypass row security. A policy that works in an isolated SQL example may therefore behave differently through a privileged production connection. Keep authorization tests close to the real request path and include background jobs that retrieve evidence.
