Skip to content

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

Closed
Kaspre wants to merge 12 commits into
openclaw:mainfrom
Kaspre:fix/ollama-local-embedding-proxy-bypass
Closed

Kaspre wants to merge 12 commits into
openclaw:mainfrom
Kaspre:fix/ollama-local-embedding-proxy-bypass

Conversation

@Kaspre

@Kaspre Kaspre commented May 22, 2026 •

Copy link
Copy Markdown
Contributor

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.

PR #80751 made configured local provider origins trusted for SSRF policy purposes, but it did not change managed-proxy routing. PR #83255 addresses a separate browser/CDP loopback path. This PR covers the remaining Ollama memory embedding path.

Why this is not superseded by #80751

#80751 and this PR address adjacent but different boundaries:

  • fix(agents): scope custom provider baseUrl SSRF trust by origin #80751 is an SSRF policy trust change for configured custom / local model provider origins. Its proof exercised the buildGuardedModelFetch OpenAI-compatible model request path (POST /v1/chat/completions) and verified that exact configured private/loopback origins pass SSRF checks while other private/metadata origins stay blocked.
  • fix(agents): scope custom provider baseUrl SSRF trust by origin #80751 did not touch the bundled Ollama memory embedding provider (extensions/ollama/src/embedding-provider.ts) and did not add a managed-proxy direct transport path. After fix(agents): scope custom provider baseUrl SSRF trust by origin #80751, the Ollama memory embedding provider still called public fetchWithSsrFGuard for /api/embed.
  • On current main after fix(agents): scope custom provider baseUrl SSRF trust by origin #80751, strict guarded fetch still selects createHttp1EnvHttpProxyAgent whenever the managed proxy is active and proxy env is configured. Exact-origin SSRF trust can make the loopback target allowed, but it does not make that request reachable when the managed proxy cannot reach the OpenClaw host's loopback service.
  • This PR adds the missing transport decision for one narrow path: 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.

The exact-head proof demonstrates the distinction: with OPENCLAW_PROXY_ACTIVE=1 and a fake managed proxy configured, default loopback mode reached fake Ollama directly with proxyHits=0; proxy.loopbackMode=proxy sent the same request to the fake proxy with ollamaHits=0; and a redirect to another loopback origin was blocked before reaching the redirect target.

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.

Review gates completed at that 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:

  • 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 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.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation extensions: ollama size: M proof: supplied External PR includes structured after-fix real behavior proof. labels May 22, 2026
@clawsweeper

clawsweeper Bot commented May 22, 2026 •

Copy link
Copy Markdown
Contributor

Thanks for the context here. I swept through the related work, and this is now duplicate or superseded.

Keep open. The PR targets a real source-reproducible Ollama embeddings/proxy failure, but it intentionally adds a guarded direct path around the managed proxy and the supplied real-behavior proof is stale for the live head and packaging changes.

Canonical path: Close this PR as superseded by #80751.

So I’m closing this here and keeping the remaining discussion on #80751.

Review details

Best possible solution:

Close this PR as superseded by #80751.

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

Yes. Source inspection shows current main routes Ollama memory embeddings through strict guarded fetch, and strict guarded fetch uses EnvHttpProxyAgent whenever managed proxy mode is active; the linked user report supplies matching proxy 503 symptoms.

Is this the best way to solve the issue?

Unclear until maintainer policy review. The implementation is narrow and well-guarded, but it deliberately creates an Ollama-specific loopback IPC exception to managed proxy routing.

Security review:

Security review needs attention: Needs attention because the diff intentionally adds a guarded direct transport path around the managed forward proxy for loopback Ollama embeddings.

  • [medium] Managed proxy direct bypass requires policy approval — src/infra/net/fetch-guard.ts:546
    The new branch can replace EnvHttpProxyAgent with a pinned direct dispatcher for exact configured loopback Ollama embedding origins; the guards look narrow, but this is still a proxy/security-boundary decision for maintainers.
    Confidence: 0.86

What I checked:

  • linked superseding PR: fix(agents): scope custom provider baseUrl SSRF trust by origin #80751 (fix(agents): scope custom provider baseUrl SSRF trust by origin) is merged at 2026-05-15T10:00:30Z.
  • cluster evidence: the durable review links that PR in the work cluster or recommended risk path.
  • no human follow-up: live comments and timeline hydrated by apply contain no non-automation activity after the ClawSweeper review.

