StoicBuilder

HandbookXIV the VallumBroken access control

XIVthe Vallum, Defend it

Broken access control

1 min readUpdated 28 November

In plain words

Broken access control means the server doesn't check that this particular user may do this action on this particular record, so changing an ID or calling an unlinked route exposes someone else's data.

Where you see it

Harbor's invoice page loads /api/invoices/inv_1042. The route checks that someone is signed in, but not that the invoice belongs to their account, so a customer who edits the ID can read another company's invoice. It's the top category in the OWASP Top 10.

app/api/invoices/[id]/route.tsserver
const invoice = await db.invoice.findFirst({ where: { id: params.id, accountId: session.accountId }, // ownership is part of the query});if (!invoice) return new Response("Not found", { status: 404 });
Filtering by the caller's account means another account's invoice is never found. A 404 also avoids confirming that the ID exists.

What goes wrong

  1. Hiding the button and calling it secure

    Removing the Delete button for viewers doesn't stop a viewer sending DELETE /api/projects/42 from an HTTP client. Check every permission on the server, on every route.

  2. Checks scattered through every handler

    When each route writes its own ownership check, one new route without it is all it takes. Put the rule in one place, such as a data-access layer that always filters by account, or row-level security in Postgres.

  3. Trusting IDs and roles the client sends

    An accountId or role in the request body is a claim, not a fact. Take the account and role from the server-side session, never from the request.

    { "accountId": "acc_7", "role": "admin" }

What to tell your agent

Copy this into Lovable, Bolt, Cursor or any agent
Go through every API route and server action that reads or changes a record by ID, and tell me where each checks that the record belongs to the caller's account and that their role allows the action. Fix any that don't, take account and role only from the session, and add tests where user A tries to read and change user B's records.

Quick check

Sign in to earn +10 XP for it

Harbor hides the Delete project button from viewers. What else must be true for viewers to be unable to delete projects?

Got a prompt that touches broken access control?

Paste it. You get a better prompt first, then the cards that explain it.

Check your own prompt

Free, no sign-up.