Skip to content

Commit 4fa5b6a

Browse files
Chris ZhangChris Zhang
authored andcommitted
fix(provider-transport): exempt fake-IP DNS ranges from model transport 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 (#74571) and the trusted/self-hosted web-tools endpoint policy in `agents/tools/web-guarded-fetch.ts` (#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 #74351 (the original fake-IP IPv6 ULA report) and #74571 (the `tools.web.fetch` companion fix). Together with #76530 (the trusted-web- tools-endpoint companion), this closes the remaining major fake-IP user-visible failure path.
1 parent b6cbd92 commit 4fa5b6a

3 files changed

Lines changed: 61 additions & 1 deletion

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Docs: https://docs.openclaw.ai
1919

2020
### Fixes
2121

22+
- Agents/providers: exempt fake-IP DNS proxy ranges (RFC 2544 198.18.0.0/15 and IPv6 ULA fc00::/7) from the model provider transport SSRF guard so model API calls work behind sing-box / Clash / Surge fake-IP proxy setups, while keeping loopback, RFC1918, link-local, and cloud-metadata addresses blocked. Thanks @zqchris.
2223
- Plugins/onboarding: trust optional official plugin installs selected from the official catalog so npm security scanning treats them like other source-linked official install paths. Thanks @vincentkoc.
2324
- CLI/plugins: keep `plugins enable` and `plugins disable` from creating unconfigured channel config sections, so channel plugins with required setup fields no longer fail validation during lifecycle probes. Thanks @vincentkoc.
2425
- Agents/sessions: keep delayed `sessions_send` A2A replies alive after soft wait-window timeouts, while preserving terminal run timeouts and avoiding stale target replies in requester sessions. Fixes #76443. Thanks @ryswork1993 and @vincentkoc.

‎src/agents/provider-transport-fetch.test.ts‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,49 @@ describe("buildGuardedModelFetch", () => {
7676
);
7777
});
7878

79+
it("exempts only fake-IP DNS ranges from the model transport SSRF guard", async () => {
80+
const { buildGuardedModelFetch } = await import("./provider-transport-fetch.js");
81+
const model = {
82+
id: "gpt-5.4",
83+
provider: "openai",
84+
api: "openai-responses",
85+
baseUrl: "https://api.openai.com/v1",
86+
} as unknown as Model<"openai-responses">;
87+
88+
const fetcher = buildGuardedModelFetch(model);
89+
await fetcher("https://api.openai.com/v1/responses", { method: "POST" });
90+
91+
const policy = fetchWithSsrFGuardMock.mock.calls[0]?.[0]?.policy;
92+
expect(policy).toEqual({
93+
allowRfc2544BenchmarkRange: true,
94+
allowIpv6UniqueLocalRange: true,
95+
});
96+
expect(policy?.allowedHostnames).toBeUndefined();
97+
expect(policy?.dangerouslyAllowPrivateNetwork).toBeUndefined();
98+
expect(policy?.allowPrivateNetwork).toBeUndefined();
99+
});
100+
101+
it("merges allowPrivateNetwork into the fake-IP exemption when explicitly opted in", async () => {
102+
resolveProviderRequestPolicyConfigMock.mockReturnValueOnce({ allowPrivateNetwork: true });
103+
const { buildGuardedModelFetch } = await import("./provider-transport-fetch.js");
104+
const model = {
105+
id: "qwen3:32b",
106+
provider: "ollama",
107+
api: "ollama",
108+
baseUrl: "http://10.0.0.5:11434",
109+
} as unknown as Model<"ollama">;
110+
111+
const fetcher = buildGuardedModelFetch(model);
112+
await fetcher("http://10.0.0.5:11434/api/chat", { method: "POST" });
113+
114+
const policy = fetchWithSsrFGuardMock.mock.calls[0]?.[0]?.policy;
115+
expect(policy).toEqual({
116+
allowRfc2544BenchmarkRange: true,
117+
allowIpv6UniqueLocalRange: true,
118+
allowPrivateNetwork: true,
119+
});
120+
});
121+
79122
it("threads explicit transport timeouts into the shared guarded fetch seam", async () => {
80123
const { buildGuardedModelFetch } = await import("./provider-transport-fetch.js");
81124
const model = {

‎src/agents/provider-transport-fetch.ts‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { Api, Model } from "@mariozechner/pi-ai";
22
import { fetchWithSsrFGuard } from "../infra/net/fetch-guard.js";
3+
import type { SsrFPolicy } from "../infra/net/ssrf.js";
34
import { resolveDebugProxySettings } from "../proxy-capture/env.js";
45
import {
56
buildProviderRequestDispatcherPolicy,
@@ -10,6 +11,18 @@ import {
1011

1112
const DEFAULT_MAX_SDK_RETRY_WAIT_SECONDS = 60;
1213

14+
// Allow fake-IP DNS proxy ranges (RFC 2544 benchmark 198.18.0.0/15 and IPv6
15+
// ULA fc00::/7) so model API calls work behind sing-box / Clash / Surge fake-IP
16+
// proxy setups. The model transport still rejects loopback, RFC1918, link-
17+
// local, and cloud-metadata addresses — only the fake-IP-only special-use
18+
// ranges are exempted, matching the public web_fetch policy extended in
19+
// #74571 and the trusted web-tool endpoint policy in
20+
// `agents/tools/web-guarded-fetch.ts`.
21+
const MODEL_TRANSPORT_FAKE_IP_SSRF_POLICY: SsrFPolicy = {
22+
allowRfc2544BenchmarkRange: true,
23+
allowIpv6UniqueLocalRange: true,
24+
};
25+
1326
function hasReadableSseData(block: string): boolean {
1427
const dataLines = block
1528
.split(/\r\n|\n|\r/)
@@ -303,7 +316,10 @@ export function buildGuardedModelFetch(model: Model<Api>, timeoutMs?: number): t
303316
// Provider transport intentionally keeps the secure default and never
304317
// replays unsafe request bodies across cross-origin redirects.
305318
allowCrossOriginUnsafeRedirectReplay: false,
306-
...(requestConfig.allowPrivateNetwork ? { policy: { allowPrivateNetwork: true } } : {}),
319+
policy: {
320+
...MODEL_TRANSPORT_FAKE_IP_SSRF_POLICY,
321+
...(requestConfig.allowPrivateNetwork ? { allowPrivateNetwork: true } : {}),
322+
},
307323
});
308324
let response = result.response;
309325
if (shouldBypassLongSdkRetry(response)) {

0 commit comments

Comments
 (0)