Skip to content

Commit

Permalink
Merge pull request #1379 from orangetw/master
Browse files Browse the repository at this point in the history
enhanced path validation in Windows
  • Loading branch information
namusyaka authored Feb 11, 2018
2 parents d661739 + ba7af51 commit 6bcc6c3
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion rack-protection/lib/rack/protection/path_traversal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,17 @@ def cleanup(path)
encoding = path.encoding
dot = '.'.encode(encoding)
slash = '/'.encode(encoding)
backslash = '\\'.encode(encoding)
else
# Ruby 1.8
dot = '.'
slash = '/'
backslash = '\\'
end

parts = []
unescaped = path.gsub(/%2e/i, dot).gsub(/%2f/i, slash)
unescaped = path.gsub(/%2e/i, dot).gsub(/%2f/i, slash).gsub(/%5c/i, backslash)
unescaped = unescaped.gsub(backslash, slash)

unescaped.split(slash).each do |part|
next if part.empty? or part == dot
Expand Down

0 comments on commit 6bcc6c3

Please sign in to comment.