Skip to content

fix(ollama): bypass managed proxy for loopback embeddings - #85707

Merged
steipete merged 23 commits into
openclaw:mainfrom
Kaspre:fix/ollama-loopback-embedding-proxy-gap
May 23, 2026
Merged

steipete merged 23 commits into
openclaw:mainfrom
Kaspre:fix/ollama-loopback-embedding-proxy-gap

Conversation

@Kaspre

@Kaspre Kaspre commented May 23, 2026 •

Copy link
Copy Markdown
Contributor

Replacement for closed #85448

This PR (#85707) is the ready replacement for #85448. That PR was closed as superseded by #80751, but GitHub reports the closed PR cannot be reopened by this contributor identity. The replacement branch points at the same final reviewed code head, 5093f4eddf37ea75435973ded15e4ec5ca7f97c7; no code changed from the proofed #85448 final head.

The #81249 fix set: what each PR covers

Issue #81249 has multiple managed-proxy/local-loopback paths. #80751 fixed one boundary, #83255 is aimed at another, and this PR fills the remaining Ollama memory embedding gap.

1. What #80751 already fixed

#80751 fixed the SSRF trust decision for configured custom / local model provider baseUrl values. Its proof exercised the buildGuardedModelFetch OpenAI-compatible model request path (POST /v1/chat/completions) and showed that an exact configured private/loopback model-provider origin can pass SSRF validation while different ports, metadata addresses, and other private targets stay blocked.

That change did not add a general NO_PROXY / proxy bypass mechanism. It also did not change the bundled Ollama memory embedding provider (extensions/ollama/src/embedding-provider.ts) or the managed-proxy transport decision. After #80751, strict guarded fetch can allow the exact loopback origin but still route the request through createHttp1EnvHttpProxyAgent whenever the managed proxy is active and proxy env is configured.

2. What #83255 is intended to fix

#83255 is the browser/CDP path. It adds a narrow managed-proxy bypass for the exact loopback Chrome DevTools HTTP discovery and WebSocket endpoints used by the managed browser profile, for failures like cdp=http://127.0.0.1:<port> and ws://127.0.0.1:<port>/devtools/browser/... returning proxy 502/503.

That PR is still open at the time this replacement PR is opened. It does not change Ollama, model-provider, or embedding-provider routing.

3. What this PR fills

PR #85707 fills the remaining #81249 gap for bundled Ollama memory embeddings. The Ollama memory embedding provider calls /api/embed on the configured Ollama baseUrl; with proxy.enabled=true, that request can still be sent through the managed proxy. If the proxy container cannot reach the OpenClaw host's loopback service, http://127.0.0.1:11434 / local Ollama can still fail even after #80751.

The fix is intentionally narrow: bundled Ollama memory embeddings may use a private internal configured-local-origin helper that can bypass the managed proxy only for the exact configured loopback origin, after DNS/policy validation, and only when proxy.loopbackMode allows it. Public, LAN/private non-loopback, unrelated local services, different ports, metadata addresses, and redirects away from the configured origin do not get this bypass.

Problem

When proxy.enabled=true, OpenClaw routes strict HTTP fetches through the managed forward proxy. That is the right default for ordinary egress, but it breaks the bundled Ollama memory embedding provider when the configured Ollama baseUrl points at a host-local loopback service such as http://127.0.0.1:11434: a remote or policy-strict proxy cannot reach the OpenClaw host's loopback service.

Change and value

This PR lets the bundled Ollama memory embedding provider mark its exact configured loopback baseUrl as eligible for a guarded managed-proxy direct path. When the managed proxy is active, guarded fetch still resolves and validates the destination first, then uses a pinned direct dispatcher only when the request origin exactly matches the configured provider origin, the configured origin is loopback, all resolved target addresses are loopback, and proxy.loopbackMode allows it.

The practical effect is that host-local Ollama memory embeddings can work with proxy.enabled=true without creating a general local-network bypass. Public, LAN/private, and otherwise non-loopback Ollama origins stay on the managed proxy path.

Who is affected, and who is not

Affected:

  • Users running the bundled Ollama memory embedding provider against a loopback Ollama baseUrl while the managed proxy is active.
  • Operators who need proxy.loopbackMode to keep explicit control over loopback behavior.

Not affected:

  • Public Ollama Cloud or other public embedding endpoints: these stay on the managed proxy path.
  • LAN/private non-loopback Ollama endpoints: these are not granted a direct proxy bypass by this PR.
  • Browser/CDP loopback discovery and WebSocket routing: that is the separate fix(browser): bypass managed proxy for loopback CDP #83255 scope.
  • General user WebUIs, arbitrary local model servers, and other local-network targets: this does not add a broad bypass.
  • Redirects away from the configured Ollama origin: those are re-evaluated and do not inherit the bypass.

Implementation

  • Adds a private internal configured-local-origin managed-proxy bypass marker for core/bundled-provider use.
  • Keeps the bypass marker out of the public openclaw/plugin-sdk/ssrf-runtime option surface; public fetchWithSsrFGuard strips forged markers before delegating.
  • Exposes the helper only through openclaw/plugin-sdk/ssrf-runtime-internal, which is private, local-only, not package-exported, and scoped by the plugin SDK alias resolver to the bundled Ollama plugin source/dist paths.
  • Keeps staged bundled plugin runtime aliases public-only, with no wildcard and no emitted ssrf-runtime-internal artifact.
  • In managed-proxy strict mode, resolves the request hostname under the existing SSRF policy before deciding transport.
  • Uses direct pinned dispatch only when the request origin exactly matches the configured origin, the configured origin is loopback, all resolved addresses are loopback, and proxy.loopbackMode allows it.
  • Keeps public, LAN/private, and otherwise non-loopback configured origins on the managed proxy path.
  • Honors proxy.loopbackMode: "proxy" by leaving loopback traffic on the proxy path.
  • Honors proxy.loopbackMode: "block" by rejecting loopback provider traffic before opening a connection, including bracketed IPv6 loopback URLs.
  • Switches the Ollama embedding SSRF policy from configured hostname trust to configured exact-origin trust.
  • Documents the narrower Ollama memory embedding behavior in the provider and network proxy docs.

Security and maintainer decision

This intentionally treats an exact configured loopback Ollama embedding origin as operator-trusted local IPC for the bundled embedding provider. That matches the local-provider direction from #80751, but it is still a managed-proxy policy exception: under the default loopback mode, exact configured loopback Ollama embedding traffic can bypass the operator-managed forward proxy.

Maintainers should explicitly accept that policy exception. Operators who do not want this behavior can keep loopback traffic on the proxy path with proxy.loopbackMode: "proxy", or block configured local-provider loopback traffic with proxy.loopbackMode: "block".

The bypass is not a new public plugin SDK contract.

Out of scope

Verification

Exact code head under review: 5093f4eddf37ea75435973ded15e4ec5ca7f97c7.

Replacement PR opening preflight against current origin/main at 55a0c9b1f47453b0a5b78a20cec033843c73bae4:

  • git merge-tree --write-tree origin/main HEAD produced a clean merge tree.
  • git diff --check origin/main...HEAD passed.

Review gates completed at the exact code head:

  • Claude --print multi-lane review with the full current diff embedded: security/public-surface, package/runtime, and proof/tests lanes had no blocking findings after triage.
  • Codex review against origin/main: no discrete actionable regressions found.
  • Read-only adversarial review lanes: security and package/runtime lanes cleared; proof/process findings were fixed by correcting the validation script's diff-check target and pinned-main classification behavior.

Focused exact-head gates passed:

  • node --check scripts/stage-bundled-plugin-runtime.mjs
  • git diff --check origin/main...HEAD
  • src/plugins/stage-bundled-plugin-runtime.test.ts (14 passed)
  • src/infra/net/fetch-guard.ssrf.test.ts (79 passed)
  • extensions/ollama/src/embedding-provider.test.ts (21 passed)
  • src/plugins/plugin-sdk-native-resolver.test.ts (5 passed)
  • src/plugins/sdk-alias.test.ts -t "aliases the Ollama SSRF internal helper only for the bundled Ollama plugin" (1 passed / 54 skipped)
  • src/plugins/loader.test.ts -t "private local-only plugin-sdk artifacts out" (2 passed / 134 skipped)
  • plugin-sdk-package-contract-guardrails.test.ts -t "configured local-origin fetch helpers" (2 passed / 18 skipped)

Final remote validation and full-suite classification from #85448's final reviewed head:

  • Remote environment: GCP Spot us-east1-c, e2-standard-8, lease cbx_d95a340b2c96 / blue-prawn.
  • PR head: 5093f4eddf37ea75435973ded15e4ec5ca7f97c7.
  • Pinned comparison main: 9ff1a4371f6867825022c10688395cbc0e3c6d3e.
  • Live origin/main advanced to 0b2ab6c... during the run, so the classifier kept the launch-time pinned main for an apples-to-apples comparison.

Remote focused gates passed on the PR head:

  • pr-install rc=0
  • pr-diff-check rc=0
  • pr-sdk-subpath rc=0
  • pr-sdk-api rc=0
  • pr-sdk-surface rc=0
  • pr-sdk-alias-test rc=0 (55 passed)
  • pr-plugin-contract-test rc=0 (42 passed)
  • pr-bundled-loader-alias-test rc=0 (4 passed / 132 skipped)
  • pr-tsgo-prod rc=0
  • pr-fetch-guard-test rc=0 (79 passed)
  • pr-ollama-embedding-test rc=0 (21 passed)

Full-suite classification from the same remote environment:

  • PR pnpm test: red, 13 failed files parsed.
  • Pinned-main pnpm test: red, 14 failed files parsed.
  • PR-only failed files: 0.
  • Main-only failed files: 1 (src/pairing/pairing-store.test.ts).

Inherited PR red paths, all present on pinned main:

  • src/agents/agent-command.live-model-switch.test.ts
  • src/agents/bash-tools.exec-approval-followup.test.ts
  • src/agents/pi-embedded-runner/compact.hooks.test.ts
  • src/agents/pi-embedded-runner/model.forward-compat.errors-and-overrides.test.ts
  • src/agents/subagent-announce-delivery.test.ts
  • src/agents/subagent-registry.announce-loop-guard.test.ts
  • src/commands/models/list.list-command.forward-compat.test.ts
  • src/gateway/call.test.ts
  • src/gateway/client.watchdog.test.ts
  • src/gateway/handshake-timeouts.test.ts
  • src/gateway/server-runtime-config.test.ts
  • src/gateway/server-startup-config.secrets.test.ts
  • src/gateway/server.preauth-hardening.test.ts

Real behavior proof

Behavior or issue addressed: Ollama memory embeddings configured to a host-local loopback baseUrl should still work when OPENCLAW_PROXY_ACTIVE=1 and HTTP(S)_PROXY points at a managed proxy that cannot reach host loopback. The same path should keep proxy.loopbackMode=proxy on the proxy path and should not trust redirects away from the configured origin.

Real environment tested: Exact PR head 5093f4eddf37ea75435973ded15e4ec5ca7f97c7 in the OpenClaw source worktree, Node v26.1.0. The proof starts a fake Ollama-compatible /api/embed service on 127.0.0.1:<random> and a fake managed proxy on 127.0.0.1:<random> that returns 503 for ordinary and CONNECT requests. It sets OPENCLAW_PROXY_ACTIVE=1, points HTTP_PROXY/HTTPS_PROXY at the fake proxy, and clears proxy bypass environment for the request.

Exact steps or command run after this patch: A temporary proof harness imported extensions/ollama/src/embedding-provider.ts, created the real Ollama embedding provider with remote.baseUrl set to the fake loopback service, and executed three requests: default loopback mode, proxy.loopbackMode=proxy, and a cross-origin loopback redirect.

Evidence after fix:

DEFAULT_BYPASS ok ollamaHits=1 proxyHits=0
PROXY_MODE ok ollamaHits=0 proxyHits=1
[security] blocked URL fetch (ollama-memory-embedding) targetOrigin=http://127.0.0.1:<redirect-port> reason=Blocked hostname or private/internal/special-use IP address
REDIRECT_REEVALUATION ok targetHits=0 proxyHits=0

Observed result after fix: In default loopback mode, the real Ollama embedding provider code reached the fake host-local Ollama service directly, returned the normalized vector [0.6, 0.8], and did not hit the fake proxy. With proxy.loopbackMode=proxy, the same request hit and failed through the fake proxy without reaching fake Ollama. A redirect from the configured origin to a different loopback port was blocked by the existing SSRF guard before reaching the redirect target or proxy.

What was not tested: A real Ollama daemon/local model was not exercised. The proof covers the provider transport and response-handling path with an Ollama-compatible fake /api/embed endpoint and fake managed proxy, not actual local model execution. Full pnpm test remains red in the remote environment, but the exact-head comparison classified the red paths as inherited from pinned origin/main, with no PR-only failed files.

Related #81249.
Supersedes closed #85448.

@Kaspre
Kaspre requested a review from a team as a code owner May 23, 2026 11:37
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation scripts Repository scripts extensions: ollama size: XL triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels May 23, 2026
@clawsweeper

clawsweeper Bot commented May 23, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

Latest ClawSweeper review: 2026-05-23 19:39 UTC / May 23, 2026, 3:39 PM ET.

Workflow note: Future ClawSweeper reviews update this same comment in place.

How this review workflow works
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

PR Surface
Source +413, Tests +786, Docs +13, Generated 0, Other +115. Total +1327 across 23 files.

View PR surface stats
Area Files Added Removed Net
Source 9 475 62 +413
Tests 8 809 23 +786
Docs 2 18 5 +13
Config 0 0 0 0
Generated 1 2 2 0
Other 3 119 4 +115
Total 23 1423 96 +1327

Summary
The PR changes Ollama memory embeddings to use a guarded direct path for exact configured loopback origins under managed proxy mode, with private SDK alias guardrails, tests, and docs.

Reproducibility: yes. from source, not from a live run: current main routes strict guarded Ollama embedding fetches through the env proxy when managed proxy mode is active. I did not run a live fake-proxy repro in this read-only review.

PR rating
Overall: 🦪 silver shellfish
Proof: 🦪 silver shellfish
Patch quality: 🐚 platinum hermit
Summary: The patch is coherent and covered by focused tests, but stale real behavior proof and the open security-boundary decision keep overall readiness low.

Rank-up moves:

  • Update the Real behavior proof section with current-head terminal or log output for the fake Ollama plus fake managed-proxy scenario, with private details redacted.
  • Get explicit maintainer acceptance or requested changes for the default loopback bypass policy and private bundled-only SDK seam.
  • Classify the current failed check runs against main or rerun after proof is refreshed.
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Real behavior proof
Needs stronger real behavior proof before merge: The PR body supplies terminal-style after-fix proof, but it is stale because it names 5093f4e while the current head is 15a7da3; update the PR body with current-head redacted logs or terminal output.

Risk before merge

  • The current PR head lacks fresh real behavior proof: the posted terminal proof is for 5093f4e, before later bypass and type changes ending at 15a7da3.
  • Under default proxy.loopbackMode gateway-only, exact configured loopback Ollama embedding calls can bypass the operator-managed forward proxy unless operators choose proxy or block mode.
  • The private openclaw/plugin-sdk/ssrf-runtime-internal seam is guarded as bundled-Ollama-only, but maintainers still need to accept that private SDK boundary as the long-term shape.
  • Current public check data for the head includes at least two failing check runs, so CI needs normal classification before merge.

Maintainer options:

  1. Refresh current-head proof (recommended)
    Require terminal or log proof at 15a7da3 showing default bypass, proxy mode, and redirect revalidation before merge.
  2. Accept scoped local IPC
    Maintainers can intentionally accept exact configured loopback Ollama embeddings as trusted local IPC under the default loopback mode.
  3. Ask for a stricter policy shape
    If the default bypass or private SDK seam is not acceptable, ask for proxy-by-default behavior, explicit opt-in, or a different owner-approved internal hook.

Next step before merge
The remaining blocker is maintainer security/product acceptance plus refreshed current-head proof, not a safe automated repair.

Security
Needs attention: No supply-chain issue was found, but the diff intentionally changes a managed-proxy security boundary and needs maintainer policy acceptance.

Review details

Best possible solution:

Land the narrow guarded implementation only after maintainers accept the scoped Ollama local-IPC exception and private bundled-only SDK seam, and after current-head transport proof plus CI classification are in place.

Do we have a high-confidence way to reproduce the issue?

Yes from source, not from a live run: current main routes strict guarded Ollama embedding fetches through the env proxy when managed proxy mode is active. I did not run a live fake-proxy repro in this read-only review.

Is this the best way to solve the issue?

Unclear until maintainer decision: the patch is narrow and well-guarded, but the default local-IPC exception and private SDK seam are policy/API-shape choices. A safer alternative, if maintainers reject the default bypass, is an explicit opt-in or different owner-approved internal hook.

Label justifications:

  • P2: The PR addresses a real but bounded Ollama managed-proxy workflow failure.
  • merge-risk: 🚨 compatibility: The PR changes default managed-proxy routing for existing loopback Ollama embedding setups under proxy.loopbackMode gateway-only.
  • merge-risk: 🚨 security-boundary: The PR intentionally creates a scoped bypass around the operator-managed forward proxy for a local-provider path.
  • rating: 🦪 silver shellfish: Current PR rating is 🦪 silver shellfish because proof is 🦪 silver shellfish, patch quality is 🐚 platinum hermit, and The patch is coherent and covered by focused tests, but stale real behavior proof and the open security-boundary decision keep overall readiness low.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs stronger real behavior proof before merge: The PR body supplies terminal-style after-fix proof, but it is stale because it names 5093f4e while the current head is 15a7da3; update the PR body with current-head redacted logs or terminal output.

Security concerns:

  • [medium] Accept the scoped proxy bypass policy — src/infra/net/fetch-guard.ts:474
    Exact configured loopback Ollama embedding traffic can bypass the operator-managed forward proxy under the default loopback mode, which is a deliberate security-boundary decision rather than a pure mechanical fix.
    Confidence: 0.88

What I checked:

  • current main Ollama embedding path: On current main, Ollama memory embeddings call the public strict SSRF guarded fetch helper with the configured base URL policy and no loopback direct-transport hook. (extensions/ollama/src/embedding-provider.ts:97, d2e9f91cecc7)
  • current main managed proxy behavior: On current main, strict guarded fetch resolves the destination under SSRF policy, then selects createHttp1EnvHttpProxyAgent whenever managed proxy mode is active and proxy env is configured. (src/infra/net/fetch-guard.ts:415, d2e9f91cecc7)
  • PR direct-bypass guard: The PR only switches the strict managed-proxy branch to a pinned direct dispatcher when shouldUseConfiguredLocalOriginManagedProxyBypass approves the request after DNS/policy resolution. (src/infra/net/fetch-guard.ts:474, 15a7da374382)
  • PR bypass policy helper: The new helper requires an exact configured origin, a loopback configured hostname, loopback resolved addresses, and honors proxy.loopbackMode proxy/block behavior. (src/infra/net/configured-local-origin-bypass.ts:59, 15a7da374382)
  • private SDK alias scope: The PR adds an owner-scoped private SDK subpath for bundled Ollama and keeps it out of unrelated bundled or installed plugin paths in the alias owner registry. (src/plugins/sdk-alias.ts:280, 15a7da374382)
  • proof mismatch: The PR body's real behavior proof names exact code head 5093f4e, while the current PR head is 15a7da3 after later bypass/type changes. (15a7da374382)

Likely related people:

  • steipete: Current-main blame for the central Ollama embedding and fetch-guard paths points to Peter Steinberger, and the latest two commits on this PR are authored by steipete to tighten the bypass and type registry. (role: recent area contributor and current PR follow-up owner; confidence: high; commits: b47bace01423, fe2cd84e4090, 15a7da374382; files: extensions/ollama/src/embedding-provider.ts, src/infra/net/fetch-guard.ts, src/plugins/sdk-alias.ts)
  • Kaspre: Kaspre authored this PR and also authored the merged exact-origin SSRF policy PR that the Ollama transport fix builds on, so they are relevant beyond just opening this branch. (role: related SSRF/Ollama proxy contributor; confidence: medium; commits: 44840007d42d, bdbf0bf46be1; files: src/infra/net/fetch-guard.ts, src/infra/net/ssrf.ts, extensions/ollama/src/embedding-provider.ts)
  • Peter Steinberger: Shortlog over the central Ollama, fetch-guard, SDK alias, and native resolver files shows the most local history under this display name, though the checkout history is compact. (role: broad adjacent owner signal; confidence: medium; commits: b47bace01423, e510042870cf; files: extensions/ollama/src/embedding-provider.ts, src/infra/net/fetch-guard.ts, src/plugins/sdk-alias.ts)

Codex review notes: model gpt-5.5, reasoning high; reviewed against d2e9f91cecc7.

@openclaw-barnacle openclaw-barnacle Bot added proof: supplied External PR includes structured after-fix real behavior proof. and removed triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels May 23, 2026
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. labels May 23, 2026
@clawsweeper

clawsweeper Bot commented May 23, 2026 •

Copy link
Copy Markdown
Contributor

ClawSweeper PR egg

🎁 Pass real behavior proof to wake the egg and unlock a hatchable treat.

Where did the egg go?
  • The egg game starts only after the PR passes the real-behavior proof check.
  • Before that, no creature or rarity is rolled. The treat waits for real proof.
  • This is still just collectible flavor: proof affects review readiness, not creature quality.

@Kaspre
Kaspre force-pushed the fix/ollama-loopback-embedding-proxy-gap branch from 5093f4e to 206242a Compare May 23, 2026 13:07
@openclaw-barnacle openclaw-barnacle Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 23, 2026
@Kaspre
Kaspre force-pushed the fix/ollama-loopback-embedding-proxy-gap branch from 8a31939 to bd9e47a Compare May 23, 2026 13:23
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 23, 2026

Kaspre commented May 23, 2026

Copy link
Copy Markdown
Contributor Author

Maintainer decision note: recommended approach

I want to make the remaining design decision explicit from the contributor side. This PR is our recommended approach for the Ollama part of #81249, not just a mechanical patch to get CI green.

Problem analysis

#80751 fixed exact-origin SSRF trust for configured local/custom provider baseUrl values. It did not change managed-proxy transport routing. With proxy.enabled=true, the strict guarded fetch path can still select the managed env-proxy dispatcher after SSRF validation. That means a configured host-local Ollama endpoint such as http://127.0.0.1:11434 can still fail when the proxy process/container cannot reach the OpenClaw host's loopback service.

For bundled Ollama memory embeddings, the configured loopback baseUrl is not ordinary egress. It is the operator intentionally pointing OpenClaw at local IPC. The bug is that the managed-proxy transport layer treats that local IPC request like external egress even after the configured-origin policy decision has been made.

Viable approaches

  1. Accept the scoped Ollama IPC exception. This is the current PR and our recommendation. It lets only the bundled Ollama memory embedding path request direct transport for the exact configured loopback origin. The guarded fetch path still resolves and validates the target first, requires all resolved addresses to be loopback, requires the request origin to exactly match the configured base origin, re-evaluates redirects, and still honors proxy.loopbackMode.

  2. Require an explicit opt-in for direct loopback embeddings. This is the most conservative policy option, but it adds another configuration surface and leaves the common local-Ollama setup broken by default even though the operator already configured a loopback Ollama baseUrl. It would still need nearly the same guarded direct-transport implementation, just hidden behind one more knob. I would choose this only if maintainers do not want proxy.loopbackMode: gateway-only to treat configured loopback Ollama as trusted local IPC.

  3. Pause or replace the private SDK seam. If maintainers do not want openclaw/plugin-sdk/ssrf-runtime-internal even as a bundled-only private subpath, the alternative is an owner-approved internal hook or a deeper core/provider integration. That may be cleaner architecturally, but it is a larger refactor and would delay the user-facing fix. The current seam is intentionally private and narrow: public fetchWithSsrFGuard strips forged bypass markers, the internal subpath is excluded from package exports/staged public SDK artifacts, and aliasing is scoped to bundled Ollama source/dist/runtime paths rather than installed external plugins.

  4. Use a broader NO_PROXY/loopback bypass. I do not recommend this. It would be simpler operationally, but it weakens the boundary by bypassing the managed proxy for more traffic than this bug requires and would be harder to reason about with DNS pinning, redirects, and non-Ollama local services.

Why this PR is the recommended approach

The current patch matches the actual ownership boundary: Ollama memory embeddings are the only path asking for this exception, and only for the exact configured loopback origin. Public, LAN/private non-loopback, public cloud, mismatched port, and redirect targets do not inherit the bypass. Operators who want stricter behavior still have the existing policy controls: proxy.loopbackMode: proxy keeps loopback traffic on the managed proxy path, and proxy.loopbackMode: block rejects the loopback provider request before opening a connection.

That makes this smaller and safer than a general proxy bypass, while avoiding a new public config knob for the normal local-Ollama case.

Addressing the review risks

  • Default proxy.loopbackMode: gateway-only policy: yes, this PR intentionally treats exact configured loopback Ollama memory embeddings as trusted local IPC under the default mode. Maintainer acceptance of that policy is the main decision needed before merge.
  • Private SDK/internal helper seam: the private helper is meant to be bundled-Ollama-only, not public plugin SDK API. The patch includes guardrails for public export exclusion, staged runtime exclusion, forged marker stripping, and alias scoping. If maintainers dislike this seam, I would rather replace it with an explicit owner-approved core/internal hook than make the helper public.
  • Proof uses fake Ollama service: that is intentional and sufficient for the transport claim. The failure being fixed is routing/proxy/SSRF behavior, not model quality or Ollama daemon lifecycle. The proof exercises the real embedding provider transport and response-handling path against an Ollama-compatible /api/embed endpoint plus a fake managed proxy. A real daemon smoke test would be useful extra confidence, but I do not think it should be required to decide the proxy policy.

Maintainer ask

Our recommendation is option 1: accept the scoped Ollama IPC exception and the bundled-only private seam as implemented. If maintainers prefer option 2 or 3, I can revise in that direction, but I would avoid broad NO_PROXY-style behavior.

@steipete steipete self-assigned this May 23, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 23, 2026
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels May 23, 2026
@steipete
steipete force-pushed the fix/ollama-loopback-embedding-proxy-gap branch from f50710e to 15a7da3 Compare May 23, 2026 19:32
@openclaw-barnacle openclaw-barnacle Bot added the gateway Gateway runtime label May 23, 2026
@steipete
steipete merged commit fd2a9ad into openclaw:main May 23, 2026
105 of 107 checks passed
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 24, 2026
…5707)

