Prompt
Building search into a portal with private records
Latest observation
When building search into a portal that includes private records, the main challenge is making search useful without exposing sensitive data. A good design usually combines access control, indexing strategy, query filtering, and auditing.
Core principles
1. Enforce authorization at query time
Search results should only include records the current user is allowed to see. This means:
- Every search query must be filtered by permissions
- Security should not rely on the UI hiding items
- Permission checks should happen in the backend, not just in the frontend
2. Index only what is safe to search
You may not want to index:
- Full private document bodies
- Sensitive fields like SSNs, account numbers, medical notes, etc.
Instead:
- Index metadata and non-sensitive text
- Redact or tokenize sensitive fields if they must be searchable
- Consider separate indexes for public vs. restricted content
3. Use field-level access control
If some users can view only part of a record:
- Store searchable fields separately
- Mark fields with sensitivity labels
- Return only permitted snippets or highlights
4. Protect search suggestions and autocomplete
Autocomplete can leak private data quickly.
- Restrict suggestions by user permissions
- Avoid showing raw sensitive terms
- Consider limiting suggestions to document titles or categories
5. Audit all search activity
Keep logs for:
- Queries issued
- Records returned
- Access denials
- Export actions
This helps with compliance and incident response.
Recommended architecture
Option A: Search filtered by ACLs in the search engine
Good when your search engine supports document-level security.
Each indexed document includes:
record_id- searchable fields
- access control list or visibility tags
At query time:
- User identity is passed to the search layer
- Search engine filters results based on ACLs
Pros:
- Fast
- Cleaner application code
Cons:
- More complex indexing and permission synchronization
Option B: Application-layer filtering after search
Search engine returns candidate matches, then your app filters them.
Pros:
- Simpler to start
Cons:
- Risky if not done carefully
- Less efficient
- Can leak relevance hints or snippets if filtering is incomplete
For private records, Option A is usually safer.
Security considerations
Prevent side-channel leaks
Even if records aren’t shown, metadata can leak:
- Result counts
- Facets
- Ranking differences
- “No results” vs “some results”
Mitigations:
- Suppress counts for unauthorized scopes
- Avoid facets on sensitive dimensions
- Normalize error messages
Encrypt sensitive data
If the portal stores highly sensitive records:
- Encrypt data at rest
- Use strong key management
- Consider field-level encryption for especially sensitive attributes
Minimize data exposure in logs
Search terms can themselves be sensitive.
- Don’t log raw queries unless necessary
- Mask or tokenize sensitive inputs
- Restrict who can access logs
UX recommendations
- Clearly indicate why some records may not appear
- Provide filters only for authorized data
- Use safe snippets, not full text previews
- Allow admins to manage permissions without rebuilding the index each time if possible
Practical implementation checklist
- Define data sensitivity levels
- Map each record/field to access roles or ACLs
- Decide what gets indexed
- Implement query-time authorization filtering
- Secure autocomplete and suggestions
- Audit search queries and result access
- Test with users of different permission levels
- Review for leakage via counts, snippets, and facets
If you want, I can also help you design this for a specific stack, like Elasticsearch/OpenSearch, SQL full-text search, or Azure Cognitive Search, or sketch a secure search architecture for your portal.