Skip to content
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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

jjfreund
Copy link
Contributor

@jjfreund jjfreund commented Jan 4, 2021

No description provided.

Joe Freund added 2 commits January 3, 2021 14:04
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 + ")"
Copy link
Member

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/

Copy link
Contributor Author

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.

Comment on lines +28 to +37
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
Copy link
Member

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...

Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants