Rails very very very very very imp methods ::::::::::::::::::::::::::::::::
Rails very very very very very imp methods ::::::::::::::::::::::::::::::::
Link ::
https://rails-sqli.org/
.....................................................
1. calculation sum method ::
Order.calculate(:sum, params[:column])User.delete_by("id = #{params[:id]}")User.destroy_by(["id = ? AND admin = '#{params[:admin]}", params[:id]])User.exists? params[:user]User.exists? ["name = '#{params[:user]}'"]Note that find_or_create_by / find_or_create_by! / find_or_initialize_by all call find_by and are therefore vulnerable to SQL injection in the same way.
User.find_by params[:id]Instead of returning all non-admin users, we return all admin users.
User.from(params[:from]).where(admin: false).allThe intent of this query is to group non-admin users by the specified column. Instead, the query returns all users.
User.where(:admin => false).group(params[:group])This input injects a union in order to return all orders, instead of just the orders from a single user.
Order.where(:user_id => 1).group(:user_id).having("total > #{params[:total]}")joins method can take an array of associations or straight SQL strings.Skip WHERE clause and return all orders instead of just the orders for the specified user.
Order.joins(params[:table]).where("total > 1000").allNot a real example: SQLite does not support this option.
User.where('id > 1').lock(params[:lock])The not method is equivalent to where and is equally unsafe when passed SQL strings directly.
SELECT clause is at the beginning of the query, nearly any SQL can be injected.User.select(params[:column])This is the same as select. Since the SELECT clause is at the beginning of the query, nearly any SQL can be injected, including querying totally different tables than intended.
User.select(:name).reselect(params[:column])The example below is using classic SQL injection to bypass authentication.
User.where("name = '#{params[:name]}' AND password = '#{params[:password]}'")Like where, the rewhere method can be passed a straight SQL string. rewhere adds the new conditions as a conjunction using AND.
Calls using a hash of name-value pairs are escaped, and the array form can be used for safely parameterizing queries.
User.where(name: "Bob").rewhere("age > #{params[:age]}")update_all accepts any SQL as a string.
User input should never be passed directly to update_all, only as values in a hash table.
User.update_all("admin = 1 WHERE name LIKE '%#{params[:name]}%'")
Comments
Post a Comment