Fix Elasticsearch BadRequest from non-Hash search param in profile pages#4334
Open
Fix Elasticsearch BadRequest from non-Hash search param in profile pages#4334
Conversation
Contributor
|
@gumclaw can we prevent the controller from passing the search query param to the method in the first place? |
Contributor
Author
|
Good call — yeah, already sanitizes Something like adding this to params.delete(:search) unless params[:search].is_a?(Hash)Then the I'll update the PR. |
526b033 to
2fb38c0
Compare
The search_options method appends params[:search] directly to the ES bool.must array. When a URL query parameter like ?search=string arrives, this injects a string into must, which expects objects. Only append params[:search] when it's a Hash (the intended internal use case). String values from URL params are now ignored. Fixes https://gumroad-to.sentry.io/issues/7366918596/
Strip non-Hash search params at the controller level in format_search_params! instead of guarding in the ES query builder. This is consistent with how tags, filetypes, and size are already sanitized in the same method.
2fb38c0 to
ef5306c
Compare
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Only append
params[:search]to the ESbool.mustarray when it's a Hash.Why
The
search_optionsmethod inProduct::Searchableappendsparams[:search]directly to the ESmustclause. When a user visits a profile page with?search=some_string, this string gets injected intomust, which expects objects. Elasticsearch returns a 400:parsing_exception: query malformed, must start with start_object.The
searchparam is designed for internal use (passing a pre-built ES query hash). String values from URL params should be ignored.Fixes https://gumroad-to.sentry.io/issues/7366918596/
Impact