OWASP Top 10 Explained with Practical Examples
Why the OWASP Top 10 Still Matters
You've built a web app, and it works. But have you checked it against the most common security pitfalls? The OWASP Top 10 is a list of the most critical web application security risks, maintained by the Open Worldwide Application Security Project. It's not a standard, but a guide to what attackers exploit most. In this article, we'll walk through each risk with practical examples and concrete fixes.
Whether you're a developer, DevOps engineer, or security tester, understanding these risks helps you write safer code and configure systems more securely. Let's dive in.
1. Broken Access Control
Access control enforces policy such that users cannot act outside of their intended permissions. Failures typically lead to unauthorized information disclosure, modification, or destruction of data.
Example: A user can change a URL parameter to access another user's account: https://example.com/account?id=123 → ?id=124. If the server doesn't verify that the logged-in user owns account 123, it's a broken access control.
Fix: Always enforce access control on the server side. Use session-based checks and deny by default.
// Insecure
app.get('/account', (req, res) => {
const account = getAccount(req.query.id);
res.json(account);
});
// Secure
app.get('/account', (req, res) => {
if (req.user.id !== req.query.id) return res.status(403).send('Forbidden');
const account = getAccount(req.query.id);
res.json(account);
});
2. Cryptographic Failures
Previously known as "Sensitive Data Exposure," this risk focuses on failures related to cryptography that lead to exposure of sensitive data.
Example: Storing passwords in plaintext or using weak hashing algorithms like MD5 or SHA1.
Fix: Use strong, slow hashing algorithms like bcrypt or Argon2. Encrypt sensitive data at rest and in transit (HTTPS).
// Insecure
const hash = md5(password);
// Secure
const bcrypt = require('bcrypt');
const hash = await bcrypt.hash(password, 12);
3. Injection
Injection flaws occur when untrusted data is sent to an interpreter as part of a command or query. Common types include SQL, NoSQL, OS command, and ORM injection.
Example: A login form that concatenates user input into a SQL query:
String query = "SELECT * FROM users WHERE username = '" + username + "' AND password = '" + password + "'";
An attacker could enter ' OR '1'='1 to bypass authentication.
Fix: Use parameterized queries or prepared statements.
String query = "SELECT * FROM users WHERE username = ? AND password = ?";
PreparedStatement stmt = connection.prepareStatement(query);
stmt.setString(1, username);
stmt.setString(2, password);
For more on SQL injection prevention, see our dedicated guide.
4. Insecure Design
Insecure design refers to missing or ineffective control design. It's not about implementation bugs but architectural flaws.
Example: A password recovery system that uses security questions, which can be easily guessed or researched.
Fix: Threat modeling during design, use secure design patterns, and reference catalogs like OWASP ASVS.
5. Security Misconfiguration
This is the most common issue, often resulting from default configurations, incomplete configurations, or verbose error messages.
Example: Leaving directory listing enabled on a web server, exposing sensitive files.
Fix: Harden configurations: disable directory listing, remove default accounts, and use minimal base images.
# Nginx: disable autoindex
autoindex off;
Regularly review your server logs for anomalies. Tools like the Nginx Log Analyzer can help spot unusual patterns.
6. Vulnerable and Outdated Components
Using components with known vulnerabilities undermines your app's defenses.
Example: Running an old version of a library like jQuery with a known XSS vulnerability.
Fix: Maintain an inventory of dependencies, monitor for vulnerabilities (e.g., using Dependabot), and remove unused dependencies.
7. Identification and Authentication Failures
Weaknesses in authentication and session management allow attackers to compromise passwords, keys, or session tokens.
Example: Allowing weak passwords like "123456" or not invalidating sessions after logout.
Fix: Implement multi-factor authentication, enforce strong password policies, and use secure session management.
8. Software and Data Integrity Failures
This risk relates to code and infrastructure that does not protect against integrity violations.
Example: Deserializing untrusted data without verification, leading to remote code execution.
Fix: Verify digital signatures, use integrity checks, and avoid deserializing untrusted data.
9. Security Logging and Monitoring Failures
Insufficient logging and monitoring allows breaches to go undetected.
Example: Not logging failed login attempts, so brute force attacks go unnoticed.
Fix: Log authentication events, monitor logs, and set up alerts for suspicious activities.
10. Server-Side Request Forgery (SSRF)
SSRF flaws occur when a web app fetches a remote resource without validating the user-supplied URL.
Example: A feature that fetches an image from a URL: /fetch?url=http://169.254.169.254/latest/meta-data/ could expose cloud metadata.
Fix: Validate and sanitize URLs, use allowlists, and restrict network access.
Comparison Table: Risk vs. Mitigation
| Risk | Example | Mitigation |
|---|---|---|
| Broken Access Control | Changing user ID in URL | Server-side checks |
| Cryptographic Failures | Plaintext passwords | Use bcrypt/Argon2 |
| Injection | SQL injection via input | Parameterized queries |
| Security Misconfiguration | Directory listing enabled | Harden configs |
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 Worldwide Application Security Project. It serves as a baseline for developers and security professionals.
How often is the OWASP Top 10 updated?
It is updated periodically, typically every few years, to reflect changes in the threat landscape. The latest version is from 2021, but always refer to the official OWASP website for the current list.
Is the OWASP Top 10 enough to secure my app?
While it covers major risks, it's not exhaustive. Use it as a starting point and complement it with other resources like OWASP ASVS and secure coding practices.
Ready to put this into practice? Start by scanning your code for injection flaws and misconfigurations. For a quick security check, try our Nginx Log Analyzer to spot suspicious requests that might indicate an attack.