# Unsanitized user input in format string detected

## Overview

* **Rule ID**: `java_lang_format_string_manipulation`
* **Applicable Languages**: Java
* **Weakness ID**: CWE-134

## Description

Using unsanitized user input as the format string in formatting functions can make your application vulnerable to attacks. This flaw allows attackers to create malicious format strings, potentially exposing unauthorized data or causing your application to crash.

## Remediation Guidelines

* **Avoid** using user input directly as the format string in formatting functions. This applies to any scenario where the first argument (or the second, if a locale is specified) should be a format string.

  ```java
  String.format(request.getParameter("foo"), "bar"); // unsafe
  String.format(Locale.US, request.getParameter("foo"), "bar"); // unsafe

  ```
* **Use** hard-coded format strings when working with formatting functions. This practice ensures that the format string is not affected by external input, reducing the risk of format string vulnerabilities.

  ```java
  String.format("Strings: %s", request.getParameter("foo"), "bar");
  String.format(Locale.US, "Strings: %s", request.getParameter("foo"), "bar");
  ```

## References

* [**OWASP Testing for Format String Injection**](https://owasp.org/www-project-web-security-testing-guide/stable/4-Web_Application_Security_Testing/07-Input_Validation_Testing/13-Testing_for_Format_String_Injection)
* [**CWE-134: Use of Externally-Controlled Format String**](https://cwe.mitre.org/data/definitions/134.html)

## 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-format-string-detected.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.
