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.
| Rank | Category | In one line |
|---|---|---|
| A01 | Broken Access Control | Users can do or see things they should not, such as another user's record |
| A02 | Cryptographic Failures | Sensitive data unencrypted, or protected with weak or misused crypto |
| A03 | Injection | Untrusted input is run as code: SQL injection, and cross-site scripting |
| A04 | Insecure Design | The design itself has no defence, such as unlimited password guesses |
| A05 | Security Misconfiguration | Default passwords, open cloud storage, detailed error pages in production |
| A06 | Vulnerable and Outdated Components | Libraries or servers with known, unpatched weaknesses |
| A07 | Identification and Authentication Failures | Weak logins, guessable sessions, no protection against password guessing |
| A08 | Software and Data Integrity Failures | Updates or data accepted without checking they are genuine |
| A09 | Security Logging and Monitoring Failures | Attacks go unnoticed because nothing is logged or watched |
| A10 | Server-Side Request Forgery | The 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));Line by line
invoicesis the fake database: invoice 101 is Rahim's and 102 is Anika's.getInvoiceUnsafefinds the invoice by its id and shows it to whoever asked.- 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.
getInvoiceSafealso checksinv.owner !== user. For 102 it answers404 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
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.