Lesson 15 of 19 · 16m
Logging and Detection That See Attacks
Log the security decision, not the secret — what to capture, what to exclude, shipping logs off-box, and alerting on shape instead of volume.
The breach report lands on a Tuesday and the first question is always the same: when did it start? The honest answer in most organizations is "we don't know — the logs rotated," or worse, "the attacker deleted them." Mandiant's M-Trends reports have tracked global median dwell time for over a decade; it has fallen from hundreds of days in 2011 to roughly ten days in the 2024 report — and "ten days" is still ten days of an attacker walking around inside systems that saw nothing, because nothing was watching.
OWASP calls this A09, Security Logging and Monitoring Failures. The wrong mental model: logging is a debugging tool you add when things break. For security, logging is the only instrument that can tell you the application did exactly what it was designed to do and it was still an attack. A successful login with the right password is indistinguishable from a credential-stuffing hit — unless you log enough context to see the pattern.
What to actually log
The rule: log every event where a security decision was made, with enough context to reconstruct it.
{"ts":"2026-11-16T14:03:11Z","event":"auth.login.fail","ip":"203.0.113.9","user":"a@b.c","reason":"bad_password","request_id":"req_9f2…","ua":"curl/8.5.0","mfa":null}- Authentication: success and failure, MFA enrollment/verification/failure, password resets requested and completed, session creation and invalidation.
- Authorization: every denied request — not just the 403 page, the event, with which rule fired.
- Privilege changes: role grants, permission edits, admin actions, API key mints — the operations an attacker performs once inside.
- Boundary failures: input validation rejects at trust boundaries, CSRF token mismatches, CSP violation reports, upload rejections.
- Money and data movement: transfers, exports, bulk reads, deletions.
What stays out: passwords, session tokens, full card numbers, raw MFA codes, and any PII you don't need — logs get breached as reliably as databases do, and they get read by every engineer and vendor tool with access. A log line containing Authorization: Bearer … is a credential leak filed under "debugging."
Mechanics that matter
- Structured, not greppable. JSON lines with a schema —
ts,event,request_id,actor,ip,outcome— so queries work. Free-text logs are where investigations go to die. - Correlate. One
request_idminted at the edge, propagated through every log line and downstream call (W3Ctracecontextheaders if you're fancy), so "what did this session do" is one query, not an afternoon. - UTC timestamps, synchronized clocks. An incident reconstructed across five services with skewed clocks is archaeology.
- Ship logs off-box. If the box holds its own logs, the attacker's first act is
rm -rfor a quieter edit. Append-only sink — a logging service, a SIEM, even a separate object store with retention locking — so the system under attack cannot rewrite its own history.
Detection is the other half
Logs without alerting are a write-only database. Alert on shape, not volume: five failed logins on one account is noise; five hundred across five hundred accounts from one /24 in two minutes is credential stuffing. Impossible-travel logins (two countries, one account, one hour). New admin actions outside business hours. A sudden run of 403s on object IDs incrementing by one — that is IDOR enumeration, the pattern every first-lesson bug leaves behind. CSP violation reports are a free XSS tripwire.
Then test the alarms: run a drill where a colleague does something attack-shaped — ten failed logins, a bulk export — and confirm the page fires. An alerting rule that's never triggered in testing is a hope, not a control.
Try this
Pull your app's logs for the last 24 hours and answer three questions without opening a code file: who logged in, what failed, and what did the most recent admin action change. If any answer needs source access or guesswork, your logging is incomplete — and grep for password, token, and secret in the same log file while you're there.
Pitfalls
- Logging credentials — a session token in a log line is a breach inside a breach.
- Alert floods — a channel that pages hourly gets muted; tune for events that require a human decision.
- No retention plan — 7 days of logs can't reconstruct a 30-day intrusion; keep security logs longer than your anticipated detection time, not your disk budget.
- Clock skew — correlate events across services only if the timestamps mean the same thing everywhere.
Was this lesson helpful?
Keep reading
Related articles from the SudoSecurity blog.
Building a Production REST API With Node.js and Express
Build a REST API in Node.js and Express the way production systems need: input validation, JWT auth, refresh token rotation, status codes, rate limiting, idempotency keys, and centralized error handling.
Node.js Fixed 16 Flaws in One Release. Most of Them Live in HTTP/2 and TLS.
The November 11 Node.js security releases fix 16 CVEs across the 26, 24 and 22 lines, seven of them rated high. Nearly all sit in HTTP/2 and TLS, where a remote client can crash a server, leak memory, or get past per-host client-certificate checks.
Next.js Shipped Seven Advisories and Six of Them Are the Cache
The November 2026 Next.js security release patches seven issues, and six live in the new Cache Components layer, the feature meant to make your app faster by remembering more. Three hit self-hosted next start specifically: the ones Vercel's own platform quietly absorbs.
Forum Archaeology: Nulled vBulletin, XenForo, and the Missing Footer
I could spot a nulled forum in about four seconds, and it never stopped being funny. Here's why the copyright line gives it away, what a measured 97% of nulled add-ons actually contain, and why MyBB quietly became the smart choice for everyone who wanted the look without the paper trail.