Skip to content

Commit

Permalink
Merge branch '3-0-stable-sec' into 3-0-stable-rel
Browse files Browse the repository at this point in the history
* 3-0-stable-sec:
  Array parameters should not contain nil values.
  Additional fix for CVE-2012-2661
  • Loading branch information
tenderlove committed Jun 11, 2012
2 parents 6c0c40b + 2f3bc04 commit b9e048c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
6 changes: 4 additions & 2 deletions actionpack/lib/action_dispatch/http/request.rb
Expand Up @@ -262,17 +262,19 @@ def local?

# Remove nils from the params hash
def deep_munge(hash)
keys = hash.keys.find_all { |k| hash[k] == [nil] }
keys.each { |k| hash[k] = nil }

hash.each_value do |v|
case v
when Array
v.grep(Hash) { |x| deep_munge(x) }
v.compact!
when Hash
deep_munge(v)
end
end

keys = hash.keys.find_all { |k| hash[k] == [nil] }
keys.each { |k| hash[k] = nil }
hash
end

Expand Down
4 changes: 4 additions & 0 deletions actionpack/test/dispatch/request/query_string_parsing_test.rb
Expand Up @@ -89,6 +89,10 @@ def teardown
assert_parses({"action"=>{"foo"=>[{"bar"=>nil}]}}, "action[foo][][bar]")
end

def test_array_parses_without_nil
assert_parses({"action" => ['1']}, "action[]=1&action[]")
end

test "query string with empty key" do
assert_parses(
{ "action" => "create_customer", "full_name" => "David Heinemeier Hansson" },
Expand Down
6 changes: 3 additions & 3 deletions activerecord/lib/active_record/relation/predicate_builder.rb
Expand Up @@ -5,17 +5,17 @@ def initialize(engine)
@engine = engine
end

def build_from_hash(attributes, default_table, check_column = true)
def build_from_hash(attributes, default_table, allow_table_name = true)
predicates = attributes.map do |column, value|
table = default_table

if value.is_a?(Hash)
if allow_table_name && value.is_a?(Hash)
table = Arel::Table.new(column, :engine => @engine)
build_from_hash(value, table, false)
else
column = column.to_s

if check_column && column.include?('.')
if allow_table_name && column.include?('.')
table_name, column = column.split('.', 2)
table = Arel::Table.new(table_name, :engine => @engine)
end
Expand Down
6 changes: 6 additions & 0 deletions activerecord/test/cases/relation/where_test.rb
Expand Up @@ -11,6 +11,12 @@ def test_where_error
end
end

def test_where_error_with_hash
assert_raises(ActiveRecord::StatementInvalid) do
Post.where(:id => { :posts => {:author_id => 10} }).first
end
end

def test_where_with_table_name
post = Post.first
assert_equal post, Post.where(:posts => { 'id' => post.id }).first
Expand Down

0 comments on commit b9e048c

Please sign in to comment.