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


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.sec1.io/user-docs/4-sast/2-java/unsanitized-user-input-in-logger-message.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
