brakeman
brakeman copied to clipboard
Rule for Pathname.join with forward slash.
Is your feature request related to a problem? Please describe.
Pathname.join
has a weird behavioral quirk where, if a string beginning with a /
is joined to the end of a pathname object, the entire pathname is removed up to the /
.
A developer might do something like this: Rails.root.join("safe_path", user_submitted_path)
thinking that the user only has control over the end of the path.
Describe the solution you'd like It would be nice to have a rule that detects this. Below is an example of what the issue looks like:
irb(main):012:0> Rails.root.join("safe_path", "a", "b", "c")
=> #<Pathname:/home/ryan/test/safe_path/a/b/c>
irb(main):013:0> Rails.root.join("safe_path", "a", "b", "/c")
=> #<Pathname:/c>