Given this method from Mustache.rb Context#find:
def find(obj, key, default = nil)
hash = obj.respond_to?(:has_key?)
if hash && obj.has_key?(key)
obj[key]
elsif hash && obj.has_key?(key.to_s)
obj[key.to_s]
elsif !hash && obj.respond_to?(key)
meth = obj.method(key) rescue proc { obj.send(key) }
if meth.arity == 1
meth.to_proc
else
meth[]
end
else
default
end
rescue Exception => e # I added this to give the debugging output below
debugger
# ... see debug output below
raise
end
Can anyone explain why I'm getting SecurityError Exception: calling insecure method: foo_id
given the following:
obj #=> #<MyModel id: 1, foo_id: 3 ...> (an ActiveRecord object)
# Note foo_id is a column in the DB (a method defined by AR)
key #=> :foo_id
obj.tainted? #=> false
obj.method(key) #=> #<Method: MyModel#foo_id>
obj.send(key) #=> 3
obj.method(key)[] #=> raises "SecurityError Exception: calling insecure method: foo_id"
obj.method(key).tainted? #=> true... WTF?
Is there something I should know about obj.method(key)
and obj.method(key).call
?