Skip to content

Instantly share code, notes, and snippets.

@ehlertij
Created November 27, 2012 17:35
Show Gist options
  • Save ehlertij/4155742 to your computer and use it in GitHub Desktop.
Save ehlertij/4155742 to your computer and use it in GitHub Desktop.
class UserController < ApplicationController
def show
@user = User.where("id = #{params[:user_id]}").first
end
end
params = { :id => '0; DROP TABLE users' }
# Rails will scrub this for you!
User.where(:id => params[:id])
# For more complicated queries, use array syntax!
User.where("created_at between ? and ?", params[:start], params[:end])
# Here's another nice option if you have lots of params to pass in
User.where(
" (created_at between :start and :end)
and last_name like :last_name",
{ :start => params[:start],
:end => params[:end],
:last_name => params[:lastname]
})
# Bad!
send(params[:method])
# Still not great, but better!
SAFE_VALUES = %w[foo bar]
if SAFE_VALUES.include?(params[:method])
send(params[:method])
else
# bad params[:method]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment