# 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.

  ```java
  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.

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

## References

* [**OWASP Log Injection**](https://owasp.org/www-community/attacks/Log_Injection)
* [**OWASP logging cheat sheet**](https://cheatsheetseries.owasp.org/cheatsheets/Logging_Cheat_Sheet.html)
* [**CWE-117: Improper Output Neutralization for Logs**](https://cwe.mitre.org/data/definitions/117.html)
* [**OWASP Top 10: A09:2021 - Security Logging and Monitoring Failures**](https://owasp.org/Top10/A09_2021-Security_Logging_and_Monitoring_Failures/)

## 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**](https://scopy.sec1.io/login)
