Unsanitized user input in logger message

Overview

  • Rule ID: java_lang_log_injection

  • Applicable Languages: Java

  • Weakness ID: CWE-117

Description

Including unsanitized user input in log messages can lead to log forgery or malicious content injection. This vulnerability occurs when user input is incorporated into log entries without adequate sanitization.

Remediation Guidelines

  • Avoid including unsanitized user input in log messages, as this can enable attackers to manipulate log files or inject harmful content.

    String username = request.getParameter("username");
    log.warn("Username is " + username); // unsafe
    
    
  • Ensure to sanitize user input before logging it. This ensures that any data derived from user input is cleaned to prevent potential log injection attacks.

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

References

Configuration

To omit this rule during a scan, and to provide you with continuous 24/7 code-level scanning, you can employ our SAST TOOL

Last updated