Skip to content

Commit

Permalink
CVE-2012-5664 options hashes should only be extracted if there are ex…
Browse files Browse the repository at this point in the history
…tra parameters
  • Loading branch information
tenderlove committed Dec 23, 2012
1 parent fbe436b commit c42f548
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
6 changes: 5 additions & 1 deletion activerecord/lib/active_record/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1065,7 +1065,11 @@ def method_missing(method_id, *arguments, &block)
eowarn
end
if match.finder?
options = arguments.extract_options!
options = if arguments.length > attribute_names.size
arguments.extract_options!
else
{}
end
relation = options.any? ? scoped(options) : scoped
relation.send :find_by_attributes, match, attribute_names, *arguments
elsif match.instantiator?
Expand Down
12 changes: 12 additions & 0 deletions activerecord/test/cases/finder_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,18 @@
class FinderTest < ActiveRecord::TestCase
fixtures :companies, :topics, :entrants, :developers, :developers_projects, :posts, :comments, :accounts, :authors, :customers, :categories, :categorizations

def test_find_by_id_with_hash
assert_raises(ActiveRecord::StatementInvalid) do
Post.find_by_id(:limit => 1)
end
end

def test_find_by_title_and_id_with_hash
assert_raises(ActiveRecord::StatementInvalid) do
Post.find_by_title_and_id('foo', :limit => 1)
end
end

def test_find
assert_equal(topics(:first).title, Topic.find(1).title)
end
Expand Down

0 comments on commit c42f548

Please sign in to comment.