Skip to content

fix: prevent DEFAULT_PARAMETERS from overriding user-provided values#128

Open
spidershield-contrib wants to merge 2 commits into
tavily-ai:mainfrom
spidershield-contrib:fix/default-params-override
Open

fix: prevent DEFAULT_PARAMETERS from overriding user-provided values#128
spidershield-contrib wants to merge 2 commits into
tavily-ai:mainfrom
spidershield-contrib:fix/default-params-override

Conversation

@spidershield-contrib

@spidershield-contrib spidershield-contrib commented Mar 15, 2026

Copy link
Copy Markdown

Summary

Fixes #127

The default parameter application loop iterated over searchParams keys and unconditionally replaced matching values from defaults. This caused user-provided values to be silently overwritten by DEFAULT_PARAMETERS.

Changes

File Change
src/index.ts Reverse loop direction: iterate defaults keys, only apply when user value is undefined/null

Before / After

Before (buggy):

for (const key in searchParams) {       // iterates user params
  if (key in defaults) {
    searchParams[key] = defaults[key];  // always overwrites
  }
}

After (fixed):

for (const key in defaults) {           // iterates defaults
  if (key in searchParams && (searchParams[key] === undefined || searchParams[key] === null)) {
    searchParams[key] = defaults[key];  // only fills gaps
  }
}

Test Plan

  • npx tsc --noEmit — zero errors
  • With DEFAULT_PARAMETERS='{"max_results":5}', calling tavily_search(query="test", max_results=10) should return 10 results (not 5)
  • With DEFAULT_PARAMETERS='{"search_depth":"basic"}', calling tavily_search(query="test") should use "basic" (default fills the gap)

Note

Low Risk
Low risk: changes are localized to tavily_search request parameter merging and should only affect how defaults are applied; main risk is subtle behavior changes for callers relying on old (buggy) overriding behavior.

Overview
Fixes tavily_search parameter merging so DEFAULT_PARAMETERS no longer overwrites explicitly provided user arguments; defaults are now applied only when the user value is undefined/null.

Also normalizes include_domains/exclude_domains so they are never undefined (coalesced to []) to match the Tavily API’s expected array types.

Written by Cursor Bugbot for commit b7b2a3a. This will update automatically on new commits. Configure here.


Found by SpiderShield security scanner

The default parameter application loop iterated over searchParams keys
and unconditionally replaced them with values from defaults. This caused
user-provided parameter values (e.g., max_results=10) to be silently
overwritten by DEFAULT_PARAMETERS (e.g., max_results=5).

Reverse the iteration to loop over defaults keys instead, and only
apply a default when the user-provided value is undefined or null.
@spidershield-contrib spidershield-contrib requested a review from a team March 15, 2026 05:10

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Comment thread src/index.ts
The || [] fallback on include_domains/exclude_domains prevented
DEFAULT_PARAMETERS from ever applying to these fields, since
their value was always [] (never undefined/null).

Move the [] fallback to after default parameter application so
domain list defaults work correctly.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

Bug: DEFAULT_PARAMETERS unconditionally overrides user-provided search parameters

1 participant