Unsanitized user input in format string

Description

Including user input directly in a format string can lead to security vulnerabilities. Attackers might exploit these format strings to generate misleading or fabricated messages by inserting format specifiers into the user input.

Remediations

  • Do not include user input directly in format strings. This approach is vulnerable to manipulation by attackers.
    sprintf("The value was #{params[:value]}") # unsafe
  • Do use a literal format string with user input as separate arguments. This method prevents attackers from exploiting the format string.
    sprintf("The value was %s", params[:value])

Associated CWE

Configuration

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

bearer scan /path/to/your-project/ --skip-rule=ruby_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=ruby_lang_format_string_using_user_input