Security logging and alerting
| Field | Security concepts |
|---|---|
| CWE | CWE-778: Insufficient Logging; CWE-223: Omission of Security-relevant Information |
| OWASP Top 10 | A09:2025 Security Logging and Alerting Failures |
| Related | Audit logs, Personal data in logs, Log injection |
When a sign-in form rejects a wrong password, nothing remains of the rejection unless the application writes it down. A written record lets someone count, later, how many failures came from one address; an alert on that count reaches a person while the attempts are still coming in. Security logging is the recording of events that bear on an application's security, such as sign-ins, refused requests and permission changes, in a form a person or a program can search. Alerting is the rule that turns some of those records into a message to a person while there is still time to act.
Events worth recording
The usual minimum is every sign-in success and failure, every refused access check, every rejected input on the server, failures of sessions such as a tampered cookie, application errors, and the start and stop of the application and of its logging.1 A common gap is an application that records successful sign-ins and drops the failed ones, which are the events that show Brute-force attack, Credential stuffing and Password spraying.2 The patterns to watch in those failures are repeats against one account, attempts from many addresses, and sudden bursts.1
A rejected value from a fixed list, such as a country that is not in the dropdown, is suspicious but not proof: a broken client or a confused user sends the same request. Its weight comes from repetition and from what else the same visitor did.1 Errors belong in the log as well. Code that swallows an exception never learns that something went wrong and so has nothing to record, which ties logging to Error handling and stack traces.2
| Event | Recorded when |
|---|---|
authn_login_fail_max | An account reaches its limit of failed sign-ins |
authn_impossible_travel | One account signs in from two places too far apart for the time between them |
authz_admin | An administrator does anything |
excess_rate_limit_exceeded | A caller passes an agreed request ceiling |
malicious_excess_404 | One visitor asks for many files that do not exist |
Contents of an entry
Each entry answers when, where, who and what.1 A shared vocabulary of event names makes those answers searchable across services; its format writes times in ISO 8601 with the UTC offset and puts the event type and the user in one field:3
{
"datetime": "2026-11-22T14:03:11+00:00",
"appid": "shop.auth",
"event": "authn_login_fail_max:user_4821,5",
"level": "WARN",
"source_ip": "203.0.113.10",
"request_uri": "/api/auth/login",
"request_method": "POST"
}An interaction identifier on every entry links all the events of one request, so they need not be pieced together later by timestamp, and the clocks of all servers are kept in sync for the same reason.1 Traffic from search engine robots, uptime monitors and penetration testers stays in the log with a flag that marks it.1 Passwords, tokens and most personal data stay out, as covered in Personal data in logs; an IP address combined with other data can count as personal data that privacy law covers.3 Text taken from a request is encoded before it is written, the subject of Log injection.2 A log that a visitor can read or download leaks everything in it, so log files stay out of the web server's public folders.2 Security events are usually kept apart from the business record of who changed what, which is the subject of Audit logs.1
From records to alerts
A missing log line produces no error and no visible bug, so testing rarely finds one. Only 723 CVEs map to the category in the 2025 OWASP Top 10. It keeps its place because practitioners voted it in through the community survey, for the third time, and the 2025 edition added alerting to its name.2 An alert is a query over the log with a threshold and a recipient. The threshold is the hard part. Rules copied from a checklist produce "alarm fog", in which real problems go unnoticed among routine ones,1 and a team that receives too many false alarms notices the true one late or never.2 Of the events in Table 1, the vocabulary rates a reached sign-in limit and a passed request ceiling as warnings and impossible travel as critical. The request ceiling earns an alert for cost alone, as Denial of wallet shows.3 A honeytoken, such as a fake row in the users table, gives alerts with almost no false alarms, because normal work never touches it.2
Running a DAST scan or a penetration test against the application tests the alerts directly, since either one should set some off.2 A separate check notices when logging itself stops.1 Each alert also needs a written, current playbook for the person who receives it.2 If log data drives automatic action, such as Account lockout, an attacker who sets it off on purpose can lock other users out.1
Retention and storage
Logs kept only on the machine that wrote them are lost with it.2 Hosting platforms keep their own logs briefly. Vercel holds runtime logs for 1 hour on the Hobby plan, 1 day on Pro and 30 days with Observability Plus,4 and Supabase keeps API and database logs for 1 day on Free, 7 days on Pro, 28 on Team and 90 on Enterprise.5 An intrusion found weeks later cannot be traced in logs that expired after a day, so applications forward events to a central store.1 Logs are kept for the required retention period and deleted after it, and their growth is capped, because logs that fill the disk can take the application down with them.1
Equifax, 2017
In July 2017 Equifax found that attackers had entered its online dispute portal; the personal data of at least 145.5 million people was reached, and the company's own investigation named detection as one of four factors.6 An expired certificate had disabled its intrusion detection system for 19 months. The attacker spent weeks moving through the network, and the mass copying of data was seen only once the certificate was renewed.7
Prompt for a coding agent
Add security event logging to this application. Write one structured JSON line for each sign-in success and failure, each refused permission check, each rejected input on the server, each administrator action and each unhandled error. Include an ISO 8601 time with UTC offset, an event name such as authn_login_success, the user id, the source IP, the request path and method, and a request id. Never write passwords, tokens, session ids, API keys or full request bodies. Encode newlines and control characters in any value taken from the request. List each place you added logging, and suggest alert thresholds for failed sign-ins and administrator actions.
In SecFlash
SecFlash reports SF-SRV-411 on the Server page when Docker keeps container logs with no size limit, and SF-EXP-411 on the Exposure page when a log, backup or settings file can be downloaded from the web server.
See also
- Audit logs
- Personal data in logs
- Log injection
- Brute-force attack
- SSH brute-force attack
- Rogue administrator account
- Responding to an administrator account takeover
- OWASP Top 10
References
- a b c d e f g h i j k l "Logging Cheat Sheet". OWASP Cheat Sheet Series.
- a b c d e f g h i j "A09:2025 Security Logging and Alerting Failures". OWASP Top 10:2025. OWASP Foundation.
- a b c "Application Logging Vocabulary Cheat Sheet". OWASP Cheat Sheet Series.
- back "Runtime Logs". Vercel Docs. Vercel.
- back "Logging". Supabase Docs. Supabase.
- back U.S. Government Accountability Office (30 August 2018). "Data Protection: Actions Taken by Equifax and Federal Agencies in Response to the 2017 Breach" (GAO-18-559). GAO.
- back Nichols, Shaun (11 December 2018). "Equifax how-it-was-mega-hacked damning dossier lands, in all of its infuriating glory". The Register.
External links
- Logging Cheat Sheet, OWASP Cheat Sheet Series