Search and Pagination Scoping
Verify search indexes, pagination cursors and sort operations never widen results past the caller's own scope
Use when: the API offers search, filtering, sorting or cursor-based pagination over shared data sets
Avoid when: results are a fixed single object with no list or query surface to review
Procedure
- Populate both test accounts with distinctive labeled records so leakage is visible in any result set.
- Run broad searches as each account, including wildcards and empty filters, and diff the result identifiers.
- Walk pagination to its end for both accounts, checking that page boundaries never expose another scope's records.
- Test sort and filter parameters, since query builders sometimes apply scope before filtering and sort after.
- Check whether cursors encode scope, and whether substituting another account's cursor returns their page.
- Record which layer applies the scope: index query, application filter or post-processing.
Signals
- A wildcard search returns another test account's labeled records.
- A cursor from one account produces results from the other when replayed.
- Sorting by a field changes which records appear, suggesting scope is applied after ordering.
- Deep pages contain records that the first pages correctly excluded.
Patterns
1. Search diff
query=* as alice -> 38 hits, as bob -> 55 hits
overlap contains BOB-* rows in alice's results -> finding
2. Cursor swap
cursor issued for alice replayed as bob -> returns alice's next page -> scope not encoded
3. Result row
endpoint=/api/search scope=applied-at=index leaked=0 cursor=bound-to-session
Pitfalls
- Testing only the first page, where filters are strongest and pagination is where they break.
- Using identical data for both accounts, making leakage invisible even if it occurs.
- Ignoring asynchronous index updates, where a record removed from one scope lingers in the index.
Done when
- Wildcard search, full pagination traversal and cursor substitution have been tested for both accounts.
- The layer applying scope is identified and any leak is attributed to a specific query or step.