A07: Authentication Failures
Authentication failures occur when attackers can compromise passwords, keys, or session tokens, or exploit implementation flaws to assume other users' identities temporarily or permanently.
Key Vulnerabilities
Permitting brute force and credential stuffing attacks
Allowing weak or well-known passwords (e.g., 'password123')
Using weak credential recovery processes (knowledge-based answers)
Storing passwords in plain text or using weak hashing
Missing or ineffective multi-factor authentication
Exposing session identifiers in URLs
Prevention Strategies
Implement multi-factor authentication (MFA)
Never ship with default credentials
Check passwords against breached password lists (Have I Been Pwned)
Enforce password length, complexity, and rotation policies
Limit and delay failed login attempts
Use server-side, secure session manager with random session IDs
Real-World Example
In 2019, credential stuffing attacks using previously breached passwords affected millions of accounts across streaming services, food delivery, and retail platforms.
Code Comparison
// VULNERABLE: No brute-force protection, weak session
app.post('/login', (req, res) => {
const user = db.findUser(req.body.email);
if (user.password === req.body.password) { // Plain text!
res.cookie('session', user.id); // Predictable!
res.json({ success: true });
}
});// SECURE: Rate limiting, bcrypt, secure sessions
app.post('/login', loginLimiter, async (req, res) => {
const user = db.findUser(req.body.email);
if (!user) return res.status(401).json({
error: 'Invalid credentials' // Generic message
});
const valid = await bcrypt.compare(req.body.password, user.hash);
if (!valid) { recordFailedAttempt(user.id); return; }
req.session.regenerate(); // New session ID
req.session.userId = user.id;
});