Skip to content

fix(provider-transport): pass baseUrl hostname to SSRF guard so fake-IP proxies don't block model API calls - #76549

Closed
zqchris wants to merge 1 commit into
openclaw:mainfrom
zqchris:fix/provider-transport-fake-ip
Closed

zqchris wants to merge 1 commit into
openclaw:mainfrom
zqchris:fix/provider-transport-fake-ip

Conversation

@zqchris

@zqchris zqchris commented May 3, 2026

Copy link
Copy Markdown
Contributor

Summary

Companion to #74571 (public tools.web.fetch config) and #76530 (trusted web-tools endpoint policy). Fixes the third major fake-IP user-visible failure path: all model API calls (LiteLLM proxies, api.openai.com, generativelanguage.googleapis.com, api.x.ai, api.anthropic.com, etc).

(Re-submission of #76543 which the activity bot auto-closed for queue-quota reasons; I closed two older lower-priority PRs of mine — #72913 and #73400 — to make room.)

On fake-IP DNS proxy setups (sing-box / Clash / Surge), every foreign provider hostname resolves into the 198.18.0.0/15 RFC 2544 benchmark range (or fc00::/7 IPv6 ULA). Currently the model transport guarded fetch only opts in via requestConfig.allowPrivateNetwork, which exempts RFC1918 private networks but not the fake-IP-only special-use ranges. The schema on models.providers.<id>.request doesn't accept allowRfc2544BenchmarkRange / allowIpv6UniqueLocalRange either, so users have no config-level escape hatch.

Symptom every fake-IP user sees:

[security] blocked URL fetch (url-fetch) target=https://api.openai.com/v1/audio/transcriptions
  reason=Blocked: resolves to private/internal/special-use IP address
[security] blocked URL fetch (url-fetch) target=https://generativelanguage.googleapis.com/...
  reason=Blocked: resolves to private/internal/special-use IP address
[image-generation] candidate failed: litellm/gpt-image-2:
  Blocked: resolves to private/internal/special-use IP address

Change

Thread the resolved model.baseUrl hostname through ssrfPolicyFromHttpBaseUrlAllowedHostname() so the configured provider host short-circuits the SSRF private-IP check via allowedHostnames.

+import { ssrfPolicyFromHttpBaseUrlAllowedHostname } from "../infra/net/ssrf.js";
…
+  const baseUrlPolicy = ssrfPolicyFromHttpBaseUrlAllowedHostname(model.baseUrl);
…
-      ...(requestConfig.allowPrivateNetwork ? { policy: { allowPrivateNetwork: true } } : {}),
+      ...(baseUrlPolicy || requestConfig.allowPrivateNetwork
+        ? {
+            policy: {
+              ...(baseUrlPolicy ?? {}),
+              ...(requestConfig.allowPrivateNetwork ? { allowPrivateNetwork: true } : {}),
+            },
+          }
+        : {}),

Why this is safe

This is the same pattern already used in the codebase by:

  • ElevenLabs (extensions/elevenlabs/speech-provider.ts)
  • OpenAI TTS (extensions/openai/tts.ts)
  • BlueBubbles (extensions/bluebubbles/src/client.ts)
  • Feishu (extensions/feishu/src/streaming-card.ts)
  • Google Meet (extensions/google-meet/src/oauth.ts)
  • LM Studio (extensions/lmstudio/src/stream.ts)
  • Slack (extensions/slack/src/send.ts)
  • Azure Speech, Ollama, GitHub Copilot embeddings, Kilocode

Each of those plugins resolves its own configured base URL and allowlists just that hostname. This commit moves the same allowlist into the shared transport so every provider that goes through buildGuardedModelFetch (i.e. all LLM chat / image / embedding / audio) benefits without each plugin having to copy the boilerplate.

The hostname is operator-configured (via models.providers.<id>.baseUrl or the bundled-catalog default), so allowlisting just the configured provider host is no broader trust than what the plugins above already grant their own configured hostnames.

Test plan

  • Local repro: chat / image / Whisper calls failed with SsrFBlockedError on a fake-IP setup before the patch
  • After the patch + rebuild, chat / fallback (litellm/claude-sonnet-4-6), image (litellm/gpt-image-2), Whisper transcription, and gemini-3-pro-image-preview via internal LiteLLM all return real responses
  • Re-checked: requests to non-configured hostnames still fall through to the existing private-IP / cloud-metadata block (no regression — allowedHostnames only short-circuits the configured base URL host)
  • CI: agent-runner / pi-embedded transport tests (existing test coverage in provider-transport-fetch.test.ts should still pass; happy to add a fake-IP regression test if maintainers prefer)

Refs

🤖 Generated with Claude Code

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: XS labels May 3, 2026
@clawsweeper

clawsweeper Bot commented May 3, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: found issues before merge.

Summary
The PR changes model provider HTTP fetch policy to exempt RFC2544 and IPv6 ULA fake-IP DNS ranges, adds provider transport regression tests, and records the user-facing fix in the changelog.

Reproducibility: yes. from source inspection. Current main sends model provider requests through fetchWithSsrFGuard without RFC2544 or IPv6 ULA policy flags unless private networking is explicitly enabled, while the SSRF guard blocks those DNS answers by default.

Next step before merge
The remaining blocker is a model-provider SSRF trust-boundary decision; an automated repair should wait for maintainer agreement on host scoping/default policy.

Security
Needs attention: The diff narrows the earlier bypass to fake-IP ranges, but still broadens model-provider SSRF behavior for every URL/redirect routed through the shared model fetcher.

Review findings

  • [P2] Scope fake-IP exemptions to the provider host — src/agents/provider-transport-fetch.ts:316-320
Review details

Best possible solution:

Scope the fake-IP-only SSRF exemption to the configured model provider base host while preserving explicit allowPrivateNetwork for operator-trusted private endpoints.

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

Yes, from source inspection. Current main sends model provider requests through fetchWithSsrFGuard without RFC2544 or IPv6 ULA policy flags unless private networking is explicitly enabled, while the SSRF guard blocks those DNS answers by default.

Is this the best way to solve the issue?

No. The PR targets the right surface and uses the safer fake-IP-only flags, but it should scope that exemption to model.baseUrl or an equivalent provider-host policy rather than applying it to every URL and redirect handled by the model fetcher.

Full review comments:

  • [P2] Scope fake-IP exemptions to the provider host — src/agents/provider-transport-fetch.ts:316-320
    The new policy is attached to every guarded model fetch request, so redirects and any SDK-supplied URL inherit the RFC2544/IPv6 ULA exemptions, not just the configured model.baseUrl host. On fake-IP DNS, non-provider hostnames with 198.18/fc00 answers now pass the resolved-IP guard; please derive a host-scoped policy from the provider base URL or otherwise keep the exemption limited to that provider host.
    Confidence: 0.8

Overall correctness: patch is incorrect
Overall confidence: 0.84

Security concerns:

  • [medium] Fake-IP exemption is not provider-host scoped — src/agents/provider-transport-fetch.ts:316
    Because the same policy is reused for all model fetch targets, a cross-origin redirect or unexpected SDK URL can resolve to RFC2544 or IPv6 ULA and pass the DNS safety check even when it is not the configured provider host.
    Confidence: 0.8

What I checked:

  • Current model transport lacks fake-IP SSRF policy: Current main only forwards { allowPrivateNetwork: true } to fetchWithSsrFGuard when the resolved model request policy explicitly enables private networking; normal provider calls do not pass allowRfc2544BenchmarkRange or allowIpv6UniqueLocalRange. (src/agents/provider-transport-fetch.ts:311, c02bf2f399db)
  • SSRF fake-IP flags are narrow range exemptions: SsrFPolicy has separate RFC2544 and IPv6 ULA flags, and the resolver still blocks other private/internal/special-use hostnames and addresses unless policy permits them. (src/infra/net/ssrf.ts:40, c02bf2f399db)
  • Model request config has no fake-IP escape hatch: The model-provider request schema accepts allowPrivateNetwork but not the RFC2544 or IPv6 ULA SSRF policy knobs, matching the PR's reported config gap. (src/config/zod-schema.core.ts:300, c02bf2f399db)
  • Docs frame fake-IP ranges as trusted-proxy opt-ins: The web_fetch documentation says the fake-IP SSRF flags are narrow opt-ins for trusted fake-IP proxy stacks and should be left unset unless the proxy owns and enforces those synthetic ranges. Public docs: docs/tools/web-fetch.md. (docs/tools/web-fetch.md:151, c02bf2f399db)
  • PR head applies the fake-IP policy globally within model fetch: The provided PR diff adds a constant fake-IP SSRF policy and always passes it as policy for model transport, merged only with explicit allowPrivateNetwork; it does not include a provider-host allowlist or other host scoping. (src/agents/provider-transport-fetch.ts:316, 4fa5b6af2ca9)

Likely related people:

  • qas: Related merged PR feat(models): allow private network via models.providers.*.request #63671 added models.providers.<id>.request.allowPrivateNetwork and plumbed it into provider HTTP fetch, which is the policy seam this PR changes. (role: introduced model provider private-network request policy; confidence: medium; commits: cc2ce816ac49; files: src/agents/provider-transport-fetch.ts, src/agents/provider-request-config.ts, src/config/zod-schema.core.ts)
  • jeffrey701: Related merged PR fix(ssrf): allow opt-in IPv6 unique-local exemption for fake-ip proxies #74571 added the allowIpv6UniqueLocalRange SSRF policy field and tests for fake-IP proxy behavior, which this PR reuses for model transport. (role: introduced fake-IP IPv6 SSRF policy support; confidence: medium; commits: 3b744bff8f72; files: src/infra/net/ssrf.ts, src/shared/net/ip.ts, docs/tools/web-fetch.md)
  • Alex Knight: Local blame on the checked-out snapshot attributes the current provider transport and SSRF guard lines to the grafted snapshot commit, so this is weaker routing evidence than the related merged PR history. (role: recent adjacent maintainer from local blame snapshot; confidence: low; commits: 8a0e3b6422; files: src/agents/provider-transport-fetch.ts, src/infra/net/ssrf.ts)

Remaining risk / open question:

  • Maintainers still need to decide whether model transport should default-trust fake-IP synthetic ranges for all provider requests, and whether redirects or SDK-supplied non-base URLs should be included.

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

@zqchris
zqchris force-pushed the fix/provider-transport-fake-ip branch from 0ef7bba to 963e434 Compare May 3, 2026 08:02
@zqchris

zqchris commented May 3, 2026

Copy link
Copy Markdown
Contributor Author

CI surfaced a non-deterministic vitest stall in checks-node-agentic-control-plane-runtime:

[vitest] no output for 300000ms; terminating stalled Vitest process group
(test/vitest/vitest.gateway-server.config.ts).
[test] retrying test/vitest/vitest.gateway-server.config.ts after no-output timeout
[vitest] no output for 300000ms; terminating stalled Vitest process group …

Both attempts of vitest.gateway-server.config.ts stalled with no output for 5 minutes — this looks like a known runner-environment flake on this shard rather than something this PR triggers (the diff is a 4-line change in provider-transport-fetch.ts and doesn't touch any gateway-server code path). checks-node-core then fails as the aggregator over the stalled shard.

Local pnpm test src/agents/provider-transport-fetch.test.ts passes; pnpm exec oxlint src/agents/provider-transport-fetch.ts is clean.

I don't have rerun rights on this repo — could a maintainer kick checks-node-agentic-control-plane-runtime again? Happy to also rebase onto current main if that's preferred.

…rt SSRF guard

The model transport guarded fetch passes `{ allowPrivateNetwork: true }` to
`fetchWithSsrFGuard` only when the operator opts in via
`models.providers.<id>.request.allowPrivateNetwork`. That covers RFC1918
private networks, but not the RFC 2544 benchmark range (198.18.0.0/15) or
IPv6 ULA (fc00::/7) that fake-IP DNS proxies (sing-box / Clash / Surge)
hand back for foreign provider hostnames.

Result: every model API call (LiteLLM gateway, api.openai.com,
generativelanguage.googleapis.com, api.x.ai, api.anthropic.com, etc) on a
fake-IP setup fails with:

  [security] blocked URL fetch (url-fetch) target=https://api.openai.com/...
    reason=Blocked: resolves to private/internal/special-use IP address

…even though those hostnames are reachable just fine through the proxy.
The schema on `models.providers.<id>.request` doesn't currently accept
`allowRfc2544BenchmarkRange` / `allowIpv6UniqueLocalRange` either, so
users have no way to opt in via config.

Fix: thread a fake-IP-only narrow exemption
(`{ allowRfc2544BenchmarkRange: true, allowIpv6UniqueLocalRange: true }`)
into the model transport guard policy. Same pattern the public
`tools.web.fetch` policy uses (openclaw#74571) and the trusted/self-hosted
web-tools endpoint policy in `agents/tools/web-guarded-fetch.ts` (openclaw#76530).

The narrow exemption only un-blocks the two fake-IP-specific special-use
ranges — loopback, RFC1918 private networks, link-local (including
169.254.169.254 cloud metadata), and `metadata.google.internal` stay
blocked unless the operator separately opts in via
`allowPrivateNetwork`. This is a strict subset of the
`ssrfPolicyFromHttpBaseUrlAllowedHostname` allowlist path used by
adjacent plugins, addressing the codex review concern that an
`allowedHostnames` bypass would be broader than the reported fake-IP
failure.

Adds regression coverage in `provider-transport-fetch.test.ts` asserting
that:
  * the policy threaded into `fetchWithSsrFGuard` only contains the
    fake-IP flags (no `allowedHostnames`, no
    `dangerouslyAllowPrivateNetwork`, no `allowPrivateNetwork`)
  * `allowPrivateNetwork: true` from the resolved provider request
    config still merges into the policy when the operator opts in

Refs openclaw#74351 (the original fake-IP IPv6 ULA report) and openclaw#74571 (the
`tools.web.fetch` companion fix). Together with openclaw#76530 (the trusted-web-
tools-endpoint companion), this closes the remaining major fake-IP
user-visible failure path.
@steipete

steipete commented May 3, 2026

Copy link
Copy Markdown
Contributor

Thanks for pushing this. Landed the scoped version in #76887, including the provider-host fake-IP allowance and the explicit-proxy regression fix so target hostname allowlists do not reject configured public proxy hosts.

Canonical landed PR: #76887
Landed commit: edb7e00

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants