OWASP Top 10 Explained with Practical Examples

Security2026-11-26TryQuickToolBox

You've probably heard of the OWASP Top 10—the list of the most critical web application security risks. But do you know what each risk actually looks like in code? Many developers can recite the names but struggle to spot these vulnerabilities in their own projects. This article walks through each OWASP Top 10 category with concrete examples and practical fixes, so you can recognize and remediate them in your codebase.

1. Broken Access Control

Broken access control occurs when users can act outside their intended permissions. For example, a user might access another user's data by changing a URL parameter.

// Vulnerable: no check if the requested order belongs to the user
app.get('/orders/:id', (req, res) => {
  const order = db.getOrder(req.params.id);
  res.json(order);
});

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

Fix: Enforce access control checks on every request, preferably using a centralized mechanism. Deny by default.

2. Cryptographic Failures

Sensitive data must be encrypted in transit and at rest. Common mistakes include storing passwords in plaintext or using weak hashing algorithms like MD5.

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

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

Fix: Use strong, salted hashing for passwords (bcrypt, Argon2). Always use HTTPS. Encrypt sensitive data at rest.

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
const query = `SELECT * FROM users WHERE id = ${req.params.id}`;

// Fixed: parameterized query
db.query('SELECT * FROM users WHERE id = ?', [req.params.id]);

Fix: Use parameterized queries or prepared statements. Validate and sanitize all input.

4. Insecure Design

Insecure design refers to missing or ineffective control design. For example, a password reset feature that uses a predictable token.

// Vulnerable: predictable token
const token = Date.now();

// Fixed: cryptographically random token
const token = crypto.randomBytes(32).toString('hex');

Fix: Incorporate security during the design phase. Use threat modeling and secure design patterns.

5. Security Misconfiguration

This includes leaving default passwords, exposing stack traces, or misconfiguring cloud storage permissions.

# Vulnerable: debug mode in production
DEBUG = True

# Fixed: disable debug
DEBUG = False

Fix: Harden configurations, remove unused features, and automate configuration checks.

6. Vulnerable and Outdated Components

Using libraries with known vulnerabilities is a common risk. For example, an outdated version of Lodash with a prototype pollution flaw.

# Check for vulnerabilities
npm audit

Fix: Regularly update dependencies, remove unused ones, and monitor for CVEs.

7. Identification and Authentication Failures

Weak authentication allows attackers to compromise passwords or session tokens. For example, allowing brute-force attacks.

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

// Fixed: add rate limiting
const rateLimit = require('express-rate-limit');
app.use('/login', rateLimit({ windowMs: 15 * 60 * 1000, max: 5 }));

Fix: Implement multi-factor authentication, enforce strong passwords, and use secure session management.

8. Software and Data Integrity Failures

This involves code and infrastructure that does not protect against integrity violations. For example, using untrusted CDNs or deserializing untrusted data.

// Vulnerable: deserializing untrusted data
deserialize(req.body.data);

// Fixed: use safe formats like JSON and validate
const data = JSON.parse(req.body.data);
// validate schema

Fix: Use digital signatures, verify integrity of dependencies, and avoid unsafe deserialization.

9. Security Logging and Monitoring Failures

Without proper logging, breaches go undetected. For example, not logging failed login attempts.

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

// Fixed: log failures
app.post('/login', (req, res) => {
  if (!valid) {
    logger.warn(`Failed login for ${req.body.username}`);
  }
});

Fix: Log security events, monitor logs, and set up alerts for suspicious activities.

10. Server-Side Request Forgery (SSRF)

SSRF occurs when an attacker can make the server perform requests to unintended locations. For example, fetching a URL provided by the user without validation.

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

// Fixed: validate URL and restrict to allowlist
const allowedHosts = ['api.example.com'];
const url = new URL(req.query.url);
if (!allowedHosts.includes(url.hostname)) return res.status(400).end();

Fix: Validate and sanitize URLs, use allowlists, and restrict outbound traffic.

Comparison Table: OWASP Top 10 Risks and Mitigations

Risk Example Mitigation
Broken Access Control Accessing other users' data via IDOR Enforce access control checks
Cryptographic Failures Storing passwords in plaintext Use strong hashing and HTTPS
Injection SQL injection via concatenated queries Use parameterized queries
Insecure Design Predictable password reset tokens Threat modeling and secure design
Security Misconfiguration Debug mode enabled in production Harden configurations
Vulnerable Components Outdated library with known CVE Regular updates and audits
Authentication Failures No rate limiting on login MFA and rate limiting
Integrity Failures Deserializing untrusted data Digital signatures and safe formats
Logging Failures No logging of failed logins Centralized logging and monitoring
SSRF Fetching arbitrary URLs URL validation and allowlists

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, with updates typically every few years.

Can I use the OWASP Top 10 as a checklist?

While the OWASP Top 10 is not exhaustive, it provides a solid starting point. It's best used alongside other resources like the OWASP Application Security Verification Standard (ASVS) for comprehensive coverage.

Ready to test your applications for common vulnerabilities? Use our Nginx Log Analyzer to detect suspicious patterns in your server logs and identify potential attacks.