The OWASP Top 10 and broken access control

Introduction

Most attacks on websites are not clever new tricks. They use the same few mistakes, made again and again by developers who were busy. The OWASP Top 10, published by the Open Worldwide Application Security Project (a non-profit), lists the ten most serious kinds of web application risk, based on data from real applications and a survey of security experts.

This module walks through the most common ones in code you can read. This lesson gives the map: what each category means, and the one that tops the list.

How it works

Here is the 2021 edition, the one most courses and tools use. OWASP has published a newer edition that reorders and renames some categories, so check owasp.org for the latest; the ideas below carry over.

RankCategoryIn one line
A01Broken Access ControlUsers can do or see things they should not, such as another user's record
A02Cryptographic FailuresSensitive data unencrypted, or protected with weak or misused crypto
A03InjectionUntrusted input is run as code: SQL injection, and cross-site scripting
A04Insecure DesignThe design itself has no defence, such as unlimited password guesses
A05Security MisconfigurationDefault passwords, open cloud storage, detailed error pages in production
A06Vulnerable and Outdated ComponentsLibraries or servers with known, unpatched weaknesses
A07Identification and Authentication FailuresWeak logins, guessable sessions, no protection against password guessing
A08Software and Data Integrity FailuresUpdates or data accepted without checking they are genuine
A09Security Logging and Monitoring FailuresAttacks go unnoticed because nothing is logged or watched
A10Server-Side Request ForgeryThe server can be tricked into fetching a URL the attacker chooses

Many of these connect to earlier lessons: A02 is the cryptography module done wrong, and A07 is the passwords module done wrong. The next four lessons take injection (SQL and cross-site scripting), cross-site request forgery and authentication one at a time.

A01, Broken Access Control, is the top risk. The pattern is simple: the page checks that you are logged in, but not that the thing you asked for is yours. If an invoice page reads ?id=101 and you change it to ?id=102, the server must refuse, not show someone else's invoice. This specific mistake has a name: an insecure direct object reference (IDOR).

Example

Two versions of the same function: one checks only that the record exists, the other also checks who owns it.

// Broken access control, the top OWASP risk: the server must check that the record belongs to the person asking.
const invoices = [
  { id: 101, owner: "rahim", amount: 1200 },
  { id: 102, owner: "anika", amount: 560 },
];

function getInvoiceUnsafe(user, id) {
  const inv = invoices.find((i) => i.id === id);
  return inv ? user + " sees invoice " + id + " (" + inv.owner + ", " + inv.amount + " taka)" : "not found";
}

function getInvoiceSafe(user, id) {
  const inv = invoices.find((i) => i.id === id);
  if (!inv || inv.owner !== user) return user + " asked for invoice " + id + ": 404 not found";
  return user + " sees invoice " + id + " (" + inv.amount + " taka)";
}

// Rahim changes ?id=101 to ?id=102 in the address bar.
console.log(getInvoiceUnsafe("rahim", 101));
console.log(getInvoiceUnsafe("rahim", 102));
console.log(getInvoiceSafe("rahim", 101));
console.log(getInvoiceSafe("rahim", 102));
Open in compiler

Line by line

  1. invoices is the fake database: invoice 101 is Rahim's and 102 is Anika's.
  2. getInvoiceUnsafe finds the invoice by its id and shows it to whoever asked.
  3. Rahim asks for 101, his own, and sees it. Then he changes the number to 102 and sees Anika's invoice too: broken access control.
  4. getInvoiceSafe also checks inv.owner !== user. For 102 it answers 404 not found, the same answer as for an invoice that does not exist, so it does not even confirm that invoice 102 exists.

Expected result

rahim sees invoice 101 (rahim, 1200 taka)
rahim sees invoice 102 (anika, 560 taka)
rahim sees invoice 101 (1200 taka)
rahim asked for invoice 102: 404 not found

In the real world

  • Many real data leaks came from exactly this: changing a number in an address or an API request returned other people's records.
  • The checks must happen on the server. Hiding a button in the page stops nobody, because anyone can send the request directly.
  • OWASP also publishes free guides, cheat sheets and testing guides that developers use alongside the Top 10.
  • Security testers report findings using these category names, so knowing them helps you read a security report.

Common mistakes

  • Checking only that the user is logged in. Logged in is not the same as allowed.
  • Trusting ids, prices or roles sent by the browser. Anything from the client can be changed.
  • Hiding instead of checking. A missing button is not access control.
  • Treating the list as complete. The Top 10 covers common risks, not every risk.

Best practices

  • Deny by default: every request must pass an explicit check that this user may do this to this record.
  • Put access checks in one shared place on the server, so no page forgets them.
  • Prefer ids that are hard to guess as an extra layer, but never as the only protection.
  • Log access-control failures; a user trying many ids is a warning sign.

Summary

The OWASP Top 10 names the most serious web application risks; in the 2021 edition, broken access control is first, followed by cryptographic failures and injection. Access control means checking, on the server, that this user may do this action on this record, not just that they are logged in. The example shows the classic mistake, an insecure direct object reference, and its fix: check the owner and answer "not found" otherwise.

Quick check

1. A page checks that you are logged in, then shows invoice ?id= whatever you type. Which risk is this?
2. Why is hiding the "delete user" button from normal users not enough?
3. A login page has no limit on wrong passwords. Which 2021 category fits best?
4. Why does the safe invoice function answer "404 not found" rather than "403 forbidden" for someone else's invoice?

Key takeaways

  • Broken access control tops the 2021 OWASP Top 10.
  • Logged in is not the same as allowed: check ownership on every request.
  • Checks belong on the server; hidden buttons stop nobody.
  • Answer "not found" for records a user may not see, so ids are not confirmed.

Practice problems for this lesson

Was this lesson clear?

My notes

Write down what you want to remember from this lesson. Notes are saved on this device as you type, and appear on your dashboard.