Log injection detected.

Description

Writing invalidated user input to log files can allow an attacker to forge log entries or inject malicious content into the logs. This rule looks for instances of user input sent to loggers.

Remediations

❌ Avoid using unsanitized user input in logger messages:

 String username = request.getParameter("username");
log.warn("Username is" + username);

✅ If you need to identify a user, use their unique identifier instead of their personal identifiable information:

 String username = sanitized(request.getParameter("username"));
log.warn("Username is" + username);

Resources

Associated CWE

OWASP Top 10

Configuration

To skip this rule during a scan, use the following flag

bearer scan /path/to/your-project/ --skip-rule=java_lang_log_injection

To run only this rule during a scan, use the following flag

bearer scan /path/to/your-project/ --only-rule=java_lang_log_injection

Ready to take the next step? Learn more about Bearer Cloud.