Skip to content
SecurityChapter 38 / 57Advanced6 min read

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:

#RiskIn one line
A01Broken Access ControlA user sees or changes data that is not theirs
A02Security MisconfigurationWrong headers, CORS, default settings
A03Software Supply Chain FailuresA dependency or build pipeline is compromised
A04Cryptographic FailuresWeak hashing, plain text secrets
A05InjectionUser input inside SQL, shell or HTML
A10Mishandling of Exceptional ConditionsOn 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 codeSafe code
Checked login, not ownershipOwner or tenant check on every resource
A variable joined into the SQL stringA parameterized query
The user's HTML rendered directlyReact escaping, or sanitize first
User input in a file pathMap from an allow-list or a random ID
next() or success inside catchDeny and log inside catch
Stack trace in the errorA generic message, detail in the logs

3. When to follow it

LevelHow importantWhy
Learning projectUnderstand injection and access controlThey are asked about in interviews and in your first job
Production codeIn every PROne missing check becomes a full data leak
Senior levelA review checklist and automated scanningCatching these in every PR the team opens

4. Bad vs good code

Broken access control (IDOR)

ts
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.

ts
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

ts
const rows = await sql.unsafe(`SELECT * FROM users WHERE email = '${email}'`);
ts
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

tsx
<div dangerouslySetInnerHTML={{ __html: comment.body }} />
tsx
<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

ts
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?

VulnerabilityBadGood
IDORFetch by id onlyFetch by id + ownerId
SQL injectionString interpolationParameterized query
XSSRender raw HTMLEscaped text or sanitized HTML
Path traversalreadFile(req.query.name)Look up by allow-list or ID
Exceptional conditionsAllow on errorDeny on error

5. How to apply it

On every new endpoint or PR, ask these questions:

Endpoint security review
Is this route behind authentication?
Was the owner or tenant of every resource checked?
Was the input validated with a schema?
Is every query parameterized?
Is the output encoded for its context (HTML, URL, shell)?
What happens on error: deny or allow?

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

Final quick revision

CheckYes?
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