← PHP / Laravel · Contents

PHP-042 / Intermediate

Logging passwords, tokens or personal data and log injection

A09:2021 Security Logging and Monitoring Failures · CWE-532 Sensitive Info in Log · CWE-117 Log Neutralization

Why is this a problem?

Secrets remain in log files, and newline insertion enables forged logs.

How to fix it

php
Log::info('login', ['email' => $request->email, 'ip' => $request->ip()]);
// Remove control characters: str_replace(["\r", "\n"], ' ', $value)

Further reading