Skip to content

Commit 6475e09

Browse files
emesobviyus
andauthored
fix(tavily): resolve dedicated tool SecretRefs (#131082)
Resolve manifest-owned Tavily SecretRefs at startup for both dedicated tools. Capability-owned secrets now fail cold when their provider is unavailable, so stale credentials cannot reach search or extract. Configured unresolved refs still do not borrow an ambient Tavily key. Co-authored-by: Michael Smith <[email protected]> Co-authored-by: Ayaan Zaidi <[email protected]>
1 parent 11bf3cb commit 6475e09

14 files changed

Lines changed: 292 additions & 16 deletions

‎docs/plugins/manifest.md‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -858,10 +858,12 @@ Each `dangerousFlags` entry supports:
858858

859859
`secretInputs` supports:
860860

861-
| Field | Required | Type | What it means |
862-
| ----------------------- | -------- | ---------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
863-
| `bundledDefaultEnabled` | No | `boolean` | Override bundled-plugin default enablement when deciding whether this SecretRef surface is active. Use this when the plugin is bundled but the surface should stay inactive until explicitly enabled in config. |
864-
| `paths` | Yes | `object[]` | Secret-shaped config paths, each with `path` (dot-separated, relative to `plugins.entries.<id>.config`, supports `*` wildcards), optional `expected` (currently only `"string"`), and optional `ownerKind` (currently only `"route"`). A declared owner isolates only that exact matched path when resolution fails; its owner id is the full config path. |
861+
| Field | Required | Type | What it means |
862+
| ----------------------- | -------- | ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
863+
| `bundledDefaultEnabled` | No | `boolean` | Override bundled-plugin default enablement when deciding whether this SecretRef surface is active. Use this when the plugin is bundled but the surface should stay inactive until explicitly enabled in config. |
864+
| `paths` | Yes | `object[]` | Secret-shaped config paths, each with `path` (dot-separated, relative to `plugins.entries.<id>.config`, supports `*` wildcards), optional `expected` (currently only `"string"`), and optional `ownerKind` (`"capability"` or `"route"`). A declared owner isolates only that exact matched path when resolution fails; its owner id is the full config path. |
865+
866+
Capability owners fail cold when their provider is unavailable, so a stale credential never remains active. Route owners may retain the last-known-good value while their full plugin config and provider definition stay unchanged.
865867

866868
For plugins declaring `secretInputs`, `configSchema` validates the pre-resolution source config paired with the runtime config. A valid SecretRef is not rejected because its resolved credential is a string with a different shape. Invalid plaintext source values still fail validation. Runtime loading, CLI registration, and root command discovery use the same rule; plugins receive resolved values with defaults selected from the source config, without changing either input.
867869

‎docs/plugins/sdk-subpaths.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ usage endpoint failed or returned no usable usage data.
225225
| `plugin-sdk/ssrf-dispatcher` | Private-local after July 2026; Narrow pinned-dispatcher helpers without the broad infra runtime surface |
226226
| `plugin-sdk/ssrf-runtime` | Pinned-dispatcher, SSRF-guarded fetch, `SsrFBlockedError` and `GuardedFetchRedirectError`, SSRF policy helpers, and loopback/private host classification |
227227
| `plugin-sdk/secret-input` | Secret input parsing helpers and `isBuiltInDefaultSecretProviderRef(config, ref)`, which returns true when the built-in `env` or `store` provider owns its source's selected default alias, and false for a same-source explicit provider entry |
228-
| `plugin-sdk/secret-input-runtime` | Secret input normalization, SecretRef coercion, and configured secret resolution helpers |
228+
| `plugin-sdk/secret-input-runtime` | Secret input normalization, SecretRef coercion, configured secret resolution, and manifest-owned capability availability guards |
229229
| `plugin-sdk/secret-ref-readonly` | Closed available/missing/blocked resolution and provider-policy checks for read-only env SecretRefs |
230230
| `plugin-sdk/webhook-ingress` | Webhook request/target helpers and raw websocket/body coercion |
231231
| `plugin-sdk/webhook-request-guards` | Request body size/timeout helpers, canonical Gateway browser-origin acceptance via `resolveAcceptedBrowserOrigin`, and `runDetachedWebhookWork` for tracked post-ack processing |

‎extensions/tavily/openclaw.plugin.json‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,17 @@
2424
"help": "Tavily API base URL override."
2525
}
2626
},
27+
"configContracts": {
28+
"secretInputs": {
29+
"paths": [
30+
{
31+
"path": "webSearch.apiKey",
32+
"expected": "string",
33+
"ownerKind": "capability"
34+
}
35+
]
36+
}
37+
},
2738
"contracts": {
2839
"webSearchProviders": ["tavily"],
2940
"tools": ["tavily_search", "tavily_extract"]

‎extensions/tavily/src/config.ts‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export const DEFAULT_TAVILY_BASE_URL = "https://api.tavily.com";
99
const DEFAULT_TAVILY_SEARCH_TIMEOUT_SECONDS = 30;
1010
const DEFAULT_TAVILY_EXTRACT_TIMEOUT_SECONDS = 60;
1111
const TAVILY_API_KEY_ENV_VAR = "TAVILY_API_KEY";
12+
export const TAVILY_API_KEY_CONFIG_PATH = "plugins.entries.tavily.config.webSearch.apiKey";
1213

1314
type TavilySearchConfig =
1415
| {
@@ -45,11 +46,7 @@ function resolveConfiguredSecret(value: unknown, path: string, cfg?: OpenClawCon
4546

4647
export function resolveTavilyApiKey(cfg?: OpenClawConfig): string | undefined {
4748
const search = resolveTavilySearchConfig(cfg);
48-
const resolved = resolveConfiguredSecret(
49-
search?.apiKey,
50-
"plugins.entries.tavily.config.webSearch.apiKey",
51-
cfg,
52-
);
49+
const resolved = resolveConfiguredSecret(search?.apiKey, TAVILY_API_KEY_CONFIG_PATH, cfg);
5350
if (resolved.status === "available") {
5451
return resolved.value;
5552
}

‎extensions/tavily/src/tavily-client.test.ts‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ import { createStreamingResponse } from "../../test-support/streaming-error-resp
55
// Capture every call to postTrustedWebToolsJson so we can assert on extraHeaders.
66
const postTrustedWebToolsJson = vi.fn();
77
const writeCache = vi.fn();
8+
const assertPluginCapabilitySecretAvailable = vi.fn();
9+
10+
vi.mock("openclaw/plugin-sdk/secret-input-runtime", () => ({
11+
assertPluginCapabilitySecretAvailable,
12+
}));
813

914
vi.mock("openclaw/plugin-sdk/provider-web-search", async (importOriginal) => ({
1015
...(await importOriginal<typeof import("openclaw/plugin-sdk/provider-web-search")>()),
@@ -18,6 +23,7 @@ vi.mock("openclaw/plugin-sdk/provider-web-search", async (importOriginal) => ({
1823

1924
vi.mock("./config.js", () => ({
2025
DEFAULT_TAVILY_BASE_URL: "https://api.tavily.com",
26+
TAVILY_API_KEY_CONFIG_PATH: "plugins.entries.tavily.config.webSearch.apiKey",
2127
resolveTavilyApiKey: () => "test-key",
2228
resolveTavilyBaseUrl: () => "https://api.tavily.com",
2329
resolveTavilySearchTimeoutSeconds: () => 30,
@@ -33,6 +39,7 @@ describe("tavily client X-Client-Source header", () => {
3339
});
3440

3541
beforeEach(() => {
42+
assertPluginCapabilitySecretAvailable.mockReset();
3643
postTrustedWebToolsJson.mockReset();
3744
writeCache.mockReset();
3845
postTrustedWebToolsJson.mockImplementation(
@@ -41,6 +48,28 @@ describe("tavily client X-Client-Source header", () => {
4148
);
4249
});
4350

51+
it.each(["search", "extract"] as const)(
52+
"rejects unavailable capability state before %s credential or cache access",
53+
async (kind) => {
54+
const unavailable = Object.assign(new Error("Tavily capability unavailable"), {
55+
name: "SecretSurfaceUnavailableError",
56+
ownerKind: "capability",
57+
ownerId: "plugins.entries.tavily.config.webSearch.apiKey",
58+
});
59+
assertPluginCapabilitySecretAvailable.mockImplementationOnce(() => {
60+
throw unavailable;
61+
});
62+
63+
const operation =
64+
kind === "search"
65+
? runTavilySearch({ query: "unavailable" })
66+
: runTavilyExtract({ urls: ["https://example.com/unavailable"] });
67+
68+
await expect(operation).rejects.toBe(unavailable);
69+
expect(postTrustedWebToolsJson).not.toHaveBeenCalled();
70+
},
71+
);
72+
4473
it("runTavilySearch sends X-Client-Source: openclaw", async () => {
4574
await runTavilySearch({ query: "test query" });
4675

‎extensions/tavily/src/tavily-client.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
resolveCacheTtlMs,
1010
writeCache,
1111
} from "openclaw/plugin-sdk/provider-web-search";
12+
import { assertPluginCapabilitySecretAvailable } from "openclaw/plugin-sdk/secret-input-runtime";
1213
import {
1314
truncateSanitizedExternalContent,
1415
wrapExternalContent,
@@ -17,6 +18,7 @@ import {
1718
import { isRecord } from "openclaw/plugin-sdk/string-coerce-runtime";
1819
import {
1920
DEFAULT_TAVILY_BASE_URL,
21+
TAVILY_API_KEY_CONFIG_PATH,
2022
resolveTavilyApiKey,
2123
resolveTavilyBaseUrl,
2224
resolveTavilyExtractTimeoutSeconds,
@@ -138,6 +140,7 @@ export async function runTavilySearch(
138140
params: TavilySearchParams,
139141
): Promise<Record<string, unknown>> {
140142
params.signal?.throwIfAborted();
143+
assertPluginCapabilitySecretAvailable(TAVILY_API_KEY_CONFIG_PATH);
141144
const apiKey = resolveTavilyApiKey(params.cfg);
142145
if (!apiKey) {
143146
throw new Error(
@@ -270,6 +273,7 @@ export async function runTavilyExtract(
270273
params: TavilyExtractParams,
271274
): Promise<Record<string, unknown>> {
272275
params.signal?.throwIfAborted();
276+
assertPluginCapabilitySecretAvailable(TAVILY_API_KEY_CONFIG_PATH);
273277
const apiKey = resolveTavilyApiKey(params.cfg);
274278
if (!apiKey) {
275279
throw new Error(

‎scripts/check-plugin-sdk-exports.mts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ const FORBIDDEN_PUBLIC_PROTOCOL_REGISTRY_RE = /\bdeclare\s+const\s+ProtocolSchem
4949
const RELATIVE_DECLARATION_SPECIFIER_RE = /\b(?:from|import)\s*(?:\(\s*)?["']([^"']+)["']/gu;
5050
const requiredSubpathExports: Record<string, string[]> = {
5151
"secret-input-runtime": [
52+
"assertPluginCapabilitySecretAvailable",
5253
"coerceSecretRef",
5354
"hasConfiguredSecretInput",
5455
"isSecretRef",

‎scripts/plugin-sdk-surface-report.mts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,8 @@ export function readPluginSdkSurfaceBudgets(env: NodeJS.ProcessEnv = process.env
328328
// +1: prepared model-provider builder preserves the stable builder's return contract.
329329
// +1: canonical SecretRef default-alias predicate for plugin binding parity.
330330
// +2: strict session-agent resolution aliases preserve shipped Plugin SDK behavior.
331-
4355,
331+
// +1: manifest-owned plugin capability secret availability guard.
332+
4356,
332333
env,
333334
),
334335
publicFunctionExports: readPluginSdkSurfaceBudgetEnv(
@@ -433,7 +434,8 @@ export function readPluginSdkSurfaceBudgets(env: NodeJS.ProcessEnv = process.env
433434
// +1: prepared model-provider builder preserves the stable builder's return contract.
434435
// +1: canonical SecretRef default-alias predicate for plugin binding parity.
435436
// +2: strict session-agent resolution aliases preserve shipped Plugin SDK behavior.
436-
2591,
437+
// +1: manifest-owned plugin capability secret availability guard.
438+
2592,
437439
env,
438440
),
439441
publicDeprecatedExports: readPluginSdkSurfaceBudgetEnv(

‎src/plugin-sdk/secret-input-runtime.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
/**
22
* Runtime SDK subpath for secret input normalization and configured secret resolution.
33
*/
4+
import { assertSecretOwnerAvailable } from "../secrets/runtime-degraded-state.js";
5+
46
export {
57
coerceSecretRef,
68
hasConfiguredSecretInput,
@@ -17,3 +19,8 @@ export {
1719
resolveConfiguredSecretInputWithFallback,
1820
resolveRequiredConfiguredSecretRefInputString,
1921
} from "../gateway/resolve-configured-secret-input-string.js";
22+
23+
/** Reject use of a manifest-owned plugin capability whose startup secret is unavailable. */
24+
export function assertPluginCapabilitySecretAvailable(ownerId: string): void {
25+
assertSecretOwnerAvailable("capability", ownerId);
26+
}

‎src/plugins/manifest-capability-normalizers.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,8 @@ function normalizeManifestSecretInputPaths(
434434
continue;
435435
}
436436
const expected = entry.expected === "string" ? entry.expected : undefined;
437-
const ownerKind = entry.ownerKind === "route" ? entry.ownerKind : undefined;
437+
const ownerKind =
438+
entry.ownerKind === "capability" || entry.ownerKind === "route" ? entry.ownerKind : undefined;
438439
normalized.push({
439440
path: pathLocal,
440441
...(expected ? { expected } : {}),

0 commit comments

Comments
 (0)