QA Interview Hub · Knowledge base · Quizzes · Українська

API › The most critical API bugs

Access and authorization: BOLA/IDOR, tokens, mass assignment

BOLA/IDOR is when an authenticated user gets someone else's object by swapping its id, because the server checked the token but not who owns the resource. It is visible only with two accounts: B creates the resource and A requests it, covering every method and neighbouring address. Token revocation and mass assignment are checked the same way, by reading the state after the request, not just the status.

API · Typical bugs

The token is valid, and the server returned another user’s invoice. Which test catches it?

User A opens their own invoice GET /v1/invoices/10441, changes the number in the address to 10442 and gets user B’s invoice. The request is authenticated, the token is genuine, the status is 200. A test “a signed-in user sees an invoice” is green, while production leaks other people’s data. This class of bug is the most expensive because it hands out someone else’s data or extra rights, and it stays invisible until you use two users.

The lesson covers three bugs: access to someone else’s object (BOLA/IDOR), tokens that do not die, and mass assignment. For each: how it works, how to reproduce it, what to do next.

How it works

Authentication answers “who are you”, authorization answers “what are you allowed to do”. A server that checks only the token signature did the first half. In the OWASP API Security Top 10 (2023 edition) these are the top entries: API1 Broken Object Level Authorization (BOLA, called IDOR in older terminology), API2 Broken Authentication and API3 Broken Object Property Level Authorization, which absorbed mass assignment.

Why it happens. The owner check is not part of the protocol, it has to be written in every handler: “the resource belongs to the user from the token”. The framework does not know that. A developer adds it where security came to mind and forgets the neighbouring method, an export or a nested resource. So the bug lives in easy-to-miss places: PUT/DELETE while GET is protected, /invoices/{id}/pdf, /users/{id}/orders, ids in the body and query.

What the server checks in a request

Typical

Token only

The signature is valid, the token has not expired, the role allows the method. Whose invoice 10442 is, the server never asks.

Better

Token and owner

The same plus the condition “the resource belongs to the token’s subject” (or a role with rights over others). Otherwise 403 or 404.

Figure 1. The first check answers “who”, the second also “whose”. A BOLA bug is the missing second check.

Example: two accounts instead of one

The test needs two test users: B creates the resource and A accesses it. One account cannot reveal this bug by definition. We check all methods and neighbouring addresses, not only GET:

import { test, expect } from '@playwright/test';

// authA and authB hold the Authorization headers of two test accounts
test('A cannot read, change or delete the invoice of B', async ({ request }) => {
  const created = await request.post('/v1/invoices', {
    headers: authB,
    data: { amountMinor: 5000, currency: 'UAH' },
  });
  const { id } = await created.json();
  const url = '/v1/invoices/' + id;

  const attempts = [
    await request.get(url, { headers: authA }),
    await request.put(url, { headers: authA, data: { amountMinor: 1 } }),
    await request.delete(url, { headers: authA }),
    await request.get(url + '/pdf', { headers: authA }),
  ];
  for (const res of attempts) expect([403, 404]).toContain(res.status());

  const own = await request.get(url, { headers: authB });
  expect((await own.json()).amountMinor).toBe(5000); // B's data is untouched
});

Both 403 and 404 are allowed: neither gives out foreign data. The last lines matter: if PUT returned 403 but still changed the amount, the status dresses up the bug, so B’s state is checked with a separate read.

403 or 404 for a foreign resource

403 Forbidden

Says honestly that access is denied. But it confirms that the resource exists, which helps id enumeration.

404 Not Found

Does not reveal that a foreign resource exists. Diagnosis is a little harder, but it is safer for private data.

Figure 2. Both responses are acceptable if the contract is the same for all endpoints. The bug is mixed behaviour and a 200.

A token that does not die

The second group: a session stays valid after logout, a password change or blocking. A short-lived JWT access token lives until it expires by design, that is not a bug. The defect is a TTL that is too long, a refresh token that survives logout, and a token that can be exchanged twice. Under refresh token rotation practice (OAuth 2.0 Security BCP), reuse of an already exchanged token should be treated as a sign of theft, and the server revokes the whole token “family”. Real systems often allow a short tolerance window, so the test repeats the request after a pause longer than the window, not in the same millisecond:

