Security Logging and Alerting Failures
Attacks happen and nobody notices, or the logs leak secrets.
What it is
Logging is how you find out you were attacked. It fails when important events (failed logins, access denied) aren't recorded, nobody is alerted, or the logs themselves contain passwords and tokens.
What can happen
- Breaches go unnoticed for months.
- No trail to understand what happened afterwards.
- Passwords in logs leak to anyone who can read them.
Example: What to log
// Logs the password, and says nothing on failure.
console.log("login", req.body);
if (!ok) return res.status(401).json({ error: "Invalid login" });if (!ok) {
logger.warn({ event: "login_failed", email, ip: req.ip });
return res.status(401).json({ error: "Invalid login" });
}
logger.info({ event: "login_ok", userId: user.id });Log who, what, when and from where. Never passwords, tokens or full cookies.
How to prevent it
- Log logins, failures, access-denied and admin actions.
- Use structured logs (JSON) so they can be searched.
- Alert on spikes, for example 100 failed logins in a minute.
- Redact secrets before writing a log line.
What CrimsonScan checks
Needs a code reviewNot visible from outside. A scanner can't know whether your server logged its requests. This is a code and operations review item.