diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2014-10-10 16:00:03 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2014-10-29 11:22:08 -0700 |
commit | 3437f260a5903b651bf8b8f751345fb288fa9052 (patch) | |
tree | ce8f727e925959328b390de5b763176376b37b0e /actionpack/lib/action_dispatch | |
parent | 53c845cb185036c71cc9793c4eb6bf4dc989307b (diff) | |
download | rails-3437f260a5903b651bf8b8f751345fb288fa9052.tar.gz rails-3437f260a5903b651bf8b8f751345fb288fa9052.tar.bz2 rails-3437f260a5903b651bf8b8f751345fb288fa9052.zip |
FileHandler should not be called for files outside the root
FileHandler#matches? should return false for files that are outside the
"root" path.
Conflicts:
actionpack/lib/action_dispatch/middleware/static.rb
Conflicts:
actionpack/lib/action_dispatch/middleware/static.rb
actionpack/test/dispatch/static_test.rb
Diffstat (limited to 'actionpack/lib/action_dispatch')
-rw-r--r-- | actionpack/lib/action_dispatch/middleware/static.rb | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/actionpack/lib/action_dispatch/middleware/static.rb b/actionpack/lib/action_dispatch/middleware/static.rb index a8d176560c..7f1117009d 100644 --- a/actionpack/lib/action_dispatch/middleware/static.rb +++ b/actionpack/lib/action_dispatch/middleware/static.rb @@ -12,7 +12,7 @@ module ActionDispatch def match?(path) path = path.dup - full_path = path.empty? ? @root : File.join(@root, escape_glob_chars(unescape_path(path))) + full_path = path.empty? ? @root : File.join(@root, escape_glob_chars(clean_path_info(unescape_path(path)))) paths = "#{full_path}#{ext}" matches = Dir[paths] @@ -42,6 +42,25 @@ module ActionDispatch path.force_encoding('binary') if path.respond_to? :force_encoding path.gsub(/[*?{}\[\]]/, "\\\\\\&") end + + private + + PATH_SEPS = Regexp.union(*[::File::SEPARATOR, ::File::ALT_SEPARATOR].compact) + + def clean_path_info(path_info) + parts = path_info.split PATH_SEPS + + clean = [] + + parts.each do |part| + next if part.empty? || part == '.' + part == '..' ? clean.pop : clean << part + end + + clean.unshift '/' if parts.empty? || parts.first.empty? + + ::File.join(*clean) + end end class Static |