문제

Having an activerecord object, it is safe to call send on it with user provided argument?

example:

string_provided_by_user.gsub(/@invoice\.([^ ]*)/) { |a| @invoice.send($1) }

this is to allow user to use @invoice object on string

도움이 되었습니까?

해결책

What do you expect to achieve with this? If you have no problems with user destroying your invoices from db or in general invoking any methods which cannot be called without arguments then they shouldn't be able to do anything harmful.

However it would be much better to define a list of acceptable methods first.

allowed_methods = [:amount, :date]
string_provided_by_user.gsub(/@invoice\.([^ ]*)/) do |a| 
  raise 'Nice try!' unless allowed_methods.include? a
  @invoice.send(a)
end
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top