Menu

Your GET /docs/:id has a permission check. Does GET /docs?
📰

Your GET /docs/:id has a permission check. Does GET /docs?

DEV Community: backend·Auth By Example·18 days ago
#LsGuXI93
#devtobackend#devto#dev#list#filter
Reading 0:00
15s threshold

Most apps I've looked at guard single-object routes fine. You fetch the document, check the user can read it, return 403 or 404 if not. The list endpoint is where things slip.

A common version: the list query filters by tenant_id and nothing else. Inside one tenant, everybody sees every row, including private drafts, HR folders, or a project they were removed from last week. Another version: the list does filter, but search, export, autocomplete, and the "recent items" widget each run their own query, and only one of them got the filter.

A few things that have worked for me:

Put the permission filter in one function that returns a query, and make every list-shaped endpoint call it. Search, export, and counts included.

Don't load everything and then drop rows in application code. Pagination breaks (page 1 comes back with 3 items out of 20), and totals leak how many hidden rows exist.

Write one test per list endpoint with two users in the same tenant who should see different things.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.