* fix(ollama): bypass proxy for local embeddings

* fix(ollama): keep managed proxy bypass loopback-only

* fix(ollama): keep proxy bypass internal

* fix(ollama): keep proxy bypass private

* fix(ollama): harden internal proxy bypass

* chore(plugin-sdk): refresh api baseline

* fix(ollama): keep internal bypass out of qa aliases

* test(ollama): keep ssrf runtime mock complete

* fix(ollama): keep dist sdk aliases public-only

* fix(ollama): keep fetch bypass out of infra runtime

* fix(ollama): preserve packaged private sdk alias

* test(ollama): harden private ssrf alias coverage

* test(ollama): cover private ssrf resolver edges

* fix(ollama): scope private sdk native aliases

* test(ollama): audit blocked loopback bypasses

* fix(plugins): keep staged sdk aliases public-only

* test(ollama): harden proxy bypass proof

* test(ollama): cover origin mismatch proxy path

* test(ollama): cover ipv6 and batch bypass paths

* fix lint findings in Ollama proxy tests

* refactor: tighten Ollama proxy bypass

* fix: widen private sdk owner registry type

* test: stabilize Ollama proxy PR checks

---------

Co-authored-by: Peter Steinberger <[email protected]>
jameslcowan pushed a commit to jameslcowan/openclaw that referenced this pull request Jun 2, 2026
…5707)

