Do not use user input to form file paths.

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