OWASP Top 10 Explained: Practical Examples for Developers

Security2026-11-20TryQuickToolBox

You've probably heard of the OWASP Top 10—the list of the most critical web application security risks. But knowing the names isn't enough. To truly protect your app, you need to see how these vulnerabilities manifest in real code and understand the practical steps to fix them.

In this article, we'll walk through each OWASP Top 10 category with concrete examples and actionable advice. Whether you're a developer, tester, or DevOps engineer, these insights will help you write safer code and build more resilient systems.

1. Broken Access Control

Broken access control occurs when users can act outside their intended permissions. A classic example: an API endpoint that doesn't verify if the requesting user owns the resource.

// Vulnerable: any user can access any order by ID
app.get('/api/orders/:id', (req, res) => {
  const order = getOrderById(req.params.id);
  res.json(order);
});

// Fixed: check ownership
app.get('/api/orders/:id', (req, res) => {
  const order = getOrderById(req.params.id);
  if (order.userId !== req.user.id) {
    return res.status(403).json({ error: 'Forbidden' });
  }
  res.json(order);
});

Prevention: Enforce access control on the server side, deny by default, and regularly test with different user roles.

2. Cryptographic Failures

This category (formerly "Sensitive Data Exposure") covers failures related to cryptography—like storing passwords in plaintext or using weak algorithms.

// Vulnerable: plaintext password storage
user.password = req.body.password;

// Fixed: hash with bcrypt
const bcrypt = require('bcrypt');
user.password = await bcrypt.hash(req.body.password, 12);

Prevention: Use strong, modern algorithms (bcrypt, Argon2 for passwords; AES-GCM for encryption), enforce HTTPS, and never hardcode secrets.

3. Injection

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

// Vulnerable: string concatenation in SQL
const query = `SELECT * FROM users WHERE email = '${email}'`;

// Fixed: parameterized query
const query = 'SELECT * FROM users WHERE email = $1';
const values = [email];

Prevention: Use parameterized queries or ORMs, validate input, and apply the principle of least privilege to database accounts.

4. Insecure Design

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

Example: A password reset flow that uses security questions with easily guessable answers.

Prevention: Threat modeling during design, use secure design patterns, and write security requirements.

5. Security Misconfiguration

This includes default accounts, verbose error messages, unnecessary features enabled, and missing security headers.

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

// Fixed: generic error message
app.use((err, req, res, next) => {
  console.error(err.stack);
  res.status(500).send('Internal Server Error');
});

Prevention: Harden configurations, remove unused features, and use security headers like CSP and HSTS.

6. Vulnerable and Outdated Components

Using libraries with known vulnerabilities is like leaving your front door open.

Example: Depending on an old version of a popular library like lodash with prototype pollution.

Prevention: Regularly update dependencies, use tools like npm audit or OWASP Dependency-Check, and remove unused dependencies.

7. Identification and Authentication Failures

Weak authentication allows attackers to compromise passwords or session tokens.

// Vulnerable: no rate limiting on login
app.post('/login', (req, res) => {
  // check credentials
});

// Fixed: add rate limiting
const rateLimit = require('express-rate-limit');
const limiter = rateLimit({ windowMs: 15 * 60 * 1000, max: 10 });
app.post('/login', limiter, (req, res) => {
  // check credentials
});

Prevention: Implement multi-factor authentication, enforce strong password policies, and use secure session management.

8. Software and Data Integrity Failures

This category relates to code and infrastructure that doesn't protect against integrity violations.

Example: Deserializing untrusted data without verification.

// Vulnerable: deserializing user input
const obj = JSON.parse(req.body.data); // if data is malicious, could lead to RCE in some languages

// Fixed: validate and sanitize before deserialization
if (typeof req.body.data !== 'string' || !isValidJSON(req.body.data)) {
  throw new Error('Invalid input');
}
const obj = JSON.parse(req.body.data);

Prevention: Verify digital signatures, use integrity checks, and avoid deserializing untrusted data.

9. Security Logging and Monitoring Failures

Without proper logging and monitoring, breaches go undetected.

Example: Not logging failed login attempts or not monitoring for suspicious patterns.

Prevention: Log security events, set up alerts, and ensure logs are monitored and protected.

10. Server-Side Request Forgery (SSRF)

SSRF occurs when an attacker can make the server send requests to unintended locations.

// Vulnerable: fetching any URL provided by user
app.get('/fetch', async (req, res) => {
  const response = await fetch(req.query.url);
  res.send(await response.text());
});

// Fixed: validate and restrict URLs
const allowedHosts = ['api.example.com'];
app.get('/fetch', async (req, res) => {
  const url = new URL(req.query.url);
  if (!allowedHosts.includes(url.hostname)) {
    return res.status(400).send('Invalid URL');
  }
  const response = await fetch(url);
  res.send(await response.text());
});

Prevention: Validate and sanitize URLs, use allowlists, and restrict network access from the server.

Comparison of OWASP Top 10 Categories

Category Example Prevention
Broken Access Control Accessing other users' data Enforce server-side checks
Cryptographic Failures Plaintext passwords Use strong hashing
Injection SQL injection Parameterized queries
Insecure Design Guessable security questions Threat modeling
Security Misconfiguration Default credentials Harden configs
Vulnerable Components Outdated libraries Regular updates
Authentication Failures No rate limiting MFA, rate limiting
Integrity Failures Unverified deserialization Validate input
Logging Failures No monitoring Log and alert
SSRF Fetching internal URLs Allowlist URLs

FAQ

What is the OWASP Top 10?

The OWASP Top 10 is a regularly updated list of the most critical security risks for web applications, published by the Open Web Application Security Project (OWASP). It serves as a baseline for developers and security professionals.

How often is the OWASP Top 10 updated?

OWASP updates the list periodically to reflect emerging threats and changes in technology. The most recent version is from 2021, but work on the next edition is ongoing.

Is the OWASP Top 10 enough to secure my app?

While the OWASP Top 10 covers major risks, it's not exhaustive. You should also follow secure coding practices, conduct regular security testing, and stay informed about new vulnerabilities.

For more hands-on security tools, check out our Nginx log analyzer to monitor and detect suspicious traffic patterns.