Skip to content

fix(brave-search): reject blank queries - #3052

Open
tang-vu wants to merge 1 commit into
Osmantic:mainfrom
tang-vu:fix/brave-search-blank-query
Open

fix(brave-search): reject blank queries#3052
tang-vu wants to merge 1 commit into
Osmantic:mainfrom
tang-vu:fix/brave-search-blank-query

Conversation

@tang-vu

@tang-vu tang-vu commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

Why this matters

Both Brave proxy routes accept a whitespace-only q because 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_q contract 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/search and 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 — passed
  • node --check extensions/services/brave-search/proxy.mjs — passed
  • node --check tests/test-brave-search-searxng-compat.mjs — passed
  • git diff --check — passed

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

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.

1 participant