Skip to content

Commit bcc1b3e

Browse files
committed
fix(web-search): assess the bridge search endpoint as a destination (#4519)
providers.<name>.webSearchBridge.endpoint names the URL that receives that provider's own API key as a Bearer token when the ollama bridge backend runs a search. Two checks stood in front of it and neither was a destination assessment: providerWebSearchBridgeConfigError did new URL plus an http/https protocol test, and resolveOllamaWebSearchEndpoint returned the configured value whenever originOf parsed it. Provider baseUrl has had the real assessment for a long time; the endpoint had none, so endpoint: "http://169.254.169.254/latest/meta-data" was accepted and the key was sent there. Both boundaries now run the existing providerDestinationConfigError. Metadata destinations are refused unconditionally. Loopback, localhost and private space are refused unless the provider sets allowPrivateNetwork or its name is a registry entry that is local by definition, which is what keeps a self-hosted Ollama working. The plan-time check is the load-bearing one, not a second opinion. A hand-edited config file, ocx config set and ocx config import all reach configSchema only and never call providerWebSearchBridgeConfigError, and resolveOllamaWebSearchEndpoint is the only reader of this field in the tree, so a value that survives file load still cannot be spent. It refuses silently by design; config-time is where the operator is told why. Both checks are synchronous and literal-only and resolve no DNS, so a hostname that resolves into metadata or private space still passes. No new classifier was written and no DNS was added at this boundary.
1 parent f7e4af0 commit bcc1b3e

6 files changed

Lines changed: 276 additions & 24 deletions

File tree

‎src/config.ts‎

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -507,9 +507,15 @@ export function requestPacingConfigError(value: unknown): string | null {
507507
/**
508508
* Bounds for the opt-in passthrough web-search bridge (`providers.<name>.webSearchBridge`,
509509
* #3761). Strict for the same reason `retryOn429` is: a misspelled key here would silently
510-
* leave the bridge disarmed while the operator believes they enabled it. `endpoint` is only
511-
* shape-checked here; `planPassthroughWebSearchBridge` re-validates the origin before any key
512-
* is sent to it, because config validation is not an authorization boundary.
510+
* leave the bridge disarmed while the operator believes they enabled it.
511+
*
512+
* `endpoint` names the destination that receives this provider's API key, so it gets the same
513+
* literal destination assessment `baseUrl` gets (#4519) — see `providerWebSearchBridgeConfigError`
514+
* below. This schema itself still only shape-checks: it is `.catch(undefined)` at the provider
515+
* row, and a hand-edited config file never reaches the error function at all. The authorization
516+
* boundary is therefore `resolveOllamaWebSearchEndpoint`, which runs the same assessment and is
517+
* the only reader of this field in the tree; config validation is where an operator is told why,
518+
* not what makes the value safe.
513519
*/
514520
const providerWebSearchBridgeSchema = z.object({
515521
enabled: z.boolean().optional(),
@@ -519,7 +525,11 @@ const providerWebSearchBridgeSchema = z.object({
519525
endpoint: z.string().min(1).optional(),
520526
}).strict();
521527

522-
export function providerWebSearchBridgeConfigError(value: unknown): string | null {
528+
export function providerWebSearchBridgeConfigError(
529+
value: unknown,
530+
providerName: string,
531+
provider: Pick<OcxProviderConfig, "allowPrivateNetwork">,
532+
): string | null {
523533
if (value === undefined) return null;
524534
if (!value || typeof value !== "object" || Array.isArray(value)) {
525535
return "webSearchBridge must be a plain object";
@@ -541,6 +551,17 @@ export function providerWebSearchBridgeConfigError(value: unknown): string | nul
541551
if (url.protocol !== "https:" && url.protocol !== "http:") {
542552
return "webSearchBridge.endpoint must be an absolute http(s) URL";
543553
}
554+
// Same classifier baseUrl uses, so a metadata address is refused outright and loopback or
555+
// private space needs the provider's allowPrivateNetwork opt-in (or a registry entry that is
556+
// local by definition, which is what keeps a self-hosted Ollama working). Literal-only and
557+
// synchronous, exactly as at the baseUrl boundary: no DNS is resolved here.
558+
const destinationError = providerDestinationConfigError(providerName, {
559+
baseUrl: endpoint,
560+
allowPrivateNetwork: provider.allowPrivateNetwork,
561+
});
562+
if (destinationError) {
563+
return destinationError.replace(/^baseUrl/, "webSearchBridge.endpoint");
564+
}
544565
}
545566
return null;
546567
}

‎src/server/auth-cors.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ export function providerManagementConfigError(
766766
if (requestPacingError) {
767767
return `provider ${JSON.stringify(redactSecretString(name))} ${requestPacingError}`;
768768
}
769-
const webSearchBridgeError = providerWebSearchBridgeConfigError(raw.webSearchBridge);
769+
const webSearchBridgeError = providerWebSearchBridgeConfigError(raw.webSearchBridge, name, typed);
770770
if (webSearchBridgeError) {
771771
return `provider ${JSON.stringify(redactSecretString(name))} ${webSearchBridgeError}`;
772772
}

‎src/server/responses/core.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6251,6 +6251,7 @@ async function handleResponsesInner(
62516251
openAiSidecar,
62526252
);
62536253
const webSearchBridgePlan = planPassthroughWebSearchBridge(parsed, route.provider, {
6254+
providerName: route.providerName,
62546255
isPassthrough: true,
62556256
stream: parsed.stream === true,
62566257
auth: webSearchBridgeAuth,

‎src/web-search/passthrough-bridge.ts‎

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ import {
6464
resolveSidecarBackend,
6565
xaiSearchOptionsFromConfig,
6666
} from "./sidecar-providers";
67+
import { providerDestinationConfigError } from "../lib/destination-policy";
6768

6869
/** Canonical Ollama Cloud origin. The only origin the "ollama" backend derives on its own. */
6970
export const OLLAMA_CLOUD_ORIGIN = "https://ollama.com";
@@ -123,13 +124,28 @@ function originOf(value: string | undefined): string | undefined {
123124
* that receives this provider's API key. Without one, the origin must be canonical Ollama Cloud
124125
* -- a renamed row pointing at an arbitrary host must not silently receive the key just because
125126
* its adapter happens to be openai-responses.
127+
*
128+
* Naming a destination is not the same as it being an allowed one. The endpoint therefore gets the
129+
* same literal destination assessment "baseUrl" already gets (#4519): metadata addresses are
130+
* refused outright, and loopback/private need the provider's "allowPrivateNetwork" opt-in or a
131+
* registry entry that is local by definition, so a local Ollama on 127.0.0.1 keeps working. This
132+
* is the ONLY reader of "webSearchBridge.endpoint" in the tree, which is what lets it act as the
133+
* authorization boundary for a config file the operator edited by hand -- that path never reaches
134+
* "providerWebSearchBridgeConfigError". The refusal is deliberately silent: config-time is where
135+
* an operator is told why, and a value that survives file load simply cannot be spent.
126136
*/
127137
export function resolveOllamaWebSearchEndpoint(
138+
providerName: string,
128139
provider: OcxProviderConfig,
129140
): string | undefined {
130141
const configured = provider.webSearchBridge?.endpoint;
131142
if (configured !== undefined) {
132-
return originOf(configured) === undefined ? undefined : configured;
143+
if (originOf(configured) === undefined) return undefined;
144+
if (providerDestinationConfigError(providerName, {
145+
baseUrl: configured,
146+
allowPrivateNetwork: provider.allowPrivateNetwork,
147+
})) return undefined;
148+
return configured;
133149
}
134150
return originOf(provider.baseUrl) === OLLAMA_CLOUD_ORIGIN
135151
? OLLAMA_CLOUD_ORIGIN + OLLAMA_WEB_SEARCH_PATH
@@ -211,6 +227,12 @@ export function planPassthroughWebSearchBridge(
211227
parsed: OcxParsedRequest,
212228
provider: OcxProviderConfig,
213229
options: {
230+
/**
231+
* Registry key for this provider. Required rather than optional: the destination assessment
232+
* consults the registry's local-by-default entries, and an absent name would silently pick a
233+
* different answer than the operator configured.
234+
*/
235+
providerName: string;
214236
isPassthrough: boolean;
215237
stream: boolean;
216238
auth?: PassthroughWebSearchBridgeAuth;
@@ -239,7 +261,7 @@ export function planPassthroughWebSearchBridge(
239261
? bridge.timeoutMs!
240262
: DEFAULT_BRIDGE_TIMEOUT_MS;
241263
if (backend === "ollama") {
242-
const endpoint = resolveOllamaWebSearchEndpoint(provider);
264+
const endpoint = resolveOllamaWebSearchEndpoint(options.providerName, provider);
243265
if (!endpoint) return undefined;
244266
return { backend, endpoint, maxSearches, timeoutMs };
245267
}

‎structure/runtime.md‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,25 @@ value import of the barrel; the barrel re-exports it.
261261
`tests/web-search/web-search-passthrough-bridge.test.ts` covers the mismatch and matching cases for
262262
anthropic, xai, and gemini, plus the unset-backend default.
263263

264+
`providers.<name>.webSearchBridge.endpoint` names the destination that receives that provider's own
265+
API key, so it carries the same literal destination assessment as `baseUrl`:
266+
`providerDestinationConfigError` runs both at management write time, inside
267+
`providerWebSearchBridgeConfigError`, and at plan time inside `resolveOllamaWebSearchEndpoint`.
268+
Metadata destinations are refused unconditionally; loopback, localhost, and private space need the
269+
provider's `allowPrivateNetwork` opt-in or a registry entry that is local by default, which is what
270+
keeps a self-hosted Ollama on `127.0.0.1` working. Both checks are synchronous and literal-only and
271+
resolve no DNS, so a hostname that resolves into metadata or private space is a disclosed residual
272+
rather than a blocked case. That residual is strictly larger than `baseUrl`'s: `baseUrl` also runs
273+
the async `providerDestinationResolvedError` at management write, which the endpoint does not, and
274+
parity there would still leave the hand-edited-file path uncovered because the plan-time boundary is
275+
synchronous. The plan-time check is the
276+
authorization boundary rather than a second opinion: a hand-edited config file, `ocx config set`,
277+
and `ocx config import` all reach `configSchema` only and never call
278+
`providerWebSearchBridgeConfigError`, and `resolveOllamaWebSearchEndpoint` is the only reader of
279+
this field in the tree, so a value that survives file load still cannot be spent. It refuses
280+
silently by design; config-time is where the operator is told why. The planner requires the
281+
provider name for that assessment, so `planPassthroughWebSearchBridge` takes it explicitly.
282+
264283
## Remote Hub hardening ownership
265284

266285
`src/remote/protocol.ts` owns pure interval/feature negotiation. `src/remote/hub-state.ts` owns the `GET|HEAD /v1/hub-state` contract, its caps, and the parser both sides share. `src/client/hub-client.ts` owns bounded, schema-validated remote catalog consumption, hub-state reads, and key-id probes; `src/client/hub-state.ts` owns the resolution and the owner-stamped 0600 cache, and a failed read reports "unavailable" rather than degrading to the client's own local provider and login state. `src/client/hub-relay.ts` is a fixed-authority management relay with URL, header, body, redirect, and stream bounds. The public data listener remains the direct client→hub path; the loopback management ingress never serves data-plane routes.

0 commit comments

Comments
 (0)