-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
1808 modify search endpoint #553
base: master
Are you sure you want to change the base?
Conversation
Corrected behavior of multiple category / eligibility search.
first_cat = true | ||
category_ids.each do |cat_id| | ||
if first_cat | ||
query_string = "services.id in (select service_id from categories_services where category_id=" + cat_id + ")" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will expose us to a SQL injection attack. Can this be written using the ActiveRecord methods that properly escape external values? Or if you have to drop into raw SQL, at least use the sanitization methods available in ActiveRecord: https://api.rubyonrails.org/v5.1.0/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ooh that's a good point. I could just check if all of the incoming IDs are integers for example.
category_ids = categories_id_string.split "," | ||
first_cat = true | ||
category_ids.each do |cat_id| | ||
if first_cat | ||
query_string = "services.id in (select service_id from categories_services where category_id=" + cat_id + ")" | ||
first_cat = false | ||
else | ||
query_string = query_string + | ||
" and services.id in (select service_id from categories_services where category_id=" + cat_id + ")" | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think what you're trying to do might be simpler using an approach like this: https://stackoverflow.com/a/15977167
I think that'd avoid having to dynamically generate a query with an arbitrary number of expressions, since you can push everything into that inner join with a HAVING
clause. Man, I haven't used the HAVING
keyword in forever...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure how that would make things easier. I'll contact you to get more information.
No description provided.