yes it is. Everytime you insert user's input into the query string, it is vulnerable. If month will be :
5' AND '8'; DROP TABLE timeslots;--
you might be in serious troubles. Not to mention drop database etc.
I haven't reproduced exactly this query, but something similar [ I had to add ) in my query due to using acts_as_paranoid plugin ]:
SomeModel.pluck(:id)
=> [1, 2, 4, 3, 5, 6]
abc = 'a\');delete from some_models where id=6;--'
User.where("name = '#{abc}'")
=> []
SomeModel.pluck(:id)
=> [1, 2, 4, 3, 5] # please note that record with id 6 was deleted!
The reason why the attack was possible, is that I could provide ' and -- ( which starts comment ). When yo use the suggested way, i.e. using .where("name = ?", "my_name"), then the attack would not be possible. Check this out:
abc = 'a\');delete from some_models where id=5;--'
User.where("name = ?", abc)
=> []
SomeModel.pluck(:id)
=> [1, 2, 4, 3, 5] # this time record with id 5 was not deleted
This is first query:
User Load (1.5ms) SELECT "users".* FROM "users" WHERE ("users"."deleted_at" IS NULL) AND (name = 'a');delete from some_models where id=6;--')
This is the second
User Load (1.0ms) SELECT "users".* FROM "users" WHERE ("users"."deleted_at" IS NULL) AND (name = 'a'');delete from some_models where id=5;--')
Note the additional ' in the second - query(name = 'a'')
params[:id].to_ihas saved us from security vulnerabilities in rails. So even rails claims to escape the parameters in a given method, trust nobody :)params[:id].to_ihas prevented security vulnerabilities?"1".to_ireturns the integer1."some_string".to_ireturns0