Common Vulnerabilities (OWASP)
OWASP top 10 vulnerabilities for web developers, with bad vs good examples of broken access control, SQL injection, XSS, path traversal and fail open errors.
On this page
1. What is this practice?
OWASP (Open Worldwide Application Security Project) is a community that looks at data from real breaches and builds a list of the most common web risks. The top part of the 2025 list is this:
| # | Risk | In one line |
|---|---|---|
| A01 | Broken Access Control | A user sees or changes data that is not theirs |
| A02 | Security Misconfiguration | Wrong headers, CORS, default settings |
| A03 | Software Supply Chain Failures | A dependency or build pipeline is compromised |
| A04 | Cryptographic Failures | Weak hashing, plain text secrets |
| A05 | Injection | User input inside SQL, shell or HTML |
| A10 | Mishandling of Exceptional Conditions | On an error the system opens up or leaks detail |
2. Why does it matter?
This is not theoretical. Broken Access Control is number 1 on the list because most breaches come from it, and it is often just one forgotten line.
| Weak code | Safe code |
|---|---|
| Checked login, not ownership | Owner or tenant check on every resource |
| A variable joined into the SQL string | A parameterized query |
| The user's HTML rendered directly | React escaping, or sanitize first |
| User input in a file path | Map from an allow-list or a random ID |
| next() or success inside catch | Deny and log inside catch |
| Stack trace in the error | A generic message, detail in the logs |
3. When to follow it
| Level | How important | Why |
|---|---|---|
| Learning project | Understand injection and access control | They are asked about in interviews and in your first job |
| Production code | In every PR | One missing check becomes a full data leak |
| Senior level | A review checklist and automated scanning | Catching these in every PR the team opens |
4. Bad vs good code
Broken access control (IDOR)
export async function GET(request: Request, ctx: { params: Promise<{ id: string }> }) {
const user = await requireUser(request);
const { id } = await ctx.params;
const invoice = await db.invoice.findUnique({ where: { id } });
return Response.json(invoice);
}The user is logged in, but nobody checked whose invoice it is.
export async function GET(request: Request, ctx: { params: Promise<{ id: string }> }) {
const user = await requireUser(request);
const { id } = await ctx.params;
const invoice = await db.invoice.findFirst({ where: { id, ownerId: user.id } });
if (!invoice) {
return Response.json({ error: "not found" }, { status: 404 });
}
return Response.json(invoice);
}Someone else's invoice also gets a 404, so it does not even leak that the ID exists.
SQL injection
const rows = await sql.unsafe(`SELECT * FROM users WHERE email = '${email}'`);const rows = await sql`SELECT * FROM users WHERE email = ${email}`;A tagged template sends the value to the driver separately, so ' OR 1=1 -- becomes just a strange email, not part of the query.
XSS
<div dangerouslySetInnerHTML={{ __html: comment.body }} /><p>{comment.body}</p>React escapes text by itself. If you really must render HTML, pass it through a trusted sanitizer (like DOMPurify) first.
Fail open error
try {
await verifySubscription(user);
} catch {
return next();
}The payment provider went down and everyone got premium. On an error, deny and log it.
What is the difference?
| Vulnerability | Bad | Good |
|---|---|---|
| IDOR | Fetch by id only | Fetch by id + ownerId |
| SQL injection | String interpolation | Parameterized query |
| XSS | Render raw HTML | Escaped text or sanitized HTML |
| Path traversal | readFile(req.query.name) | Look up by allow-list or ID |
| Exceptional conditions | Allow on error | Deny on error |
5. How to apply it
On every new endpoint or PR, ask these questions:
Also remember the patterns you can catch with grep: eval or a dynamic import() with user input, SQL built by string concatenation, http:// URLs in production, and * in CORS.
6. Exceptions and common mistakes
When the rule does not apply: public content (like published blog posts) does not need an ownership check. But every route that writes, changes or deletes does, even if it is admin only.
Mistake: Authorization only in the UI
Why? Hiding a button does not close the API, anyone can call it with curl.
Better: Do every check on the server, the UI is only a convenience.
Mistake: Returning 403 for a forbidden resource
Why? 403 reveals that the resource exists, which opens the way to enumeration.
Better: For another user's resource, return the same 404 you would return if it did not exist.
Mistake: Taking a dynamic column name from the user
Why? Column names cannot be parameterized, so injection comes back.
Better: Keep an allow-list of sort or filter columns and let the user choose only from it.
Mistake: Approving generated code after running only the success path
Why? A missing auth check is invisible on the success path.
Better: Also run the request with another user's token, and write that into a test.
7. What to learn before and after
| Stage | Topics |
|---|---|
| Before | Security Baseline, Authorization & Multi-Tenancy |
| Alongside | Query Patterns & Transactions, Input Validation at the Boundary |
| After | Dependencies & Supply Chain, Endpoint Tests First |
Final quick revision
| Check | Yes? |
|---|---|
| Ownership or tenant check on every resource | |
| Another user's resource returns 404 | |
| Every query parameterized | |
| User HTML sanitized or escaped | |
| File paths not built from user input | |
| Deny on error, detail only in logs |