Repository navigation
fix(tavily): allow a baseUrl override on a private or internal host - #198550
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: blocked before merge. What this changesThis PR lets Tavily search and extraction reach operator-configured private or loopback endpoints through a hostname-scoped guard. Example: Set TAVILY_BASE_URL=http://127.0.0.1:18081 and call tavily_search.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Blocked before merge - 1 item remains This PR addresses a private-endpoint failure still present on main, with no concrete code defect found; separate SDK/security-owner approval and successful CI remain outstanding. Priority: P2 Before merge
FindingsNone. Agent review detailsHow this fits togetherThe Tavily plugin converts agent search and extraction calls into authenticated HTTP requests; the shared network guard controls destinations, DNS resolution, redirects, and transport cleanup. flowchart TD
A[Agent tool call] --> C[Tavily client]
B[Operator endpoint configuration] --> C
C --> D[Hosted endpoint guard]
C --> E[Custom hostname guard]
D --> F[Direct or proxy transport]
E --> F
F --> G[Parsed tool results]
Technical reviewBest possible solution: Retain the narrow hostname policy and shared HTTP owner, with the separately required SDK/security approval recorded before landing. Do we have a high-confidence way to reproduce the issue? Source establishes that a private Tavily baseUrl reaches the restrictive trusted guard on main; this read-only review did not run a failing base reproduction. Is this the best way to solve the issue? The change uses existing SSRF policy owners and preserves one POST/error-handling implementation; the broader self-hosted helper cannot provide the documented hostname and metadata restrictions. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 987c04a00869. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +86, Tests +400, Docs 0. Total +486 across 9 files. Added test files: 1. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. Review metrics
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (1 earlier review cycle)
Reviewed November 15, 2026, 3:49 PM ET / 20:49 UTC (Revision 2). |
A Tavily baseUrl on a private or internal host was unusable: requests went through the trusted-endpoint guard, which keeps the private-network checks on, so hosts ending in .internal, .local or .localhost and private, loopback or link-local addresses were refused before the request left the process. No plugin setting reaches the policy. Treat baseUrl as operator authority and trust the host named in it by exact name. The configured host is honored as typed, including loopback and private addresses. Cloud-metadata destinations are always refused: the new guard helper routes 169.254.169.254 and other link-local literals, fd00:ec2::254, 100.100.100.200, their mapped and embedded forms and metadata.google.internal to the strict guard, which rejects them before any DNS lookup or request in direct and env-proxy mode alike. A configured name whose DNS answer is loopback, unspecified, link-local or cloud-metadata is refused, because that answer was not the operator's choice. Off-host redirects are refused. With an env proxy the proxy resolves the name, as for every trusted call. The default api.tavily.com endpoint keeps the trusted-endpoint mode unchanged. The helper combines the existing fake-IP hostname allowlist with the existing exact-host allowedHostnames policy for the request URL's host; isCloudMetadataHostnameOrIp in ssrf.ts reuses the guard's metadata hostname and the net-policy metadata and link-local IP classifiers. postTrustedWebToolsJson's request shape, error handling and response parsing move into a shared helper; postPinnedTrustedHostWebToolsJson is the one new export, on the local-only plugin-sdk provider-web-search subpath (no public surface budget change), and the Tavily client uses it when the resolved base URL's host is not api.tavily.com. Co-authored-by: sallyom <[email protected]>
e00dc1b to
866a711
Compare
|
@clawsweeper re-review Added real behavior proof for the current head |
|
🦞👀 Re-review progress:
|
Supersedes #139868 (closed by the stale bot). Same change and contract, rebased onto current
main.What Problem This Solves
Fixes an issue where operators who set the Tavily plugin's
baseUrl(plugins.entries.tavily.config.webSearch.baseUrlorTAVILY_BASE_URL) to a Tavily-compatible endpoint on a private or internal host would find everytavily_searchandtavily_extractcall refused before it left the process. The documented override exists for self-hosted gateways, policy proxies and test doubles, and those endpoints are normally addressed by private names such as*.internal,*.localor an RFC 1918 address, or by a loopback address on the same machine. Routing through an env proxy does not change the outcome, and no plugin setting affects it.User Impact
Operators can point the Tavily plugin at a Tavily-compatible endpoint on a private, internal or loopback host and use
tavily_searchandtavily_extractagainst it, directly or through an env proxy. Users of the default endpoint see no change. Cloud-metadata destinations remain unreachable, and a configured name whose DNS answer is loopback, link-local or metadata remains refused.Why This Change Was Made
The client posts through the trusted-endpoint guard mode, whose policy pins the hostname but keeps the private-network checks on. This change treats
baseUrlas operator authority and trusts the host named in it by exact name, under this contract:localhost-style names.169.254.169.254and other link-local literals,fd00:ec2::254,100.100.100.200, their mapped and embedded encodings, andmetadata.google.internal. AbaseUrlnaming one of these is routed to the strict guard, which refuses it before any DNS lookup or request in direct and env-proxy mode alike.api.tavily.comendpoint keeps the trusted-endpoint mode unchanged.The guard gains an internal helper that combines the existing fake-IP hostname allowlist with the existing exact-host
allowedHostnamespolicy for the request URL's host, after checking the host against a newisCloudMetadataHostnameOrIpclassifier insrc/infra/net/ssrf.tsthat reuses the guard's metadata hostname and thenet-policymetadata and link-local IP classifiers.postTrustedWebToolsJson's request shape, error handling and response parsing move into a shared helper, andpostPinnedTrustedHostWebToolsJsonis the one new export, on the local-onlyplugin-sdk/provider-web-searchsubpath, used by the Tavily client when the resolved base URL's host is notapi.tavily.com. Because the subpath is local-only, the public plugin SDK surface budgets do not change. The Tavily docs state the contract under "Custom base URL".Alternative considered: an explicit
webSearch.selfHostedopt-in flag. Not chosen because an operator who setsbaseUrlhas already named the host, and anyone able to writebaseUrlcan write the flag, so it adds a setting without adding a control.Also note: an invalid custom
baseUrlstill fails before any request, as on currentmain("reject malformed endpoints instead of switching hosts"); this change only chooses which guard mode a valid URL is posted through.Evidence
Live Gateway proof on the current head (
866a711)Real agent turns through an isolated Gateway built from this PR head, with a real hosted reasoning model, calling
tavily_searchandtavily_extractagainst a Tavily-shaped stub on a private (RFC 1918) address and on loopback, and a cloud-metadatabaseUrlthat the guard refuses before any request.Full redacted transcript (environment, config, trajectories, stub and Gateway logs)
Isolated Gateway built from the PR head, a real agent turn with a real model, and
tavily_search/tavily_extractcalls against a Tavily-shaped stub on a private (RFC 1918) address and on loopback. Also a cloud-metadata
baseUrl, which is refused.Redactions: the provider id and model id are shown as
<provider>and<model>. The container's RFC 1918 address is shown as<private-ip>. The model endpoint hostname is shown as<model-endpoint>. The model API keyis never written out: the config refers to it as
${MODEL_API_KEY}, and the Gateway reads it from the process environment. The Tavily key is thedummy value
tvly-proof-dummy, and no real Tavily key was used. The stub logs only whether a bearer token was present, never its value. The Gateway tokenwas random, kept in a file, and never printed.
Environment
OpenClaw 2026.11.3 (866a711);dist/build-info.jsoncommit866a711388a12bfe919a3470d0f2995183b03c24(PR head)pnpm build(pnpm 12.15.0) from the PR head; prod deps installed for linux/x64/glibc with pnpmsupportedArchitecturesandpnpm install --frozen-lockfile --prod --ignore-scripts; tree copied into the container<model>) behind an OpenAI-compatible endpointhttps://<model-endpoint>/v1(--thinking high)HOME=/tmp/ochome,OPENCLAW_STATE_DIR=/tmp/ochome/state, Gateway on loopback:18789, token authhttp.server:POST /searchandPOST /extractreturn Tavily-shaped JSON with marker strings. One instance on<private-ip>:18080, one on127.0.0.1:18081Commands
Prompt for cases A and B:
Prompt for case C. This prompt makes the extract call independent of the search result, so the extract is attempted even though the search is refused:
Config for case A. Cases B and C differ only in
baseUrl:{ "gateway": { "mode": "local", "port": 18789, "bind": "loopback", "auth": { "mode": "token" } }, "models": { "providers": { "<provider>": { "baseUrl": "https://<model-endpoint>/v1", "apiKey": "${MODEL_API_KEY}", "api": "openai-completions", "models": [ { "id": "<model>", "name": "<model>", "reasoning": true, "input": ["text"], "contextWindow": 200000, "maxTokens": 16000 } ] } } }, "agents": { "defaults": { "model": { "primary": "<provider>/<model>" }, "workspace": "/tmp/ochome/workspace" } }, "plugins": { "entries": { "tavily": { "enabled": true, "config": { "webSearch": { "apiKey": "tvly-proof-dummy", "baseUrl": "http://<private-ip>:18080" } } } } }, "tools": { "profile": "minimal", "alsoAllow": ["tavily_search", "tavily_extract"], "web": { "search": { "provider": "tavily", "cacheTtlMinutes": 0 } } } }The tool profile is
minimalplusalsoAllowfor the two Tavily tools. This keeps the model's tool surface small. The Gateway hands the tools to the model through itsdispatch_actiontool bridge, so the trajectory shows adispatch_actioncall wrapping each Tavily call.Case A:
baseUrl = http://<private-ip>:18080(RFC 1918 literal). PASSAgent result (
--json, projected):Session trajectory (
openclaw sessions tail):Stub request log (
<private-ip>:18080):Gateway log (relevant lines):
Case B:
baseUrl = http://127.0.0.1:18081(loopback). PASSStub request log (
127.0.0.1:18081):In this run the model first used
tool_searchto locate the Tavily tools, then called both of them.Case C:
baseUrl = http://169.254.169.254:18080(cloud metadata). Refused as intended. PASSRun C1 used the case A prompt. The model called
tavily_searchtwice, and both calls were refused. It then skipped extract because it had no URL to pass. Run C2 used the independent prompt above, and both tools were refused:Trajectory C2:
Trajectory C1:
Gateway log for the C1 and C2 runs (the guard refuses at
[security]before any request; refusal follows the tool call within about 10 ms):Stub request logs during case C: no new lines on either stub (private 0, loopback 0).
Summary
http://<private-ip>:18080(RFC 1918)/search,/extract), bearer presenthttp://127.0.0.1:18081(loopback)/search,/extract), bearer presenthttp://169.254.169.254:18080(metadata)SsrFBlockedError"Blocked hostname or private/internal/special-use IP address"Notes:
[security] blocked URL fetch ... targetOrigin=http://169.254.169.254:18080line. It is logged within milliseconds of the tool call, and the tool result isSsrFBlockedError.tools.web.search.cacheTtlMinutes=0disables the search result cache, and the extract cache is keyed by URL, so case B's extract hit the loopback stub, as its log shows.Head commit on base
main6341f93c9c565364ea86b417f21ffde4519b51b7. Original authorship and the existing co-author credit are kept.Rebase notes relative to #139868:
extensions/tavily/src/tavily-client.ts: keptmain'sresolveEndpoint(no fallback to the hosted API for malformed URLs) and addedusesDefaultTavilyHoston top of it.extensions/tavily/src/tavily-client.test.ts:mainrewrote this file; the routing assertions were ported into its current shape (hosted URL variants stay onpostTrustedWebToolsJson;https://tavily.gateway.internalsearch andhttp://10.0.0.5:8080/tavily/extract go topostPinnedTrustedHostWebToolsJsonwith the same parameter shape). Both new routing tests fail onmainand pass with the change.src/agents/tools/web-search-provider-common.ts: adapted tomain'screateLazyPromiseloader andSearchConfigRecordshape.src/agents/tools/web-search-provider-common.test.ts: the two pinned-helper tests were appended tomain's rewritten file; the non-2xx assertion now matchesmain'sProviderHttpError(messageandstatus).scripts/plugin-sdk-surface-report.mts: no change.provider-web-searchis a local-only SDK subpath, so the public export counts are identical with and without the new export (verified by runningpnpm plugin-sdk:surface:checkon both).Focused tests on this head:
pnpm test:extension tavily: 4 files, 43 passed.src/agents/tools/web-guarded-fetch.test.ts,web-guarded-fetch.pinned-endpoint.test.ts,web-search-provider-common.test.ts: 3 files, 71 passed (7 + 47 + 17). All pinned-helper cases run the real SSRF guard. They cover the configured host reached as typed (private names, RFC 1918 and ULA literals, loopback), a non-http(s) endpoint refused before any lookup or request, cloud-metadata literals andmetadata.google.internalrefused before any lookup or request (direct and env-proxy), loopback/link-local/metadata DNS answers refused after one lookup, private answers reached, off-host redirects refused and same-host redirects followed, env-proxy delivery without local DNS, the request timeout, and a real loopback server receiving the pinnedPOSTwith the same headers whilepostTrustedWebToolsJsonis refused.pnpm test:contracts:plugins: 49 files, 1028 passed; 2 files, 62 passed.main(node scripts/check-test-lines-ratchet.mts --base <base> --no-merge-base), within the 400-line allowance, so noconfig/test-lines-allocationsrecord is added. To get there, the mocked policy-shape cases inweb-guarded-fetch.test.ts(exact-host policy construction, metadata URLs falling back to the strict guard, a non-http(s) URL falling back to the strict guard) were removed: the real-guard suite inweb-guarded-fetch.pinned-endpoint.test.tsalready proves the first two by behaviour (configured host reached, off-host redirects refused, env-proxy delivery without local DNS; metadata destinations refused before any lookup or request in both modes), and the non-http(s) case moved there as a real-guard test. The real-guard suite was also consolidated (shared lookup and env-proxy helpers, table-driven DNS-answer, metadata direct/env-proxy and env-proxy redirect cases,PROXY_ENV_KEYSimported fromsrc/infra/net/proxy-env.ts) without dropping any case.pnpm check:baseline-ratchets --base <base>: line-cap, max-lines, assertion-safety, database-dialect, timeout-race, test-lines, mock-exports, config-docs and plugin-inventory pass. database-worker could not run locally (spawnSync rg ENOENT, no ripgrep on the machine); this change touches no database code.oxfmtandoxlintclean on the changed files;git diff --checkclean.pnpm check:changed(run on the previous head, before the rebase onto the current base and the test consolidation; not re-run since): typecheck (core, core tests, extensions, extension tests), plugin boundaries, Plugin SDK package exports, lint core/extension changed files and the other lanes pass. Two lanes fail identically without this change: "Plugin SDK surface budget" (public entrypoints 163 > 162, exports 3888 > 3867, callable 2243 > 2236, wildcard reexports 1 > 0 on basemaintoo) and "dead export scan" (unused exports inscripts/lib,extensions/qa-lab,extensions/telegram,src/node-hostandui, none touched here).Historical local run from #139868 (original head, same transport code; not re-run on this head):
Local run: a Tavily-shaped stub (
POST /search,POST /extract) on127.0.0.1:18080, a logging HTTP proxy stub on127.0.0.1:18090that records everyCONNECTand absolute-URI request, tunnelsCONNECTto the stub's port and answers 403 to any other tunnel, and the real plugin client (runTavilySearch,runTavilyExtractfromextensions/tavily/src/tavily-client.ts) driven from source. The driver records every localdns.lookupcall. The private name is redacted.(a) The operator-configured loopback endpoint is honored: both calls succeed and the stub receives exactly two requests. (b) and (c) A metadata
baseUrlis refused before any lookup or connection, with or without an env proxy; the proxy log stays empty. (d) A private name is delivered through the proxy: oneCONNECTper call, the name arrives at the proxy unresolved, and the stub receives exactly two requests. (e1) and (e2) The default endpoint in trusted mode and a private name in pinned mode behave identically under the proxy: oneCONNECTper call carrying the hostname as written, zero local DNS lookups, and the same failure when the proxy refuses the tunnel. The pinned helper does not weaken proxy mode beyond exempting the one configured host from the pre-DNS hostname rule.