T09 · Insecure Skill Coding Practices
- Location
scripts/smart-search.js:8- Finding
Unrestricted API Base URL Allows Tavily Credential Disclosure
- Content
View full analysis
Vulnerability Details
File Location:
scripts/smart-search.js, lines 8 and 76–83
Vulnerability Type: Unrestricted credential forwarding to a configurable endpoint
Risk Level: MediumVulnerable Code
js const BASE_URL = process.env.TAVILY_BASE_URL || "https://api.tavily.com";js const response = await fetch(`${BASE_URL}/search`, { method: "POST", headers: { "Content-Type": "application/json", "Authorization": `Bearer ${apiKey}`, "X-Client-Source": "openclaw-tavily-plus" }, body: JSON.stringify(body), signal: AbortSignal.timeout(DEFAULT_TIMEOUT) });Technical Analysis
The
TAVILY_BASE_URLenvironment variable is accepted without validating its scheme, hostname, port, or trust boundary. The search function then attaches the selected Tavily API key to theAuthorizationheader of every request made to that URL.Consequently, anyone able to influence the process environment can redirect requests to an attacker-controlled endpoint. Invoking the skill then sends both the Tavily credential and the user's search query to that endpoint. The API-key rotation logic can expose additional configured keys during repeated requests or simulated HTTP 429 responses.
This is a credential-exfiltration weakness caused by forwarding secrets to an unrestricted destination.
Attack Path
- An attacker gains the ability to control or influence
TAVILY_BASE_URLin the skill's execution environment. - The attacker sets it to an endpoint under their control, such as
https://attacker.example. - A user or agent invokes
smartSearch. getApiKey()reads a Tavily API key from the environment.searchWithRetry()sends a request tohttps://attacker.example/searchwith the key in theAuthorization: Bearer ...header.- The attacker's server records the credential and the user's query.
- If the server responds with HTTP 429, the retry logic may send other configured keys in subsequent requests.
Impact
...[truncated 525 chars]
- An attacker gains the ability to control or influence
- Remediation
View remediation
Remediation Suggestions
- Parse the configured URL with the standard
URLclass and reject malformed values. - Require HTTPS and reject plaintext HTTP or other schemes.
- Enforce an explicit hostname allowlist, such as
api.tavily.com, before attaching credentials. - Reject unexpected ports, embedded credentials, and untrusted redirects.
- Disable automatic cross-origin redirects or revalidate the final destination before forwarding the
Authorizationheader. - If custom Tavily-compatible endpoints are required, make that behavior an explicit trusted-administrator setting rather than an unrestricted environment override.
- Bind each credential to its intended origin and never reuse Tavily production keys for a different host.
- Add tests confirming that attacker-controlled hosts, non-HTTPS URLs, deceptive subdomains, and redirects cannot receive API keys.
- Rotate any API keys that may previously have been used while
TAVILY_BASE_URLpointed to an untrusted destination.
Example validation pattern:
js const configuredUrl = process.env.TAVILY_BASE_URL || "https://api.tavily.com"; const parsedBaseUrl = new URL(configuredUrl); if ( parsedBaseUrl.protocol !== "https:" || parsedBaseUrl.hostname !== "api.tavily.com" || parsedBaseUrl.port !== "" ) { throw new Error("Untrusted Tavily API endpoint"); } const BASE_URL = parsedBaseUrl.origin;- Parse the configured URL with the standard