* fix(ollama): bypass proxy for local embeddings

* fix(ollama): keep managed proxy bypass loopback-only

* fix(ollama): keep proxy bypass internal

* fix(ollama): keep proxy bypass private

* fix(ollama): harden internal proxy bypass

* chore(plugin-sdk): refresh api baseline

* fix(ollama): keep internal bypass out of qa aliases

* test(ollama): keep ssrf runtime mock complete

* fix(ollama): keep dist sdk aliases public-only

* fix(ollama): keep fetch bypass out of infra runtime

* fix(ollama): preserve packaged private sdk alias

* test(ollama): harden private ssrf alias coverage

* test(ollama): cover private ssrf resolver edges

* fix(ollama): scope private sdk native aliases

* test(ollama): audit blocked loopback bypasses

* fix(plugins): keep staged sdk aliases public-only

* test(ollama): harden proxy bypass proof

* test(ollama): cover origin mismatch proxy path

* test(ollama): cover ipv6 and batch bypass paths

* fix lint findings in Ollama proxy tests

* refactor: tighten Ollama proxy bypass

* fix: widen private sdk owner registry type

* test: stabilize Ollama proxy PR checks

---------

Co-authored-by: Peter Steinberger <[email protected]>
sablehead pushed a commit to sablehead/openclaw that referenced this pull request Jun 10, 2026
…5707)

