Showing posts tagged #rails

Return Home

The Ruby on Rails framework provides a pretty good built-in filter for SQL injection if you use ActiveRecord methods such as find or find_by.
But that does not mean you can carelessly throw parameters to an ActiveRecord method as the methods that take an SQL fragment are still vulnerable to SQLi by default.

For example, I came across these lines in a production environment:

def some_controller_method
  MyModel.all.order("#{sort_column} #{sort_direction}")
end

private

def sort_column
  params[:sort] ? params[:sort] : 'created_at'
end

As you can see the sort parameter is being interpolated

Read More

Ruby has 3 methods for testing equality: ==, eql? and equal? that are implemented on the Object class. You would think that they are just aliases for doing the same as in Ruby and the Ruby on Rails framework method aliases are common. So, are they?

Checking the doc for Ruby's Object class throws this:

obj == other → true or false

equal?(other) → true or false

eql?(other) → true or false

Equality — At the Object level, == returns true only if obj and other are the same object. Typically, this method is overridden in descendant classes to provide class-specific meaning.

Unlike ==, the equal?

Read More