lowCWE-778A09:2021

Insufficient Security Logging

Not logging security events (failed logins, permission denials, suspicious actions) means you can't detect attacks in progress or reconstruct what happened after a breach.

How It Works

OWASP A09 — Security Logging and Monitoring Failures — is consistently in the top 10 because organizations can't detect breaches without the right logs. Without security event logs, a credential stuffing attack can run for weeks before anyone notices. Post-breach forensics becomes impossible.

Vulnerable Code
// BAD: authentication with no security event logging
export async function POST(req: Request) {
  const { email, password } = await req.json();
  const user = await validateCredentials(email, password);
  if (!user) return Response.json({ error: 'Invalid' }, { status: 401 });
  // No log of failed attempt — attacker is invisible
  return Response.json({ token: createToken(user) });
}
Secure Code
// GOOD: log security events with enough context to detect and investigate
export async function POST(req: Request) {
  const { email, password } = await req.json();
  const user = await validateCredentials(email, password);
  if (!user) {
    securityLog.warn({ event: 'login_failed', email, ip: getIP(req) });
    return Response.json({ error: 'Invalid credentials' }, { status: 401 });
  }
  securityLog.info({ event: 'login_success', userId: user.id, ip: getIP(req) });
  return Response.json({ token: createToken(user) });
}

Real-World Example

The 2013 Target breach went undetected for 3 weeks because their security monitoring wasn't configured to alert on the specific patterns of data exfiltration occurring. With proper logging and alerting, the breach could have been caught within hours.

How to Prevent It

  • Log all authentication events: login success, login failure, password reset, MFA events
  • Log all authorization failures: requests to resources the user doesn't have permission to access
  • Include IP address, user ID (not username/email), timestamp, and action in every security log
  • Set up alerts for anomalous patterns: >10 failed logins per minute, access from new countries

Affected Technologies

Node.js

Data Hogo detects this vulnerability automatically.

Scan Your Repo Free

Related Vulnerabilities