* fix(ollama): bypass proxy for local embeddings

* fix(ollama): keep managed proxy bypass loopback-only

* fix(ollama): keep proxy bypass internal

* fix(ollama): keep proxy bypass private

* fix(ollama): harden internal proxy bypass

* chore(plugin-sdk): refresh api baseline

* fix(ollama): keep internal bypass out of qa aliases

* test(ollama): keep ssrf runtime mock complete

* fix(ollama): keep dist sdk aliases public-only

* fix(ollama): keep fetch bypass out of infra runtime

* fix(ollama): preserve packaged private sdk alias

* test(ollama): harden private ssrf alias coverage

* test(ollama): cover private ssrf resolver edges

* fix(ollama): scope private sdk native aliases

* test(ollama): audit blocked loopback bypasses

* fix(plugins): keep staged sdk aliases public-only

* test(ollama): harden proxy bypass proof

* test(ollama): cover origin mismatch proxy path

* test(ollama): cover ipv6 and batch bypass paths

* fix lint findings in Ollama proxy tests

* refactor: tighten Ollama proxy bypass

* fix: widen private sdk owner registry type

* test: stabilize Ollama proxy PR checks

---------

Co-authored-by: Peter Steinberger <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation extensions: ollama gateway Gateway runtime merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P2 Normal backlog priority with limited blast radius. proof: supplied External PR includes structured after-fix real behavior proof. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. scripts Repository scripts size: XL status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants