OWASP Top 10 Explained with Practical Examples
You've probably heard of the OWASP Top 10—the list of the most critical web application security risks. But memorizing the names won't protect your app. You need to see how each vulnerability manifests in real code and understand the practical steps to fix them. This guide walks through each OWASP Top 10 category with concrete examples and actionable defenses.
1. Broken Access Control
Access control enforces who can do what. When it's broken, users can access data or perform actions outside their permissions. A common example is an Insecure Direct Object Reference (IDOR): changing a URL parameter to access another user's data.
// Vulnerable: no ownership check
app.get('/api/user/:id', (req, res) => {
const user = db.getUserById(req.params.id);
res.json(user);
});
// Fixed: verify the requester owns the resource
app.get('/api/user/:id', (req, res) => {
if (req.user.id !== req.params.id) {
return res.status(403).send('Forbidden');
}
const user = db.getUserById(req.params.id);
res.json(user);
});
Defense: Enforce access control server-side, deny by default, and use role-based or attribute-based checks consistently.
2. Cryptographic Failures
This category covers failures to protect sensitive data in transit and at rest. Examples include storing passwords in plaintext, using weak hashing algorithms, or transmitting data over HTTP.
Defense: Use strong, adaptive hashing like bcrypt or Argon2 for passwords. Encrypt sensitive data at rest and enforce HTTPS with HSTS.
3. Injection
Injection flaws occur when untrusted data is sent to an interpreter as part of a command or query. SQL injection is the classic example.
// Vulnerable: string concatenation
const query = "SELECT * FROM users WHERE username = '" + username + "'";
// Fixed: parameterized query
const query = 'SELECT * FROM users WHERE username = $1';
const values = [username];
Defense: Use parameterized queries or prepared statements. For other injection types (OS command, LDAP), avoid interpreting user input directly and use safe APIs.
4. Insecure Design
Insecure design refers to flaws in the application's architecture and logic, not just implementation bugs. For example, a password reset feature that uses a predictable token or allows unlimited attempts.
Defense: Threat modeling during design, secure design patterns, and reference architectures.
5. Security Misconfiguration
This includes default accounts, verbose error messages, unnecessary features enabled, or missing security headers. A common example is leaving debug mode on in production.
Defense: Harden configurations, remove unused features, set security headers (CSP, X-Content-Type-Options), and automate configuration checks.
6. Vulnerable and Outdated Components
Using libraries or frameworks with known vulnerabilities is a major risk. For instance, an old version of a popular library with a published CVE.
Defense: Maintain an inventory of dependencies, monitor for vulnerabilities (e.g., using Dependabot), and patch regularly.
7. Identification and Authentication Failures
Weak authentication allows attackers to guess passwords, use credential stuffing, or bypass login. Examples include allowing weak passwords, missing multi-factor authentication, or exposing session IDs in URLs.
Defense: Enforce strong password policies, implement MFA, use secure session management, and limit failed login attempts.
8. Software and Data Integrity Failures
This category relates to code and infrastructure that doesn't protect against integrity violations. Examples include using untrusted CDNs, insecure deserialization, or auto-updating without verification.
Defense: Verify digital signatures, use trusted repositories, and validate integrity of updates.
9. Security Logging and Monitoring Failures
Without proper logging and monitoring, breaches go undetected. Examples include not logging authentication failures or not monitoring logs for suspicious activity.
Defense: Log security-relevant events, ensure logs are tamper-proof, and set up alerts for anomalies.
10. Server-Side Request Forgery (SSRF)
SSRF occurs when an attacker can make the server send requests to unintended locations, often to internal services. For example, a feature that fetches a URL provided by the user without validation.
# Vulnerable: no validation of URL
url = request.args.get('url')
response = requests.get(url)
# Fixed: allowlist domains and block internal IPs
from urllib.parse import urlparse
import ipaddress
parsed = urlparse(url)
if parsed.hostname not in ALLOWED_HOSTS:
abort(400)
# Also resolve and check IP is not private
Defense: Validate and sanitize URLs, use allowlists, and restrict outbound traffic.
Comparison Table
| Risk | Example | Primary Defense |
|---|---|---|
| Broken Access Control | IDOR | Enforce server-side checks |
| Injection | SQL injection | Parameterized queries |
| Cryptographic Failures | Plaintext passwords | Strong hashing, encryption |
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).
How often is the OWASP Top 10 updated?
It is updated periodically to reflect emerging threats and changes in technology; 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 new threats.
To further secure your web applications, consider using tools like the Nginx Log Analyzer to monitor and detect suspicious traffic patterns.