Do not use user input to form file paths.
- Rule ID: ruby_lang_path_using_user_input
- Languages: ruby
- Source: path_using_user_input.yml
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
- CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')
- CWE-73: External Control of File Name or Path
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
Ready to take the next step? Learn more about Bearer Cloud.