test('an exchanged refresh token cannot be used again', async ({ request }) => {
  const { refreshToken } = await login(request, 'qa-a'); // helper of the suite
  const first = await request.post('/v1/auth/refresh', { data: { refreshToken } });
  expect(first.status()).toBe(200); // rotation: a new pair is issued
  await new Promise((r) => setTimeout(r, GRACE_MS + 1000)); // wait past the reuse tolerance window (GRACE_MS from the API docs)

  const reuse = await request.post('/v1/auth/refresh', { data: { refreshToken } });
  expect(reuse.status()).toBe(401); // the old token must be dead
});

Further cases: after logout the old refresh token does not work, after a password change other sessions are ended, after a role is removed the token does not grant the action (for a JWT it depends on whether the server checks the role from the token or from the database).

Mass assignment

The server maps the request body straight onto the model, and the client sets fields it should not: role, isAdmin, price, ownerId, status. A request from a regular user:

PATCH /v1/users/me HTTP/1.1
Authorization: Bearer <token of a regular user>
Content-Type: application/json

{ "displayName": "Olena", "role": "admin", "balanceMinor": 999999 }

The test does not stop at the status. 200 (field ignored), 400 or 422 (field rejected) are acceptable, only saving it is not. So we read the state after the request:

test('extra fields are rejected or ignored, never saved', async ({ request }) => {
  const res = await request.patch('/v1/users/me', {
    headers: authA,
    data: { displayName: 'Olena', role: 'admin', balanceMinor: 999999 },
  });
  expect([200, 400, 422]).toContain(res.status());

  const me = await (await request.get('/v1/users/me', { headers: authA })).json();
  expect(me.role).toBe('user');
  expect(me.balanceMinor).not.toBe(999999);
});

Extra fields come from GET responses (which fields a user sees) and from the documentation of privileged roles. The server-side fix is an allow list of fields, not a deny list of dangerous ones.

Limits and alternatives

  • An autotest with two accounts proves only the resources and methods it checked. Systematically this is covered by a “resource × method × role” matrix generated from the specification, or by a framework-level policy of “deny by default”.
  • Unpredictable ids (UUIDs) make enumeration harder but do not replace the owner check: ids leak through logs, emails and links.
  • A UI test on tokens catches little: signing out of the app may only make the browser forget the token while it stays valid on the server.
  • Do not enumerate other people’s ids in bulk and do not use rights you obtained. Two accounts of your own are enough as proof.

Common mistakes

  • Testing with one account. BOLA cannot be seen without another user’s resource.
  • Checking only GET. Change and delete often have separate handlers and a separate (missing) check.
  • Trusting the status, not the state. A 403 after the change was already saved leaves the hole open.
  • Treating token revocation as verified after a UI logout. The old token has to be replayed with a direct request.
  • Forgetting extra fields in PATCH and POST. A vulnerable server accepts privileged fields in the request body even when GET does not show them.

Check yourself

A request GET /orders/55 from A returned 403, while DELETE /orders/55 from A returned 204. What does it mean and what next?

Answer

The owner check exists only in the GET handler. Deleting another user’s order without a check is BOLA with critical impact. I reproduce with two of my own accounts, record requests and responses, check neighbouring methods and addresses, report it as critical and add a test “A does not change B’s resource” to the suite.

A PATCH with an extra field role: "admin" returned 200 with a body that has no role. A bug or not?

Answer

Unknown until the state is read. If the next GET shows role: "user", the field was ignored, which is acceptable. If it shows admin, it is mass assignment, and the response body just did not show the field.

In an interview. Junior: BOLA is when a user sees someone else’s resource by substituting its id, even though their token is genuine. I check with two accounts: I open B’s resource with A’s token. Middle/Senior: Authentication does not give ownership: it is checked in every handler, so I test a resource × method × role matrix, including PUT, DELETE, exports and nested addresses, and I read the state after a refusal because the status can dress up a change. For tokens I check revocation (logout, password change) and reuse of an exchanged refresh token, and for mass assignment I read the state after extra fields and push for an allow list.

More articles in this chapter