1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Ensure render is case sensitive even on systems with case-insensitive filesystems.

This fixes CVE-2011-0449
This commit is contained in:
José Valim 2010-11-28 22:26:16 +01:00 committed by Aaron Patterson
parent 3ddd7f7ec9
commit b93c590297
2 changed files with 22 additions and 3 deletions

View file

@ -113,14 +113,23 @@ module ActionView
query << '{' << ext.map {|e| e && ".#{e}" }.join(',') << ',}' query << '{' << ext.map {|e| e && ".#{e}" }.join(',') << ',}'
end end
Dir[query].reject { |p| File.directory?(p) }.map do |p| query.gsub!(/\{\.html,/, "{.html,.text.html,")
handler, format = extract_handler_and_format(p, formats) query.gsub!(/\{\.text,/, "{.text,.text.plain,")
templates = []
sanitizer = Hash.new { |h,k| h[k] = Dir["#{File.dirname(k)}/*"] }
Dir[query].each do |p|
next if File.directory?(p) || !sanitizer[p].include?(p)
handler, format = extract_handler_and_format(p, formats)
contents = File.open(p, "rb") {|io| io.read } contents = File.open(p, "rb") {|io| io.read }
Template.new(contents, File.expand_path(p), handler, templates << Template.new(contents, File.expand_path(p), handler,
:virtual_path => path, :format => format, :updated_at => mtime(p)) :virtual_path => path, :format => format, :updated_at => mtime(p))
end end
templates
end end
# Returns the file mtime from the filesystem. # Returns the file mtime from the filesystem.

View file

@ -125,6 +125,10 @@ class TestController < ActionController::Base
render :action => "hello_world" render :action => "hello_world"
end end
def render_action_upcased_hello_world
render :action => "Hello_world"
end
def render_action_hello_world_as_string def render_action_hello_world_as_string
render "hello_world" render "hello_world"
end end
@ -742,6 +746,12 @@ class RenderTest < ActionController::TestCase
assert_template "test/hello_world" assert_template "test/hello_world"
end end
def test_render_action_upcased
assert_raise ActionView::MissingTemplate do
get :render_action_upcased_hello_world
end
end
# :ported: # :ported:
def test_render_action_hello_world_as_string def test_render_action_hello_world_as_string
get :render_action_hello_world_as_string get :render_action_hello_world_as_string