aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2016-01-20 10:39:19 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2016-01-22 15:02:27 -0800
commitb7758b40fc035a47f6843158155606d455314c42 (patch)
tree92e2bdb231a7dda8902e0563bdc98867098c298a /actionpack
parent0fde6f554b75b13b0435dd70f1c3ec02bc209e0d (diff)
downloadrails-b7758b40fc035a47f6843158155606d455314c42.tar.gz
rails-b7758b40fc035a47f6843158155606d455314c42.tar.bz2
rails-b7758b40fc035a47f6843158155606d455314c42.zip
allow :file to be outside rails root, but anything else must be inside the rails view directory
CVE-2016-0752
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/lib/abstract_controller/rendering.rb8
-rw-r--r--actionpack/test/controller/render_test.rb31
2 files changed, 38 insertions, 1 deletions
diff --git a/actionpack/lib/abstract_controller/rendering.rb b/actionpack/lib/abstract_controller/rendering.rb
index a73f188623..63fd76d9b7 100644
--- a/actionpack/lib/abstract_controller/rendering.rb
+++ b/actionpack/lib/abstract_controller/rendering.rb
@@ -82,7 +82,13 @@ module AbstractController
# <tt>render :file => "foo/bar"</tt>.
# :api: plugin
def _normalize_args(action=nil, options={})
- if action.is_a? Hash
+ case action
+ when ActionController::Parameters
+ unless action.permitted?
+ raise ArgumentError, "render parameters are not permitted"
+ end
+ action
+ when Hash
action
else
options
diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb
index 256ebf6a07..bbc216b52f 100644
--- a/actionpack/test/controller/render_test.rb
+++ b/actionpack/test/controller/render_test.rb
@@ -62,6 +62,16 @@ class TestController < ActionController::Base
end
end
+ def dynamic_render
+ render params[:id] # => String, AC:Params
+ end
+
+ def dynamic_render_with_file
+ # This is extremely bad, but should be possible to do.
+ file = params[:id] # => String, AC:Params
+ render file: file
+ end
+
class Collection
def initialize(records)
@records = records
@@ -243,6 +253,27 @@ end
class ExpiresInRenderTest < ActionController::TestCase
tests TestController
+ def test_dynamic_render_with_file
+ # This is extremely bad, but should be possible to do.
+ assert File.exist?(File.join(File.dirname(__FILE__), '../../test/abstract_unit.rb'))
+ response = get :dynamic_render_with_file, params: { id: '../\\../test/abstract_unit.rb' }
+ assert_equal File.read(File.join(File.dirname(__FILE__), '../../test/abstract_unit.rb')),
+ response.body
+ end
+
+ def test_dynamic_render
+ assert File.exist?(File.join(File.dirname(__FILE__), '../../test/abstract_unit.rb'))
+ assert_raises ActionView::MissingTemplate do
+ get :dynamic_render, params: { id: '../\\../test/abstract_unit.rb' }
+ end
+ end
+
+ def test_dynamic_render_file_hash
+ assert_raises ArgumentError do
+ get :dynamic_render, params: { id: { file: '../\\../test/abstract_unit.rb' } }
+ end
+ end
+
def test_expires_in_header
get :conditional_hello_with_expires_in
assert_equal "max-age=60, private", @response.headers["Cache-Control"]