-
-
Save ehlertij/4155742 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class UserController < ApplicationController | |
def show | |
@user = User.where("id = #{params[:user_id]}").first | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
params = { :id => '0; DROP TABLE users' } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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] | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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