OWASP Top 10 Explained With Practical Code Examples

Security2026-11-15TryQuickToolBox

You ship a feature, tests pass, the demo looks great — and then a security review flags three issues you did not even know existed. Most breaches are not exotic zero-days. They come from a small set of recurring mistakes that the OWASP Top 10 was created to catalog. The problem is that the list is often presented as abstract categories, which makes it hard to connect to the code you actually write.

This article walks through the OWASP Top 10 with concrete, runnable-style examples. For each risk you will see what the vulnerable code looks like, why it fails, and the fix you can apply in a normal pull request. The goal is not to memorize the list but to recognize these patterns when they appear in your own codebase.

What the OWASP Top 10 Actually Is

The OWASP Top 10 is a periodically updated awareness document that ranks the most critical web application security risks, based on community data and industry consensus. It is not a checklist or a certification. It is a prioritization tool: if you fix these categories, you eliminate a large share of real-world attack surface.

Each entry describes a category, not a single bug. One category like "Injection" covers SQL injection, command injection, LDAP injection and more. Treat each item as a family of mistakes with a shared root cause.

A1: Broken Access Control

Access control failures happen when a user can act outside their intended permissions. The classic example is an insecure direct object reference: the app fetches a resource by ID without checking ownership.

// Vulnerable: any logged-in user can read any invoice
app.get('/invoices/:id', auth, async (req, res) => {
  const invoice = await db.invoice.findById(req.params.id);
  res.json(invoice);
});

// Fixed: scope the query to the current user
app.get('/invoices/:id', auth, async (req, res) => {
  const invoice = await db.invoice.findOne({
    id: req.params.id,
    userId: req.user.id
  });
  if (!invoice) return res.status(404).end();
  res.json(invoice);
});

The fix is to enforce authorization at the data layer, not just at the route. Deny by default, check ownership on every object, and log access-control failures so you can detect probing.

A2: Cryptographic Failures

This category covers data exposed because encryption is missing, weak, or misapplied. Common examples: storing passwords with MD5, sending sensitive data over HTTP, or hardcoding keys in source code.

A quick test: search your codebase for md5(, sha1(, and password near string concatenation. Any hit deserves a review.

A3: Injection

Injection occurs when untrusted data is interpreted as code or commands. SQL injection is the most famous example, but the same pattern shows up in shell commands, template engines, and ORMs.

# Vulnerable: string interpolation into SQL
query = f"SELECT * FROM users WHERE email = '{email}'"
cursor.execute(query)

# Fixed: parameterized query
cursor.execute("SELECT * FROM users WHERE email = %s", (email,))

The rule is simple: never build queries or commands by concatenating user input. Use parameterized queries, allowlists for command arguments, and safe template engines. If you must shell out, pass arguments as an array, never as a string.

A4: Insecure Design

Some flaws cannot be fixed by better code because the design itself is unsafe. Examples include a password reset flow with no rate limit, a checkout that trusts a client-supplied price, or a multi-tenant app with no tenant isolation model.

Mitigations are process-oriented: threat modeling during design, abuse-case testing, and explicit security requirements in user stories. Ask "how would an attacker misuse this feature?" before writing code, not after.

A5: Security Misconfiguration

Misconfiguration is the easiest category to fix and one of the most common. Default credentials, verbose stack traces in production, directory listing enabled, permissive CORS, and unnecessary services all fall here.

MisconfigurationPractical Fix
Debug mode in productionSet DEBUG=false and verify in CI
Stack traces returned to clientsLog internally, return generic errors
Wildcard CORS with credentialsAllowlist specific origins
Default admin credentialsForce rotation on first login
Directory listing onDisable in the web server config

Treat configuration as code. Version it, review it, and add automated checks that fail the build when a dangerous default reappears.

A6: Vulnerable and Outdated Components

Your dependencies are part of your attack surface. A library with a known CVE can compromise the whole application, even if your own code is clean.

  1. Generate a software bill of materials (SBOM) for every build.
  2. Run dependency scanning in CI and fail on high-severity findings.
  3. Pin versions and review upgrades deliberately.
  4. Remove unused libraries; every dependency is a liability.

Automated tools help, but the real discipline is a routine upgrade cadence. A dependency you have not touched in two years is a dependency you do not understand.

A7: Identification and Authentication Failures

Weak authentication lets attackers take over accounts. Examples include allowing weak passwords, missing rate limits on login, session IDs in URLs, and sessions that never expire.

Authentication is the front door. Small lapses here have outsized impact.

A8: Software and Data Integrity Failures

This category covers code and data that is trusted without verification. Examples include deserializing untrusted input, pulling updates over unencrypted channels, or installing packages without integrity checks.

Practical defenses: verify signatures on artifacts, use lockfiles with checksums, avoid native deserialization of user input, and treat CI/CD pipelines as security-critical infrastructure. If an attacker can push to your build, they own your product.

A9: Security Logging and Monitoring Failures

Many breaches go unnoticed for months because logging is incomplete or nobody reviews it. If you cannot see an attack, you cannot respond to it.

Log authentication events, authorization failures, and input validation errors. Include enough context to investigate without logging secrets or full PII. Ship logs to a central system and alert on patterns like repeated 403s from one IP or a spike in login failures.

A10: Server-Side Request Forgery (SSRF)

SSRF happens when the server fetches a URL supplied by the user. Without validation, an attacker can reach internal services, cloud metadata endpoints, or localhost admin panels.

# Vulnerable: fetch any URL the user provides
url = request.args['url']
response = requests.get(url)

# Fixed: allowlist hostnames and block internal ranges
allowed = {'api.example.com', 'cdn.example.com'}
parsed = urlparse(url)
if parsed.hostname not in allowed:
    abort(400)
response = requests.get(url, timeout=5)

Allowlist destinations, block private IP ranges, disable redirects to internal hosts, and run outbound fetches from a restricted network segment.

A Practical Review Routine

You do not need to memorize the list. Instead, build these checks into your workflow:

  1. During design, ask how each feature could be abused.
  2. During code review, look for string-built queries, missing ownership checks, and unvalidated URLs.
  3. In CI, run dependency scanning, secret scanning, and configuration checks.
  4. In production, centralize logs and alert on authentication and authorization anomalies.

When you debug API responses or inspect payloads returned by these checks, a JSON formatter makes it much faster to read nested error objects and scan for leaked fields.

FAQ

Is the OWASP Top 10 a complete security checklist?

No. It is an awareness and prioritization document covering the most critical risk categories. A complete program also needs threat modeling, secure SDLC practices, dependency management, and penetration testing.

Which OWASP Top 10 item should I fix first?

Start with broken access control and injection. They are the most common causes of serious breaches and are usually fixable with targeted code changes. Then address misconfiguration and dependency hygiene, which are cheap to improve.

How often is the OWASP Top 10 updated?

It is revised periodically as the threat landscape and community data evolve. Always check the official OWASP site for the current edition rather than relying on a cached version.

Pick one category from this article and audit a single endpoint against it today. That small, concrete review is worth more than reading the list a dozen times.