From b93c590297ba65a6c5b18655a7790163abcb06f1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jos=C3=A9=20Valim?= <jose.valim@gmail.com>
Date: Sun, 28 Nov 2010 22:26:16 +0100
Subject: Ensure render is case sensitive even on systems with case-insensitive
 filesystems.

This fixes CVE-2011-0449
---
 actionpack/lib/action_view/template/resolver.rb | 15 ++++++++++++---
 actionpack/test/controller/render_test.rb       | 10 ++++++++++
 2 files changed, 22 insertions(+), 3 deletions(-)

diff --git a/actionpack/lib/action_view/template/resolver.rb b/actionpack/lib/action_view/template/resolver.rb
index d23aa5ef85..5bf928c62e 100644
--- a/actionpack/lib/action_view/template/resolver.rb
+++ b/actionpack/lib/action_view/template/resolver.rb
@@ -113,14 +113,23 @@ module ActionView
         query << '{' << ext.map {|e| e && ".#{e}" }.join(',') << ',}'
       end
 
-      Dir[query].reject { |p| File.directory?(p) }.map do |p|
-        handler, format = extract_handler_and_format(p, formats)
+      query.gsub!(/\{\.html,/, "{.html,.text.html,")
+      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 }
 
-        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))
       end
+
+      templates
     end
 
     # Returns the file mtime from the filesystem.
diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb
index fca8de60bc..be492152f2 100644
--- a/actionpack/test/controller/render_test.rb
+++ b/actionpack/test/controller/render_test.rb
@@ -125,6 +125,10 @@ class TestController < ActionController::Base
     render :action => "hello_world"
   end
 
+  def render_action_upcased_hello_world
+    render :action => "Hello_world"
+  end
+
   def render_action_hello_world_as_string
     render "hello_world"
   end
@@ -742,6 +746,12 @@ class RenderTest < ActionController::TestCase
     assert_template "test/hello_world"
   end
 
+  def test_render_action_upcased
+    assert_raise ActionView::MissingTemplate do
+      get :render_action_upcased_hello_world
+    end
+  end
+
   # :ported:
   def test_render_action_hello_world_as_string
     get :render_action_hello_world_as_string
-- 
cgit v1.2.3