Unsanitized user input in file path

Description

Using raw unsanitized input when forming filenames or file paths is bad practice. It can lead to path manipulation, by which attackers can gain access to resources outside of the intended scope.

Remediations

❌ Avoid wherever possible

✅ Validate expected file paths using File methods

  path = File.expand("/home/" + params[:resource_name])
if path.starts_with?("/home/")
Dir.chdir(path)
else
# path is unexpected
end

Resources

Associated CWE

OWASP Top 10

Configuration

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

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