Likely related people:

  • Kaspre: Authored the merged exact-origin SSRF trust change in fix(agents): scope custom provider baseUrl SSRF trust by origin #80751, which this PR builds on for the remaining managed-proxy transport path. (role: adjacent feature author; confidence: high; commits: 44840007d42d; files: src/infra/net/fetch-guard.ts, src/infra/net/ssrf.ts, src/plugin-sdk/ssrf-runtime.ts)
  • steipete: Recent commits touched Ollama embedding timeout behavior and fetch-guard hardening, and the SSRF origin-trust merge includes Peter as a co-author in the commit message. (role: recent area contributor; confidence: high; commits: a6225060f1dc, 4f4d10863916, 44840007d42d; files: extensions/ollama/src/embedding-provider.ts, src/infra/net/fetch-guard.ts)
  • pashpashpash: Recent private plugin SDK alias work established the installed/bundled private-runtime pattern that this PR extends for Ollama. (role: adjacent owner; confidence: medium; commits: 3688c47f1fe4; files: src/plugins/sdk-alias.ts)

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

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. 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 22, 2026
@clawsweeper

clawsweeper Bot commented May 22, 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.

@openclaw-barnacle openclaw-barnacle Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 22, 2026
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 22, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 22, 2026
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 22, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 22, 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: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels May 22, 2026
@Kaspre Kaspre changed the title fix(ollama): bypass managed proxy for local embeddings fix(ollama): bypass managed proxy for loopback embeddings May 22, 2026
@Kaspre
Kaspre force-pushed the fix/ollama-local-embedding-proxy-bypass branch from b2afeda to 0aa6bc3 Compare May 22, 2026 19:45
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed 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. labels May 22, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 22, 2026
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 22, 2026
@clawsweeper clawsweeper Bot added status: 🛠️ actively grinding The PR author has acted after the latest ClawSweeper review and work remains. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. status: 🛠️ actively grinding The PR author has acted after the latest ClawSweeper review and work remains. labels May 23, 2026
@Kaspre
Kaspre force-pushed the fix/ollama-local-embedding-proxy-bypass branch from d98178c to 64264c4 Compare May 23, 2026 03:18
@clawsweeper

clawsweeper Bot commented May 23, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper applied the proposed close for this PR.

@clawsweeper clawsweeper Bot closed this May 23, 2026
@Kaspre
Kaspre marked this pull request as ready for review May 23, 2026 07:56
@Kaspre
Kaspre requested a review from a team as a code owner May 23, 2026 07:56

Kaspre commented May 23, 2026

Copy link
Copy Markdown
Contributor Author

Follow-up after the ClawSweeper review:

  • Draft bit is now cleared and the PR body has been updated with exact-head proof for 5093f4eddf37ea75435973ded15e4ec5ca7f97c7.
  • The public SDK concern is addressed: managedProxyBypass is not on the public openclaw/plugin-sdk/ssrf-runtime option surface, public fetchWithSsrFGuard strips forged markers, and the private helper is scoped to bundled Ollama only and kept out of staged public runtime aliases.
  • The remaining proxy-policy decision is now called out explicitly for maintainers: exact configured loopback Ollama embedding traffic can bypass the managed proxy under the default loopback mode, while proxy.loopbackMode: "proxy" and "block" still enforce operator choice.
  • Full-suite red paths are classified from a same-environment remote comparison: PR pnpm test red with 13 failed files, pinned-main pnpm test red with 14 failed files, and 0 PR-only failed files. The one main-only failed file was src/pairing/pairing-store.test.ts.
  • Current-head live transport proof also passed: default loopback reached fake Ollama directly with proxyHits=0, proxy.loopbackMode=proxy hit the fake proxy with ollamaHits=0, and cross-origin loopback redirect was blocked before reaching the redirect target.

Operational note: this token can update and mark the PR ready, and the draft state is now cleared, but GitHub reports viewerCanReopen=false for reopening this closed PR. gh pr reopen 85448 returns GraphQL: Could not open the pull request. The fork branch exists at 5093f4eddf37ea75435973ded15e4ec5ca7f97c7, but the closed PR record still shows the stale pre-close head d6b74aaa64acd9f17531506674cc25220c6a80d0 until someone with reopen permission reopens or advises a replacement PR.

@openclaw-barnacle openclaw-barnacle Bot added triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. and removed proof: supplied External PR includes structured after-fix real behavior proof. labels May 23, 2026

Kaspre commented May 23, 2026

Copy link
Copy Markdown
Contributor Author

Replacement PR opened as #85707 because this closed PR could not be reopened by this contributor identity.

#85707 uses the same final reviewed/proofed code head, 5093f4eddf37ea75435973ded15e4ec5ca7f97c7, and its body now spells out the #81249 scope split: #80751 covered exact-origin SSRF trust, #83255 covers browser/CDP loopback, and #85707 covers the remaining bundled Ollama memory embedding managed-proxy transport gap.

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 merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. 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. 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. triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant