Path traversal (ARCH6103)
Esta página aún no está disponible en tu idioma.
Key ruby.security.path-traversal · Severity error · Category security · CWE CWE-22
Building a file path from untrusted input without normalization and containment lets attackers escape the intended directory (../) and reach arbitrary files.
Incorrect
Section titled “Incorrect”def read(name) File.read(File.join("/var/data", name))endCorrect
Section titled “Correct”def read(name) base = File.expand_path("/var/data") path = File.expand_path(File.join(base, name)) raise "invalid path" unless path.start_with?("#{base}/") File.read(path)endResolve and normalize the path, then verify the result stays inside the allowed root directory.