← Java / Spring · Contents

JAVA-040 / Intermediate

Log injection: logging user-supplied newlines

A09:2021 Security Logging and Monitoring Failures · CWE-117 Log Neutralization · CWE-93

Why is this a problem?

A newline (\n) can create forged log lines.

How to fix it

java
log.info("login failed user={}", sanitize(id));   // Remove newlines and control characters; bind parameters

Further reading