Access control
The server trusts what the client sends: an id in the URL, a hidden field, or a role stored in a cookie.
Material
Broken access control means a user can do something they are not entitled to do. The two common shapes are horizontal, opening another user data with an equivalent id, and vertical, escalating to a higher role.
IDOR
Insecure direct object reference appears when an endpoint fetches an object by a client-supplied id without checking ownership. Example: GET /api/invoices/1042 returns another user invoice because only the id is checked.
// Salah: hanya id yang dipakai
const invoice = await db.invoice.findUnique({ where: { id } });
// Benar: kepemilikan ikut jadi syarat
const invoice = await db.invoice.findFirst({
where: { id, userId: session.userId },
});Prevention
- Check ownership on every endpoint, not only in the UI page.
- Never store the role in a cookie or a field the client can edit.
- Deny by default, then open access per role explicitly.
- Test with two different accounts on every endpoint that accepts an id.
Labs in this topic
Labs run on a domain separate from this site, so a payload cannot reach your account session.
Challenges in this category
Challenges from the PortSwigger Web Security Academy. The original labs run on PortSwigger domains, so the link opens there.