litellm/tests/search_tests
tin-berri 9c014716ec
fix(search): block server credential leak to caller-supplied api_base (#30682)
Search providers resolved the server-configured API key (e.g.
get_secret_str("SERPER_API_KEY")) in validate_environment whenever the
caller omitted api_key, while get_complete_url independently honored a
caller-supplied api_base. A caller who passes their own api_base and no
api_key therefore made the proxy send the operator's provider key to a
host they control; POST /search_tools/test_connection forwards
request-body api_base/api_key straight into asearch, so any authenticated
user could exfiltrate the server's search credentials.

Add a shared host-aware fallback in BaseSearchConfig.resolve_server_api_key
that only applies a server-managed secret when the caller-supplied
api_base is absent or resolves to a trusted host (the provider default or
the operator's own *_API_BASE env override); otherwise it refuses and asks
for an explicit api_key. The guard only triggers when a server secret
actually exists, so keyless and self-hosted providers (searxng, you.com
free tier) keep working. Every provider that carries a server secret is
migrated to the helper; dataforseo reuses the same guard for its
login:password basic-auth credentials.

This changes behavior for callers that previously passed a per-request
api_base while relying on a server-configured key: they must now pass an
explicit api_key, or the operator must configure the base via the
provider's *_API_BASE env var (which stays trusted).
2026-06-23 13:01:21 -07:00
..
__init__.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
base_search_unit_tests.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
conftest.py fix(tests): stabilize image-edit VCR cassettes to stop live gpt-image-1 spend (#28110) 2026-05-18 09:15:39 -07:00
test_brave_search.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_dataforseo_search.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_duckduckgo_search.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_exa_ai_search.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_firecrawl_search.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_google_pse_search.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_linkup_search.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_parallel_ai_search.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_perplexity_search.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_search_tool_name_filtering.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_searchapi_search.py fix(search): block server credential leak to caller-supplied api_base (#30682) 2026-06-23 13:01:21 -07:00
test_searxng_search.py fix(search): block server credential leak to caller-supplied api_base (#30682) 2026-06-23 13:01:21 -07:00
test_serper_search.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_tavily_search.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_tinyfish_search.py feat(search): add TinyFish as search provider (#30634) 2026-06-18 09:17:53 -07:00