OWASP Top 10 Explained with Practical Examples

Security2026-11-19TryQuickToolBox

You've probably heard of the OWASP Top 10, but do you know how each vulnerability actually manifests in code? Many developers can recite the list but struggle to spot these issues in their own projects. This article bridges that gap by walking through each OWASP Top 10 category with concrete examples and practical fixes.

What is the OWASP Top 10?

The OWASP Top 10 is a standard awareness document for developers and web application security. It represents a broad consensus about the most critical security risks to web applications. The list is updated periodically to reflect the changing security landscape.

Understanding these risks is essential for building secure applications. Let's dive into each category with real code.

1. Broken Access Control

Access control enforces policy such that users cannot act outside of their intended permissions. Failures typically lead to unauthorized information disclosure, modification, or destruction of data.

Example: Insecure Direct Object Reference (IDOR)

// Vulnerable: User can access any order by changing the ID
app.get('/orders/:id', (req, res) => {
  const order = db.getOrder(req.params.id);
  res.json(order);
});

Fix: Always verify that the requested resource belongs to the authenticated user.

app.get('/orders/:id', (req, res) => {
  const order = db.getOrder(req.params.id);
  if (order.userId !== req.user.id) {
    return res.status(403).send('Forbidden');
  }
  res.json(order);
});

2. Cryptographic Failures

Previously known as "Sensitive Data Exposure," this category focuses on failures related to cryptography that lead to exposure of sensitive data.

Example: Storing Passwords in Plaintext

// Vulnerable: Plaintext password storage
user.password = req.body.password;
user.save();

Fix: Use strong hashing algorithms like bcrypt or Argon2.

const bcrypt = require('bcrypt');
user.password = await bcrypt.hash(req.body.password, 12);
user.save();

3. Injection

Injection flaws, such as SQL, NoSQL, OS, and LDAP injection, occur when untrusted data is sent to an interpreter as part of a command or query.

Example: SQL Injection

// Vulnerable: String concatenation
const query = `SELECT * FROM users WHERE username = '${username}' AND password = '${password}'`;
db.query(query);

Fix: Use parameterized queries or prepared statements.

const query = 'SELECT * FROM users WHERE username = ? AND password = ?';
db.query(query, [username, password]);

4. Insecure Design

Insecure design refers to missing or ineffective control design. It's not about implementation flaws but about architectural flaws.

Example: Missing Rate Limiting on Password Reset

Without rate limiting, attackers can brute-force password reset tokens.

Fix: Implement rate limiting and account lockout mechanisms.

const rateLimit = require('express-rate-limit');
const limiter = rateLimit({
  windowMs: 15 * 60 * 1000, // 15 minutes
  max: 5 // limit each IP to 5 requests per windowMs
});
app.use('/password-reset', limiter);

5. Security Misconfiguration

This occurs when security settings are not defined, implemented, or maintained properly. Common examples include default accounts, unnecessary features enabled, or verbose error messages.

Example: Exposing Stack Traces in Production

// Vulnerable: Detailed error messages
app.use((err, req, res, next) => {
  res.status(500).send(err.stack);
});

Fix: Log errors internally but send generic messages to users.

app.use((err, req, res, next) => {
  console.error(err.stack);
  res.status(500).send('Something broke!');
});

6. Vulnerable and Outdated Components

Using components with known vulnerabilities undermines application defenses. This includes libraries, frameworks, and other software modules.

Example: Using an Old Version of a Library

If your package.json includes a library with a known CVE, you're at risk.

Fix: Regularly update dependencies and use tools like npm audit or OWASP Dependency-Check.

npm audit fix

7. Identification and Authentication Failures

These flaws allow attackers to compromise passwords, keys, or session tokens, or to exploit other implementation flaws to assume other users' identities.

Example: Weak Session IDs

// Vulnerable: Predictable session ID
const sessionId = Date.now().toString();

Fix: Use a secure random generator.

const crypto = require('crypto');
const sessionId = crypto.randomBytes(32).toString('hex');

8. Software and Data Integrity Failures

This category focuses on code and infrastructure that does not protect against integrity violations, such as insecure deserialization or using untrusted sources.

Example: Insecure Deserialization

// Vulnerable: Deserializing untrusted data
const obj = serialize.unserialize(req.body.data);

Fix: Avoid deserializing untrusted data, or use safe formats like JSON with validation.

const obj = JSON.parse(req.body.data);
// Validate obj structure

9. Security Logging and Monitoring Failures

Insufficient logging and monitoring allows attackers to further attack systems, maintain persistence, and pivot to other systems.

Example: No Logging of Failed Logins

Without logging, you can't detect brute-force attacks.

Fix: Log authentication failures and monitor for suspicious patterns.

if (!validCredentials) {
  logger.warn(`Failed login attempt for user: ${username} from IP: ${req.ip}`);
}

10. Server-Side Request Forgery (SSRF)

SSRF flaws occur when a web application fetches a remote resource without validating the user-supplied URL. This allows an attacker to coerce the application to send a crafted request to an unexpected destination.

Example: Fetching User-Provided URLs

// Vulnerable: No validation of URL
app.get('/fetch', async (req, res) => {
  const response = await fetch(req.query.url);
  res.send(await response.text());
});

Fix: Validate and whitelist allowed domains and protocols.

const allowedDomains = ['example.com', 'api.example.com'];
const url = new URL(req.query.url);
if (!allowedDomains.includes(url.hostname)) {
  return res.status(400).send('Invalid URL');
}
// Proceed with fetch

Comparison Table: OWASP Top 10 at a Glance

Category Common Example Quick Fix
Broken Access Control IDOR Enforce ownership checks
Cryptographic Failures Plaintext passwords Use strong hashing
Injection SQL injection Parameterized queries
Insecure Design No rate limiting Implement rate limits
Security Misconfiguration Verbose errors Generic error messages
Vulnerable Components Outdated library Regular updates
Auth Failures Weak session IDs Secure random tokens
Integrity Failures Insecure deserialization Validate and use JSON
Logging Failures No failed login logs Log and monitor
SSRF Fetching arbitrary URLs Whitelist domains

FAQ

What is the OWASP Top 10?

The OWASP Top 10 is a list of the most critical security risks to web applications, maintained by the Open Web Application Security Project (OWASP). It is updated regularly to reflect current threats.

How often is the OWASP Top 10 updated?

The list is updated every few years. The most recent version is from 2021, with the next update expected in the coming years. Always refer to the official OWASP website for the latest version.

Is the OWASP Top 10 enough to secure my application?

While the OWASP Top 10 covers the most critical risks, it is not exhaustive. It should be part of a broader security strategy that includes secure coding practices, regular security testing, and staying informed about emerging threats.

Ready to put this knowledge into practice? Use our JSON Formatter to safely inspect and validate JSON data, helping you avoid injection and deserialization issues.