Application logging: what to record, what never to put in logs
Choose useful application security events to log while keeping credentials, tokens and sensitive payment data out of logs.
Logs help you debug problems and notice attacks. OWASP's Logging Cheat Sheet (https://cheatsheetseries.owasp.org/cheatsheets/Logging_Cheat_Sheet.html) focuses on application logging, especially security logging. It says many systems enable web server and database logs, but custom application event logging is often missing, disabled or poorly configured, and that application logs give much more insight than infrastructure logs alone.
Why log
OWASP says application logging should be included for security events, and that logs serve operational uses (debugging, baselines, business process monitoring) and security uses.
What to log
OWASP says what to log should be proportionate to risk and decided in design, and warns that a blind checklist can create "alarm fog" where real problems go undetected. Where possible it recommends logging, among others:
- input validation failures, which it says to treat as suspicious events, not proof of an attack
- authentication successes and failures (repeated failures can indicate brute-force or credential-stuffing attempts)
- authorization failures and session management failures
- application errors and system events, including configuration changes
- use of higher-risk functions: user administration, admin access, access to sensitive data, key rotation, data import and export, file uploads
- opt-ins such as consent and terms acceptance
- suspicious business-logic activity, such as steps out of order
What to keep out
OWASP says to never log data unless it is legally sanctioned. It lists items that should usually not be recorded directly but removed, masked, sanitized, hashed or encrypted: source code, session ID values, access tokens, sensitive personal data, passwords, database connection strings, encryption keys, bank account or card data, commercially sensitive information, and information a user has not consented to or has opted out of. It suggests de-identification techniques where a person's identity is not needed. What is legal to log depends on your jurisdiction; ask qualified counsel. We have not researched Indian rules.
Protect the logs
OWASP describes log injection: if untrusted data is written into a log message, an attacker may be able to add a fake entry, for example with line-break characters. OWASP recommends sanitizing event data, including line breaks and delimiters, and encoding it correctly for the output format. Our practical suggestion is bounded structured logging with a suitable encoder. JSON-shaped text alone does not prevent injection if values are concatenated unsafely.
Questions for your developer
- Which security events do we log today?
- Do any logs contain passwords, tokens, session IDs or personal data?
- Are logs structured, and is user input sanitized before logging?
- Who reads logs, and how long are they kept (confirm retention with counsel)?
Limits
We did not read OWASP's sections on event attributes, network architecture, retention or log integrity in detail. This is awareness material, not a compliance assurance.
By Omnistu.