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 knowing the names isn't enough. To truly protect your applications, you need to see how these vulnerabilities manifest in real code and understand the concrete steps to fix them.
In this article, we'll walk through each OWASP Top 10 category with practical examples. You'll see vulnerable code snippets, learn why they're dangerous, and get actionable mitigation strategies. Whether you're a developer, tester, or security engineer, this guide will help you write safer code and spot weaknesses before attackers do.
1. Broken Access Control
Broken access control occurs when users can act outside their intended permissions—accessing other users' data, performing admin actions, or viewing sensitive files. It's the #1 risk because it's common and impactful.
Example: Insecure Direct Object Reference (IDOR)
// Vulnerable: User can change the ID and view any invoice
app.get('/invoice/:id', (req, res) => {
const invoice = db.getInvoice(req.params.id);
res.json(invoice);
});
An attacker simply changes the id parameter to access other users' invoices.
Mitigation
- Enforce access control checks on the server side for every request.
- Use role-based or attribute-based access control (RBAC/ABAC).
- Deny by default; explicitly grant permissions.
2. Cryptographic Failures
Previously called "Sensitive Data Exposure," this category covers failures related to protecting data in transit and at rest. Common issues include using weak algorithms, hardcoding secrets, or transmitting data over HTTP.
Example: Storing Passwords in Plaintext
# Vulnerable: Plaintext password storage
user.password = request.form['password']
db.save(user)
If the database is breached, all passwords are exposed.
Mitigation
- Use strong, adaptive hashing algorithms like bcrypt, scrypt, or Argon2.
- Encrypt sensitive data at rest and in transit (TLS).
- Never hardcode secrets; use environment variables or secret managers.
3. Injection
Injection flaws occur when untrusted data is sent to an interpreter as part of a command or query. SQL injection, NoSQL injection, OS command injection, and ORM injection are all too common.
Example: SQL Injection
// Vulnerable: String concatenation
const query = "SELECT * FROM users WHERE username = '" + username + "'";
db.query(query);
An attacker can input ' OR '1'='1 to bypass authentication.
Mitigation
- Use parameterized queries or prepared statements.
- Use an ORM correctly (avoid raw queries with concatenation).
- Validate and sanitize all input on the server side.
4. Insecure Design
Insecure design refers to missing or ineffective security controls in the design phase. It's not about implementation bugs but architectural flaws.
Example: No Rate Limiting on Login
Without rate limiting, attackers can brute-force passwords or perform credential stuffing.
Mitigation
- Threat modeling during design.
- Implement rate limiting, account lockout, and CAPTCHA.
- Use secure design patterns and reference architectures.
5. Security Misconfiguration
This is the most common issue—default accounts, unnecessary features enabled, verbose error messages, missing security headers, etc.
Example: Exposing Stack Traces
app.use((err, req, res, next) => {
res.status(500).send(err.stack); // Leaks sensitive info
});
Mitigation
- Harden your servers: disable default accounts, remove unused services.
- Use security headers (CSP, HSTS, X-Content-Type-Options).
- Automate configuration checks with tools like OWASP ZAP or Docker Bench.
6. Vulnerable and Outdated Components
Using libraries, frameworks, or software with known vulnerabilities is a major risk. Attackers exploit unpatched systems.
Example: Using an Old Version of Lodash
Older versions of Lodash had prototype pollution vulnerabilities.
Mitigation
- Regularly update dependencies.
- Use tools like
npm audit, OWASP Dependency-Check, or Snyk. - Remove unused dependencies.
7. Identification and Authentication Failures
Weak authentication mechanisms allow attackers to compromise passwords, keys, or session tokens.
Example: Predictable Session IDs
// Vulnerable: Session ID based on timestamp
const sessionId = Date.now().toString();
Attackers can guess or brute-force session IDs.
Mitigation
- Use strong, random session IDs.
- Implement multi-factor authentication (MFA).
- Enforce password policies and limit login attempts.
8. Software and Data Integrity Failures
This category focuses on code and infrastructure that doesn't protect against integrity violations—like using untrusted CDNs, insecure deserialization, or CI/CD pipelines without integrity checks.
Example: Insecure Deserialization
// Vulnerable: Deserializing untrusted data
$data = unserialize($_COOKIE['data']);
Attackers can inject malicious objects leading to remote code execution.
Mitigation
- Avoid deserializing untrusted data; use safe formats like JSON.
- Verify integrity of software and data (digital signatures, checksums).
- Secure your CI/CD pipeline with proper access controls.
9. Security Logging and Monitoring Failures
Without adequate logging and monitoring, breaches go undetected. This includes missing logs, unclear logs, or not monitoring them.
Example: No Logging of Failed Logins
Brute-force attacks go unnoticed.
Mitigation
- Log authentication events, access control failures, and input validation failures.
- Ensure logs are stored securely and monitored.
- Set up alerts for suspicious activities.
10. Server-Side Request Forgery (SSRF)
SSRF occurs when an attacker can make the server perform requests to internal resources. This can lead to data leakage or internal network scanning.
Example: Fetching a URL from User Input
// Vulnerable: Fetches any URL
app.get('/fetch', (req, res) => {
fetch(req.query.url).then(data => res.send(data));
});
An attacker can request internal metadata endpoints (e.g., http://169.254.169.254/).
Mitigation
- Validate and sanitize URLs; use allowlists.
- Disable unnecessary URL schemas (e.g.,
file://,gopher://). - Use network segmentation and least privilege.
Comparison Table: OWASP Top 10 at a Glance
| Risk | Common Example | Quick Mitigation |
|---|---|---|
| Broken Access Control | IDOR | Server-side access checks |
| Cryptographic Failures | Plaintext passwords | Use bcrypt/Argon2 |
| Injection | SQL injection | Parameterized queries |
| Insecure Design | No rate limiting | Threat modeling |
| Security Misconfiguration | Stack traces | Harden configs |
| Vulnerable Components | Old Lodash | Regular updates |
| Auth Failures | Weak session IDs | MFA, strong IDs |
| Integrity Failures | Insecure deserialization | Use JSON, verify signatures |
| Logging Failures | No failed login logs | Centralized logging |
| SSRF | Fetching internal URLs | URL allowlists |
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). It serves as a baseline for developers and security professionals to prioritize security efforts.
How often is the OWASP Top 10 updated?
OWASP updates the list every few years based on data from security firms and community feedback. The most recent version is from 2021, with a new release expected in the coming years.
Can I use the OWASP Top 10 as a checklist?
While it's a great starting point, the OWASP Top 10 is not exhaustive. It's meant to raise awareness and guide prioritization. For a comprehensive security program, combine it with other OWASP resources like the Application Security Verification Standard (ASVS) and proactive controls.
Want to quickly analyze your Nginx logs for signs of attacks like SQL injection or brute force? Try our Nginx Log Analyzer to visualize and detect suspicious patterns.