Re:SQL Injection Vulnerability in Ruby on Rails; affects all...
by Groxx on Wednesday January 02, 2013 @09:10PM
(#5000696)
Have you tried it? I can do this:
params[:id] = {:select => "select * from users where admin = 1 limit 1; --"}
User.find_by_id(params[:id]) # => finds the first admin
# generated SQL:
# SELECT * from users where admin = 1 limit 1; -- select * FROM `users` WHERE (`users`.`id` IS NULL) LIMIT 1
Seems like a bigger bug than you seem to think it is. Merely accepting JSON and not calling .to_i is enough for me to select any user.
-- edit: maybe nvm on that, it requires an actual symbol, not a string key with a hash with indifferent access, like you'd get from JSON. Unless someone knows a way to get a symbol into a JSON or form-encoded field? Though you're vulnerable to this specifically if you use '.symbolize_keys' anywhere before it's passed in.
-- edit2: and I see I'm late to the game anyway, thanks tenderlove :)
-- edit: maybe nvm on that, it requires an actual symbol, not a string key with a hash with indifferent access, like you'd get from JSON. Unless someone knows a way to get a symbol into a JSON or form-encoded field? Though you're vulnerable to this specifically if you use '.symbolize_keys' anywhere before it's passed in.
-- edit2: and I see I'm late to the game anyway, thanks tenderlove :)