fix(brave-search): reject blank queries - #3052
Open
tang-vu wants to merge 1 commit into
Open
Conversation
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.
Why this matters
Both Brave proxy routes accept a whitespace-only
qbecause non-empty strings are truthy. Those requests reach the paid upstream despite carrying no meaningful search terms, consuming quota and producing provider-dependent results.Root cause: presence validation did not apply the same trimming used for returned result fields.
Behavioral invariant: missing and whitespace-only queries receive the existing
400 missing_query_param_qcontract and never call Brave; valid queries are trimmed once and used consistently.Overlap check
Searched open and closed upstream PRs for “brave search whitespace query” and reviewed PRs changing
brave-search/proxy.mjs. Open PR #2998 validates malformed result entries and #2734 concerns caller authentication. Neither validates the query boundary; no matching closed PR was found.Regression test
The loopback contract suite sends blank queries through real proxy processes for both
/v1/searchand enabled/search?format=json. It asserts the 400 body and verifies the stub-upstream request counter does not change.Validation
bash tests/test-brave-search-searxng-compat.sh— passednode --check extensions/services/brave-search/proxy.mjs— passednode --check tests/test-brave-search-searxng-compat.mjs— passedgit diff --check— passedTradeoffs and rollback
Leading and trailing whitespace is normalized before forwarding, which matches user search semantics while preserving internal whitespace. The response error code remains backward-compatible. Rollback is one commit.