Skip to content
Hidden Logic Lab

Review object-level authorization on id-based handlers

Run on PRs where handlers load rows by primary key or opaque id. You build a route table with authorization predicates, block unscoped findById, and catch batch and nested reads that skip membership checks.

Copy prompt

Cursor, Claude Code · Coding · 40 min · Deep

Outcome

A PR comment route table (operation — id source — predicate — batch?), negative-test gaps called out, and no merge where swapping id returns another user's or tenant's row.

Steps

  1. 1

    Build the id-route table first

    Grep the diff for params.id, recordId, and :id routes before reading business logic. Missing one batch endpoint is how IDOR returns after merge.

  2. 2

    Run two sessions in integration tests

    User A creates a row; User B requests the same id. Paste test name and expected status into the PR comment.

  3. 3

    Map deletes separately

    Re-open the table for DELETE and PATCH only. A read-safe route with destructive IDOR is a common follow-up incident.

Copy prompt

The prompt to paste

Review this PR for object-level authorization (IDOR/BOLA): every handler that uses a resource id must prove the caller may access that instance.

Repository facts:
[API surface in diff: Route Handlers, tRPC, GraphQL, server actions — names only]
[session identity: user id, org id fields on session/JWT]
[ownership columns: user_id, organization_id, membership join tables]
[policy helpers: canAccess, authorize, assertMembership — file paths if they exist]
[RLS: yes/no; if yes, which role hits user-facing routes]

PR context:
[PR link or diff]

## Route inventory
Table every changed operation that accepts an id (path, query, body, GraphQL arg):
| operation | id source | data access pattern | auth predicate |

## Hard blocks
- Block findById / get({ where: { id } }) without tenant/owner/membership in the same query or a scoped helper.
- Block trusting client-supplied organizationId, userId, or tenantId in list/search without server-side membership check.
- Block batch DELETE/UPDATE/PATCH over id[] without WHERE scoped to session tenant or per-id authorize.
- Block GraphQL child resolvers that load by child id without parent authorization context.
- Block server actions that take recordId from FormData and write without re-checking access.
- Block presigned download/export URLs minted from object id alone without binding to current principal.
- If RLS is cited: Block user-facing code paths using a service role that bypasses RLS without equivalent app filter.

## List and search
- Quote WHERE clauses for list endpoints. Block fetch-all-then-filter-in-memory when the DB query could scope by tenant.
- Warn on check-then-act (read row then if owner) — note timing/log leakage; prefer single scoped query.

## Nested and destructive
- Comments, attachments, versions: child loads must include parent scope or inherit from authorized parent fetch.
- Review DELETE/PATCH separately from GET — tests that only cover read miss destructive IDOR.

## Tests
- Note negative tests: principal A requests principal B's synthetic id → expect 403/404 per team policy.
- Block new id routes with zero multi-principal tests unless ticket linked.

## Findings table
[Block | Warn | Note] operation — issue — one-line fix

## Merge recommendation
Rules:
- Authentication alone is insufficient — session presence is not a predicate.
- No scanning scripts, payload recipes, or production record ids.
- Complements postgres-rls-policy-review-skill-md and nextjs-middleware-auth-bypass-review-skill-md; does not replace them.

Unguessable UUIDs are not authorization. Block unscoped queries even when ids are random — automated tools and leaked ids still reach them.

Sample case written by Hidden Logic Lab. Not affiliated with Cursor or Claude Code.

Get new cases in your inbox

Weekly notes on new use cases and agent workflows. No product pitches.

Occasional notes on new cases. No product pitches in the first note.