Logs are often used for debugging and monitoring, but if they contain sensitive data such as passwords, API keys, credit card numbers, or personal details, they become a liability. Attackers who gain access to log files can harvest this data and use it for fraud or account takeover.
Sanitizing logs ensures only safe, useful information is recorded. By redacting or removing sensitive values before writing them, you keep logs helpful for troubleshooting without creating a new source of data leakage. This also supports compliance with privacy regulations like GDPR and PCI DSS.
# Review log files for sensitive data
grep -R "password" var/log
grep -R "token" var/log
grep -R "card" var/log
# Review custom code for logging raw request/response data
// Unsafe logging
$this->logger->info("Login failed for user $email with password $password");
// Safe logging
$this->logger->info("Login failed for user $email");
// Password not included