Security logging and audit trails for auth events
Why it matters
Without audit logs for authentication events, you cannot detect an ongoing attack, reconstruct a breach timeline, or satisfy incident response obligations. CWE-778 (Insufficient Logging) and OWASP A09 (Security Logging and Monitoring Failures) document that undetected breaches are the norm, not the exception, for applications with no auth logging. NIST 800-53 AU-2 requires auditable events to include logon attempts, account changes, and authorization failures. A password reset initiated by an attacker, account lockouts triggered by credential stuffing, or privilege escalation — none of these are visible without structured, persistent auth event logging.
Severity rationale
Info because missing auth logs don't cause a breach, but they guarantee that any breach — in progress or completed — goes undetected and unrecoverable.
Remediation
Log auth events to a persistent database table with timestamp, event type, user ID, and IP address:
// lib/audit-log.ts
type AuditEvent =
| 'auth.login.success' | 'auth.login.failure'
| 'auth.logout' | 'auth.account_locked'
| 'auth.password_reset.requested' | 'authz.forbidden'
export async function logAuditEvent(
event: AuditEvent,
ctx: { userId?: string; email?: string; ip: string }
) {
await db.auditLog.create({
data: { event, userId: ctx.userId ?? null, ipAddress: ctx.ip, createdAt: new Date() },
})
}
// In login handler:
await logAuditEvent('auth.login.failure', { email, ip })
Do not rely on console.log — container restarts discard stdout. Log to a database table or a structured logging service (Axiom, Datadog) with at least 90-day retention.
DetectionPro
The detection method for this pattern is part of AuditBuffet Pro.
The full method (what to look for, pass and fail conditions, and how results get reported) ships inside the Security Hardening Audit. The pattern definition, severity rationale, and remediation remain openly licensed under CC-BY-4.0.
External references
- cwe · CWE-778 — Insufficient Logging
- owasp:2021 · A09 — Security Logging and Monitoring Failures
- nist:rev5 · AU-2 — Event Logging
- soc2:2017 · CC7.2 — Monitoring for anomalous system activity
Taxons
History
- 2026-04-18·v1.0.0·Initial import from security-hardening·automated
- 2026-07-06·v1.0.1·Add SOC 2 TSC mapping (CC7.2) from the verified compliance crosswalk register (docs/compliance/).·by soc2-mapping-enrichment-ship-2