Test API authorization: can user B read user A's data?
Authentication asks "who are you?". Authorization asks "may you touch this?". Most APIs get the first right and slip on the second: GET /invoices/1842 checks that the token is valid, but not that invoice 1842 belongs to the caller. Change the ID, read someone else's data. It tops the OWASP API Security list as Broken Object Level Authorization (BOLA), and it's easy to test once you set up two users.
Set up two users
Add both tokens to the environment as secret variables:
| Variable | Value |
|---|---|
tokenA | user A's token (account 1) |
tokenB | user B's token (account 2) |
Use users in different accounts or organizations. Two users in the same team may legitimately share data, which hides the bug you're looking for.
Make an object as A
POST {{baseUrl}}/invoices
Authorization: Bearer {{tokenA}}
Content-Type: application/json
{ "customer": "ACME", "amount": 1200 }pm.test('A created an invoice', () => pm.response.to.have.status(201));
pm.environment.set('invoiceIdA', pm.response.json().id);Touch it as B
Put the attacks in a folder whose auth is Bearer {{tokenB}}, so every request inherits user B. Then one request per operation:
GET {{baseUrl}}/invoices/{{invoiceIdA}}
PATCH {{baseUrl}}/invoices/{{invoiceIdA}} { "amount": 1 }
DELETE {{baseUrl}}/invoices/{{invoiceIdA}}
GET {{baseUrl}}/invoices/{{invoiceIdA}}/pdf
POST {{baseUrl}}/invoices/{{invoiceIdA}}/sendPut one test in the folder's post-response script, so every request in it checks the same thing:
pm.test('B is refused', () => {
pm.expect(pm.response.code).to.be.oneOf([403, 404]);
});404 is often the better answer: it doesn't confirm the object exists. Pick one for your API and assert it exactly once you've decided.
Then prove it's still there
The DELETE as B must not have deleted anything. Finish with A:
// GET {{baseUrl}}/invoices/{{invoiceIdA}} with tokenA
pm.test('A still has the invoice, unchanged', () => {
pm.response.to.have.status(200);
pm.expect(pm.response.json().amount).to.equal(1200);
});A 403 on the PATCH means nothing if the amount changed anyway.
Places the bug hides
- Lists and search.
GET /invoices?customerId=...with A's customer ID, as B. The list should be empty or refused, not A's invoices. - IDs in the body.
POST /payments { "invoiceId": "{{invoiceIdA}}" }as B. Checks on path parameters often don't run on body fields. - Nested resources.
/accounts/{{accountIdB}}/invoices/{{invoiceIdA}}: B's own account in the path, A's invoice at the end. - Other methods. GET is checked, PUT was added later and isn't.
- Exports and files. PDF, CSV and attachment URLs are frequently served by a different handler.
- Function-level checks. A regular user calling admin endpoints:
/admin/users,?role=adminin a body,"isAdmin": trueon profile update.
Keep it in CI
Once the folder exists, it costs nothing to run on every build:
requestarium run-collection "Invoices API" --folder "Authorization" --env Staging --junit authz.xmlNew endpoint? Add one request to the folder. The folder test does the rest.