On Github LeeXGreen / sql_injection_slides
http://lee.greens.io/sql_injection_slides/
Lee Green
image credit: http://xkcd.com/327
Vulnerabilities are present when user-supplied data ceases to be treated as data, and is executed in some fashion.
An attacker is said to have injected a command into the data stream, often by escaping or encoding it.
The manner of injection and execution is different for each type of vulnerability.
# bad. m = Model.where("name = '#{params[:name]}'").first # better. m = Model.where('name = ?', params[:name]).first m = Model.where(name: params[:name]).first
valid_sorts = { 'name_asc' => 'name ASC', 'name_desc' => 'name DESC', 'color_asc' => 'color ASC', 'color_desc' => 'color DESC', } user_input = params[:sort] # default to 'name ASC' on bad input sort_key = valid_sorts[user_input] || 'name ASC' order_clause = valid_sorts[sort_key]
An error message can be the foothold that an attacker needs to hone in on a vulnerability.
We should never show the user an error message directly from the DB -- or a stacktrace!
image credit: http://xkcd.com/463/