OWASP Top 10 Explained with Practical Examples

Security2026-11-21TryQuickToolBox

Why the OWASP Top 10 Matters

Every web developer faces a common problem: security vulnerabilities are easy to introduce and hard to spot. The OWASP Top 10 is a standard awareness document that lists the most critical security risks to web applications. It's updated regularly based on real-world data. Understanding these risks helps you write safer code and avoid common pitfalls.

This article walks through each category with practical examples and fixes. We'll focus on code-level issues you can address today.

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 = getOrderById(req.params.id);
  res.json(order);
});

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

Fix: Always enforce access control on the server side. Use role-based or attribute-based checks.

2. Cryptographic Failures

This category includes failures related to protecting sensitive data, such as using weak encryption or storing passwords in plain text.

// Vulnerable: Storing password in plain text
user.password = req.body.password;

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

Fix: Use strong, modern algorithms (e.g., bcrypt, Argon2) for password hashing. Encrypt sensitive data at rest and in transit.

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

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

Fix: Use parameterized queries or prepared statements. Avoid dynamic SQL.

4. Insecure Design

Insecure design refers to missing or ineffective security controls at the design level. For example, a password reset feature that uses a guessable token.

Fix: Threat modeling and secure design patterns. Use strong, random tokens with expiration.

5. Security Misconfiguration

This includes leaving default accounts enabled, exposing stack traces, or misconfiguring cloud permissions.

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

// Fixed: Log errors server-side, send generic message
app.use((err, req, res, next) => {
  console.error(err.stack);
  res.status(500).send('Something went wrong');
});

Fix: Harden configurations, remove defaults, and follow the principle of least privilege.

6. Vulnerable and Outdated Components

Using libraries with known vulnerabilities is a common risk. For example, an outdated version of a popular npm package.

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

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: Implement rate limiting
const rateLimit = require('express-rate-limit');
const limiter = rateLimit({ windowMs: 15 * 60 * 1000, max: 100 });
app.post('/login', limiter, (req, res) => {
  // check credentials
});

Fix: Enforce strong passwords, implement multi-factor authentication, and use secure session management.

8. Software and Data Integrity Failures

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

Fix: Verify integrity with digital signatures or checksums. Avoid deserializing data from untrusted sources.

9. Security Logging and Monitoring Failures

Insufficient logging and monitoring allow attackers to persist undetected.

Fix: Log security-relevant events, monitor for suspicious activity, and have an incident response plan.

10. Server-Side Request Forgery (SSRF)

SSRF occurs when an attacker can make the server send requests to unintended locations, often to access internal systems.

// Vulnerable: Fetching arbitrary URLs
app.get('/fetch', (req, res) => {
  fetch(req.query.url).then(data => res.send(data));
});

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

Fix: Validate and sanitize URLs, use allowlists, and restrict network access.

Comparison Table: OWASP Top 10 at a Glance

Risk Example Quick Fix
Broken Access Control Accessing other users' data Enforce server-side checks
Cryptographic Failures Plaintext passwords Use strong hashing
Injection SQL injection via concatenation Parameterized queries
Insecure Design Guessable reset tokens Threat modeling
Security Misconfiguration Exposed stack traces Harden configs
Vulnerable Components Outdated libraries Regular updates
Auth Failures No rate limiting Implement MFA and rate limits
Integrity Failures Untrusted CDN Verify signatures
Logging Failures No security logs Monitor and alert
SSRF Fetching internal URLs Validate and allowlist

FAQ

What is the OWASP Top 10?

The OWASP Top 10 is a regularly updated list of the most critical web application security risks, published by the Open Web Application Security Project (OWASP).

How often is the OWASP Top 10 updated?

It is updated every few years to reflect changes in the threat landscape. The current version is from 2021.

Is the OWASP Top 10 enough to secure my app?

No, it's a starting point. You should also follow secure coding practices, conduct regular security testing, and stay informed about emerging threats.

For analyzing your web server logs to detect attacks, try our Nginx Log Analyzer to identify suspicious patterns.