Prevented attack |
Directory traversal |
Supported browsers |
all |
More infos |
Unescapes ‘/’ and ‘.’, expands path_info. Thus GET /foo/%2e%2e%2fbar becomes GET /bar.
# File lib/rack/protection/path_traversal.rb, line 13 def call(env) path_was = env["PATH_INFO"] env["PATH_INFO"] = cleanup path_was if path_was && !path_was.empty? app.call env ensure env["PATH_INFO"] = path_was end
# File lib/rack/protection/path_traversal.rb, line 21 def cleanup(path) if path.respond_to?(:encoding) # Ruby 1.9+ M17N encoding = path.encoding dot = '.'.encode(encoding) slash = '/'.encode(encoding) else # Ruby 1.8 dot = '.' slash = '/' end parts = [] unescaped = path.gsub(/%2e/, dot).gsub(/%2f/, slash) unescaped.split(slash).each do |part| next if part.empty? or part == dot part == '..' ? parts.pop : parts << part end cleaned = slash + parts.join(slash) cleaned << slash if parts.any? and unescaped =~ %{/\.{0,2}$} cleaned end
Generated with the Darkfish Rdoc Generator 2.