aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2013-01-04 12:02:22 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2013-01-08 09:08:26 -0800
commitd5cd97baa44fa66dc681041a213092b45c57c32f (patch)
treef5817abd953a86aceb4710f93337405db1306ae1 /activerecord
parent95fe9ef945a35f56fa1c3ef356aec4a3b868937c (diff)
downloadrails-d5cd97baa44fa66dc681041a213092b45c57c32f.tar.gz
rails-d5cd97baa44fa66dc681041a213092b45c57c32f.tar.bz2
rails-d5cd97baa44fa66dc681041a213092b45c57c32f.zip
* Strip nils from collections on JSON and XML posts. [CVE-2013-0155] * dealing with empty hashes. Thanks Damien Mathieu
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/CHANGELOG.md4
-rw-r--r--activerecord/lib/active_record/relation/predicate_builder.rb7
-rw-r--r--activerecord/test/cases/relation/where_test.rb16
3 files changed, 25 insertions, 2 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md
index bd8a0bc039..6be0c273c8 100644
--- a/activerecord/CHANGELOG.md
+++ b/activerecord/CHANGELOG.md
@@ -1,3 +1,7 @@
+## Rails 3.2.11 ##
+
+* Fix querying with an empty hash *Damien Mathieu* [CVE-2013-0155]
+
## Rails 3.2.10 ##
* CVE-2012-5664 options hashes should only be extracted if there are extra
diff --git a/activerecord/lib/active_record/relation/predicate_builder.rb b/activerecord/lib/active_record/relation/predicate_builder.rb
index 6b118b4912..b31fdfd981 100644
--- a/activerecord/lib/active_record/relation/predicate_builder.rb
+++ b/activerecord/lib/active_record/relation/predicate_builder.rb
@@ -6,7 +6,12 @@ module ActiveRecord
if allow_table_name && value.is_a?(Hash)
table = Arel::Table.new(column, engine)
- build_from_hash(engine, value, table, false)
+
+ if value.empty?
+ '1 = 2'
+ else
+ build_from_hash(engine, value, table, false)
+ end
else
column = column.to_s
diff --git a/activerecord/test/cases/relation/where_test.rb b/activerecord/test/cases/relation/where_test.rb
index b9eef1d32f..80158332f9 100644
--- a/activerecord/test/cases/relation/where_test.rb
+++ b/activerecord/test/cases/relation/where_test.rb
@@ -1,9 +1,11 @@
require "cases/helper"
require 'models/post'
+require 'models/comment'
+require 'models/edge'
module ActiveRecord
class WhereTest < ActiveRecord::TestCase
- fixtures :posts
+ fixtures :posts, :edges
def test_where_error
assert_raises(ActiveRecord::StatementInvalid) do
@@ -21,5 +23,17 @@ module ActiveRecord
post = Post.first
assert_equal post, Post.where(:posts => { 'id' => post.id }).first
end
+
+ def test_where_with_table_name_and_empty_hash
+ assert_equal 0, Post.where(:posts => {}).count
+ end
+
+ def test_where_with_table_name_and_empty_array
+ assert_equal 0, Post.where(:id => []).count
+ end
+
+ def test_where_with_empty_hash_and_no_foreign_key
+ assert_equal 0, Edge.where(:sink => {}).count
+ end
end
end