Skip to content

Commit

Permalink
stop calling to_sym when building arel nodes [CVE-2013-1854]
Browse files Browse the repository at this point in the history
  • Loading branch information
tenderlove committed Mar 16, 2013
1 parent dad3109 commit ef9f053
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion activerecord/lib/active_record/base.rb
Expand Up @@ -2307,7 +2307,7 @@ def aggregate_mapping(reflection)
def expand_hash_conditions_for_aggregates(attrs) def expand_hash_conditions_for_aggregates(attrs)
expanded_attrs = {} expanded_attrs = {}
attrs.each do |attr, value| attrs.each do |attr, value|
unless (aggregation = reflect_on_aggregation(attr.to_sym)).nil? unless (aggregation = reflect_on_aggregation(attr)).nil?
mapping = aggregate_mapping(aggregation) mapping = aggregate_mapping(aggregation)
mapping.each do |field_attr, aggregate_attr| mapping.each do |field_attr, aggregate_attr|
if mapping.size == 1 && !value.respond_to?(aggregate_attr) if mapping.size == 1 && !value.respond_to?(aggregate_attr)
Expand Down
2 changes: 1 addition & 1 deletion activerecord/lib/active_record/reflection.rb
Expand Up @@ -18,7 +18,7 @@ def create_reflection(macro, name, options, active_record)
when :composed_of when :composed_of
reflection = AggregateReflection.new(macro, name, options, active_record) reflection = AggregateReflection.new(macro, name, options, active_record)
end end
write_inheritable_hash :reflections, name => reflection write_inheritable_hiwa :reflections, name => reflection
reflection reflection
end end


Expand Down
Expand Up @@ -109,6 +109,11 @@ def write_inheritable_hash(key, hash)
write_inheritable_attribute(key, read_inheritable_attribute(key).merge(hash)) write_inheritable_attribute(key, read_inheritable_attribute(key).merge(hash))
end end


def write_inheritable_hiwa(key, hash)
write_inheritable_attribute(key, {}.with_indifferent_access) if read_inheritable_attribute(key).nil?
write_inheritable_attribute(key, read_inheritable_attribute(key).merge(hash))
end

def read_inheritable_attribute(key) def read_inheritable_attribute(key)
inheritable_attributes[key] inheritable_attributes[key]
end end
Expand Down

2 comments on commit ef9f053

@alboyadjian
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be write_inheritable_hwia (hash with indifferent access) instead of write_inheritable_hiwa ?

@MacksMind
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found an interesting side effect. I have some test code that expected Model.reflections.keys to be symbols, and now it uses strings. It wasn't hard to change my code, but I'm guessing I'm not the only one trying to be too clever.

Please sign in to comment.