Unsanitized user input in format string

Description

Unsanitized user input in format string can lead to security vulnerabilities. This issue arises when user input is directly incorporated into a format string, enabling attackers to manipulate the output through format specifiers, resulting in misleading or fabricated messages.

Remediations

  • Do not include user input directly in format strings. This approach can be exploited by attackers to manipulate the output.
    sprintf("The value was ${_GET["value"]}"); // unsafe
  • Do use a literal format string with user input as separate arguments. This method helps prevent attackers from influencing the format of the output.
    sprintf("The value was %s", $_GET["value"]);

References

Associated CWE

Configuration

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

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

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

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