Checking access at every hop
Step 1 · The pattern
Sign in, then ask for your order
Alice opens her order: the app calls GET /orders/1043. The gateway checks she is signed in, the orders service reads order 1043, and she sees it. (All numbers are illustrative.)
- a request
- her own order
In short
Checking access at every hop: how it works and how it breaks
Authentication answers 'who is this?'; authorisation answers 'may they see this record?'. Many APIs check the first at the gateway and forget the second: a signed-in user asks for /orders/1043, and the API fetches order 1043, whoever owns it. Change the number and you see a stranger's order. Sequential IDs make it trivial to walk through every record, but random IDs only hide the hole; the fix is a check on every request, where the data is read, that the record belongs to the caller (or that the caller's role allows it). Put it in the query itself (WHERE id = ? AND owner_id = ?) or in one shared access layer, test it with two users, and return 'not found' rather than 'forbidden' so the response does not confirm the record exists. OWASP ranks this the most common API security flaw.
What this simulation simplifies
- The second user's requests are scripted; real scraping loops through numbers far faster.
- Roles such as support staff, who may see other people's orders, are left out.
How this comes up in interviews
"How do you make sure users can only see their own data in a multi-tenant API?"
Then they ask
- Where does the check live?
- Are random IDs enough?
- How do you test it?
A strong answer covers
- Authentication at the edge; authorisation where the data is read.
- Scope every query by owner or tenant, ideally by default in one data-access layer.
- Random IDs hide the hole but do not close it.
- Return not found for other people's records.
- Automated tests with two users for every endpoint.
Points to cover, not a script. Say them in your own words and tie them to a system you have worked on.
On one page: the track cheat sheet.
Sources: OWASP API Security Top 10 (2023): API1 Broken Object Level Authorization ↗ · US SEC: Order in the matter of First American Financial (Release 34-92176) ↗ · Report a problem
Diagrams are our own simulations: the timings, rates and counts in them are illustrative, not measurements. Captions are original wording.