Skip to content

Commit 3b96502

Browse files
committed
feat(cron): add webhook SSRF policy (#118237)
1 parent 181da6f commit 3b96502

30 files changed

Lines changed: 304 additions & 89 deletions
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"core": 2309,
2+
"core": 2321,
33
"channel": 3692,
4-
"plugin": 4057
4+
"plugin": 4056
55
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
f1b338718b9a058fc3b472a2004c15d146aa83303804c76f7ea831ed3f5593b8 config-baseline.json
2-
063a781ea045218fcf4f8ddc7df152b89eaf9a2ab8ed8049cafce75301425a3a config-baseline.core.json
1+
16942839f6254e337308a87e434c295edb1b0b499f796c4dd0b27a7c596c1751 config-baseline.json
2+
aa1b3a3733b7129728c66d138fa2e8e691b14ba7afe43d78fc134549fcac5b45 config-baseline.core.json
33
e9a81ee89ff032033012413e161316e4d07e8f6b206382a25fed2f8485151b5e config-baseline.channel.json
4-
c097c0bee74849e691bf295b070ce189d4e0e501bd770e448922d9f399c4901f config-baseline.plugin.json
4+
5d5fe4c95346cb1e7555395d40a6244967e6595b30f13912ae7754209944b734 config-baseline.plugin.json

‎docs/automation/cron-jobs.md‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,29 @@ Agent-turn jobs default to the creating conversation when the create request car
324324
| `webhook` | POST finished event payload to a URL |
325325
| `none` | No runner fallback delivery |
326326

327+
<Warning>
328+
Every outbound automation webhook uses the strict SSRF guard. Loopback,
329+
private/internal, link-local, and other special-use targets are refused by
330+
default for primary delivery, completion and failure destinations, and
331+
failure-alert webhooks.
332+
333+
Allow only the receiver you trust with an exact hostname or IP exemption:
334+
335+
```json5
336+
{
337+
cron: {
338+
webhookSsrfPolicy: {
339+
allowedHostnames: ["127.0.0.1"],
340+
},
341+
},
342+
}
343+
```
344+
345+
Use `dangerouslyAllowPrivateNetwork: true` under `webhookSsrfPolicy` only when
346+
every configured automation webhook may reach trusted private-network
347+
services. Leaving the policy unset keeps strict behavior.
348+
</Warning>
349+
327350
Use `--announce --channel telegram --to "-1001234567890"` for channel delivery. For Telegram forum topics, use `-1001234567890:topic:123`; OpenClaw also accepts the Telegram-owned `-1001234567890:123` shorthand. Direct RPC/config callers may pass `delivery.threadId` as a string or number. Slack/Discord/Mattermost targets use explicit prefixes (`channel:<id>`, `user:<id>`). Matrix room IDs are case-sensitive; use the exact room ID or `room:!room:server` form from Matrix.
328351

329352
On hosts with multiple configured channels, isolated announce jobs created with `automations add|create` or changed with `automations edit` must set `--channel <id>` unless a provider-prefixed `--to` or a preserved session route selects the channel. Use `--best-effort-deliver` only when unresolved fallback delivery is acceptable; it does not choose a channel, and a delivery failure does not fail the job.
@@ -474,6 +497,8 @@ The agent `automations` tool returns compact job summaries (`id`, `name`, `enabl
474497

475498
`openclaw automations create` is an alias for `openclaw automations add`. New jobs can use a positional schedule (`"0 9 * * 1"`, `"every 1h"`, `"20m"`, or an ISO timestamp) followed by a positional agent prompt. Use `--webhook <url>` on `automations add|create` or `automations edit` to POST the finished run payload to an HTTP endpoint; webhook delivery cannot combine with chat delivery flags (`--announce`, `--channel`, `--to`, `--thread-id`, `--account`). On `automations edit`, `--clear-channel`, `--clear-to`, `--clear-thread-id`, and `--clear-account` unset those routing fields individually (each rejected alongside its matching set flag) — distinct from `--no-deliver`, which only disables runner fallback delivery.
476499

500+
The webhook URL remains subject to the strict outbound policy above; configure `cron.webhookSsrfPolicy` for an intentional local or private receiver.
501+
477502
<Note>
478503
Model override note:
479504

@@ -747,6 +772,9 @@ Use the latest-generation, best-tier model available from your provider for untr
747772
enabled: false,
748773
},
749774
webhookToken: "replace-with-dedicated-webhook-token",
775+
webhookSsrfPolicy: {
776+
allowedHostnames: ["127.0.0.1"], // optional exact exception for a trusted receiver
777+
},
750778
sessionRetention: "24h",
751779
},
752780
}
@@ -755,6 +783,9 @@ Use the latest-generation, best-tier model available from your provider for untr
755783
`webhookToken` is sent as `Authorization: Bearer <token>` on automation webhook POSTs.
756784
Webhook URLs must not include embedded username/password credentials; use
757785
`webhookToken` when the receiver supports bearer authentication.
786+
`webhookSsrfPolicy` applies to every outbound automation webhook and is strict
787+
when omitted. Prefer narrow `allowedHostnames` entries over the broad
788+
`dangerouslyAllowPrivateNetwork` opt-in.
758789

759790
Automation jobs, run history, and quarantined malformed jobs live in the shared SQLite state database. Use the CLI or Gateway API to change jobs; `cron.store` is retired.
760791

‎docs/gateway/configuration-reference.md‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1457,6 +1457,9 @@ Current builds no longer include the TCP bridge. Nodes connect over the Gateway
14571457
enabled: true,
14581458
},
14591459
webhookToken: "replace-with-dedicated-token", // optional bearer token for outbound webhook auth
1460+
webhookSsrfPolicy: {
1461+
allowedHostnames: ["127.0.0.1"], // optional exact exception for a trusted receiver
1462+
},
14601463
sessionRetention: "24h", // duration string or false
14611464
},
14621465
}
@@ -1467,9 +1470,10 @@ Current builds no longer include the TCP bridge. Nodes connect over the Gateway
14671470
- `sessionRetention`: how long to keep completed isolated automation run sessions before pruning SQLite session rows. Also controls cleanup of archived deleted automation transcripts. Default: `24h`; set `false` to disable.
14681471
- Run history automatically keeps the newest 2000 terminal rows per job. Lost rows retain their 24-hour cleanup window.
14691472
- `webhookToken`: bearer token used for automation webhook POST delivery (`delivery.mode = "webhook"`), if omitted no auth header is sent.
1473+
- `webhookSsrfPolicy`: shared outbound SSRF policy for primary, completion, failure-destination, and failure-alert webhooks. Private/internal targets are blocked when omitted. Prefer exact `allowedHostnames`; use `dangerouslyAllowPrivateNetwork: true` only for trusted private-network receivers. The narrow fake-IP proxy flags are `allowRfc2544BenchmarkRange` and `allowIpv6UniqueLocalRange`.
14701474

14711475
The `cron` block is strict; `cron.enabled`, `cron.triggers`, `cron.webhookToken`,
1472-
`cron.sessionRetention`, and `cron.failureAlert` are the only accepted keys. The
1476+
`cron.webhookSsrfPolicy`, `cron.sessionRetention`, and `cron.failureAlert` are the only accepted keys. The
14731477
retired `cron.webhook` fallback URL is gone: runtime delivery uses per-job
14741478
`delivery.mode = "webhook"` plus `delivery.to`, or `delivery.completionDestination`
14751479
when preserving announce delivery. `openclaw doctor --fix` strips a leftover

‎docs/tools/browser.md‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,9 @@ Browser settings live in `~/.openclaw/openclaw.json`.
165165
evaluateEnabled: true, // default: true; false disables act:evaluate (arbitrary JS)
166166
ssrfPolicy: {
167167
// dangerouslyAllowPrivateNetwork: true, // opt in only for trusted private-network access
168-
// hostnameAllowlist: ["*.example.com", "example.com"],
169168
// allowedHostnames: ["localhost"],
169+
// allowRfc2544BenchmarkRange: true, // trusted fake-IP proxy range
170+
// allowIpv6UniqueLocalRange: true, // trusted fake-IP proxy IPv6 range
170171
},
171172
// cdpUrl: "http://127.0.0.1:18792", // legacy single-profile override
172173
tabCleanup: {
@@ -332,6 +333,8 @@ main model can read the screenshot directly.
332333
- OpenClaw-managed local CDP readiness probes and DevTools WebSocket connections bypass the managed network proxy for the exact launched loopback endpoint, so `openclaw browser start` still works when an operator proxy blocks loopback egress.
333334
- To proxy the managed browser itself, pass explicit Chrome proxy flags through `browser.extraArgs`, such as `--proxy-server=...` or `--proxy-pac-url=...`. Strict SSRF mode blocks explicit browser proxy routing unless private-network browser access is intentionally enabled.
334335
- `browser.ssrfPolicy.dangerouslyAllowPrivateNetwork` is off by default; enable only when private-network browser access is intentionally trusted.
336+
- `browser.ssrfPolicy.allowedHostnames` grants exact hosts while the rest of the private network remains blocked.
337+
- `browser.ssrfPolicy.allowRfc2544BenchmarkRange` and `browser.ssrfPolicy.allowIpv6UniqueLocalRange` narrowly allow trusted fake-IP proxy ranges.
335338
- `browser.ssrfPolicy.allowPrivateNetwork` remains supported as a legacy alias.
336339

337340
</Accordion>

‎docs/tools/web-fetch.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ progress line is channel UI state only and never contains fetched page content.
106106
"X-Routing-Target": "staging",
107107
},
108108
ssrfPolicy: {
109+
dangerouslyAllowPrivateNetwork: false, // broad private-network opt-in; keep false by default
110+
allowedHostnames: ["internal.example"], // narrow exact host exception
109111
allowRfc2544BenchmarkRange: true, // opt-in for trusted fake-IP proxies using 198.18.0.0/15
110112
allowIpv6UniqueLocalRange: true, // opt-in for trusted fake-IP proxies using fc00::/7
111113
},
@@ -256,6 +258,8 @@ outbound policy after DNS resolution.
256258
- Response body is capped at `maxResponseBytes` (default `750000`, clamped to
257259
32000-10000000) before parsing; oversized responses are truncated with a warning
258260
- Private/internal hostnames are blocked
261+
- `tools.web.fetch.ssrfPolicy.allowedHostnames` allows exact trusted hosts while leaving other private/internal targets blocked
262+
- `tools.web.fetch.ssrfPolicy.dangerouslyAllowPrivateNetwork` broadly permits private-network targets; enable it only when model-selected URLs are trusted in this deployment
259263
- `tools.web.fetch.ssrfPolicy.allowRfc2544BenchmarkRange` and
260264
`tools.web.fetch.ssrfPolicy.allowIpv6UniqueLocalRange` are narrow opt-ins
261265
for trusted fake-IP proxy stacks; leave them unset unless your proxy owns

‎extensions/browser/src/browser/config.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -851,11 +851,15 @@ describe("browser config", () => {
851851
const resolved = resolveBrowserConfig({
852852
ssrfPolicy: {
853853
allowPrivateNetwork: true,
854+
allowRfc2544BenchmarkRange: true,
855+
allowIpv6UniqueLocalRange: true,
854856
allowedHostnames: [" localhost ", " *.trusted.example ", ""],
855857
},
856858
} as unknown as BrowserConfig);
857859
expect(resolved.ssrfPolicy).toEqual({
858860
dangerouslyAllowPrivateNetwork: true,
861+
allowRfc2544BenchmarkRange: true,
862+
allowIpv6UniqueLocalRange: true,
859863
allowedHostnames: ["localhost", "*.trusted.example"],
860864
});
861865
});

‎extensions/browser/src/browser/config.ts‎

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77
import os from "node:os";
88
import path from "node:path";
9+
import { mergeSsrFPolicies } from "openclaw/plugin-sdk/ssrf-policy";
910
import {
1011
normalizeOptionalString,
1112
normalizeOptionalTrimmedStringList,
@@ -236,26 +237,20 @@ function resolveBrowserSsrFPolicy(cfg: BrowserConfig | undefined): SsrFPolicy |
236237
const rawPolicy = cfg?.ssrfPolicy as BrowserSsrFPolicyCompat | undefined;
237238
const allowPrivateNetwork = rawPolicy?.allowPrivateNetwork;
238239
const dangerouslyAllowPrivateNetwork = rawPolicy?.dangerouslyAllowPrivateNetwork;
239-
const allowedHostnames = normalizeStringList(rawPolicy?.allowedHostnames);
240240
const hasExplicitPrivateSetting =
241241
allowPrivateNetwork !== undefined || dangerouslyAllowPrivateNetwork !== undefined;
242-
const resolvedAllowPrivateNetwork =
243-
dangerouslyAllowPrivateNetwork === true || allowPrivateNetwork === true;
244-
245-
if (!resolvedAllowPrivateNetwork && !hasExplicitPrivateSetting && !allowedHostnames) {
246-
// Keep the default policy object present so CDP guards still enforce
247-
// fail-closed private-network checks on unconfigured installs.
248-
return {};
242+
const resolved = mergeSsrFPolicies({
243+
...rawPolicy,
244+
allowedHostnames: normalizeStringList(rawPolicy?.allowedHostnames),
245+
});
246+
if (resolved && hasExplicitPrivateSetting) {
247+
delete resolved.allowPrivateNetwork;
248+
resolved.dangerouslyAllowPrivateNetwork =
249+
allowPrivateNetwork === true || dangerouslyAllowPrivateNetwork === true;
249250
}
250-
251-
return {
252-
...(resolvedAllowPrivateNetwork ||
253-
dangerouslyAllowPrivateNetwork === false ||
254-
allowPrivateNetwork === false
255-
? { dangerouslyAllowPrivateNetwork: resolvedAllowPrivateNetwork }
256-
: {}),
257-
...(allowedHostnames ? { allowedHostnames } : {}),
258-
};
251+
// Keep an explicit strict object so every browser guard stays fail-closed
252+
// even when the operator leaves the shared policy unconfigured.
253+
return resolved ?? (hasExplicitPrivateSetting ? { dangerouslyAllowPrivateNetwork: false } : {});
259254
}
260255

261256
function ensureDefaultProfile(

‎src/agents/tools/web-fetch.ssrf.test.ts‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ function firstFetchUrl(fetchSpy: ReturnType<typeof setMockFetch>): string {
5454
function createWebFetchToolForTest(params?: {
5555
firecrawlApiKey?: string;
5656
useTrustedEnvProxy?: boolean;
57-
ssrfPolicy?: { allowRfc2544BenchmarkRange?: boolean; allowIpv6UniqueLocalRange?: boolean };
57+
ssrfPolicy?: ssrf.SsrFPolicy;
5858
cacheTtlMinutes?: number;
5959
}) {
6060
return createWebFetchTool({
@@ -134,6 +134,26 @@ describe("web_fetch SSRF protection", () => {
134134
expect(lookupMock).not.toHaveBeenCalled();
135135
});
136136

137+
it.each([
138+
{
139+
name: "private-network opt-in",
140+
ssrfPolicy: { dangerouslyAllowPrivateNetwork: true },
141+
},
142+
{
143+
name: "exact hostname opt-in",
144+
ssrfPolicy: { allowedHostnames: ["127.0.0.1"] },
145+
},
146+
])("allows loopback with an explicit $name", async ({ ssrfPolicy }) => {
147+
lookupMock.mockResolvedValue([{ address: "127.0.0.1", family: 4 }]);
148+
const fetchSpy = setMockFetch().mockResolvedValue(textResponse("local ok"));
149+
const tool = createWebFetchToolForTest({ ssrfPolicy });
150+
151+
const result = await tool?.execute?.("call", { url: "http://127.0.0.1/test" });
152+
153+
expectRawFetchSuccessDetails(result?.details);
154+
expect(fetchSpy).toHaveBeenCalledOnce();
155+
});
156+
137157
it("blocks when DNS resolves to private addresses", async () => {
138158
lookupMock.mockImplementation(async (hostname: string) => {
139159
if (hostname === "public.test") {

‎src/agents/tools/web-fetch.ts‎

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@ import { truncateUtf16Safe } from "@openclaw/normalization-core/utf16-slice";
1313
import { Type } from "typebox";
1414
import type { OpenClawConfig } from "../../config/types.openclaw.js";
1515
import { sha256Hex } from "../../infra/crypto-digest.js";
16-
import { SsrFBlockedError, type LookupFn, type SsrFPolicy } from "../../infra/net/ssrf.js";
16+
import {
17+
mergeSsrFPolicies,
18+
SsrFBlockedError,
19+
type LookupFn,
20+
type SsrFPolicy,
21+
} from "../../infra/net/ssrf.js";
1722
import { logDebug, logWarn } from "../../logger.js";
1823
import { assertSecretOwnerAvailable } from "../../secrets/runtime-degraded-state.js";
1924
import { runtimeWebSecretOwnerId } from "../../secrets/runtime-web-secret-owner.js";
@@ -525,10 +530,7 @@ type WebFetchRuntimeParams = {
525530
readabilityEnabled: boolean;
526531
config?: OpenClawConfig;
527532
useTrustedEnvProxy: boolean;
528-
ssrfPolicy?: {
529-
allowRfc2544BenchmarkRange?: boolean;
530-
allowIpv6UniqueLocalRange?: boolean;
531-
};
533+
ssrfPolicy?: SsrFPolicy;
532534
providerCacheKey?: string;
533535
lookupFn?: LookupFn;
534536
signal?: AbortSignal;
@@ -686,16 +688,11 @@ async function maybeFetchProviderWebFetchPayload(
686688
}
687689

688690
async function runWebFetch(params: WebFetchRuntimeParams): Promise<Record<string, unknown>> {
689-
const allowRfc2544BenchmarkRange = params.ssrfPolicy?.allowRfc2544BenchmarkRange === true;
690-
const allowIpv6UniqueLocalRange = params.ssrfPolicy?.allowIpv6UniqueLocalRange === true;
691+
const ssrfPolicy = mergeSsrFPolicies(params.ssrfPolicy);
692+
const dangerouslyAllowPrivateNetwork = ssrfPolicy?.dangerouslyAllowPrivateNetwork === true;
693+
const allowRfc2544BenchmarkRange = ssrfPolicy?.allowRfc2544BenchmarkRange === true;
694+
const allowIpv6UniqueLocalRange = ssrfPolicy?.allowIpv6UniqueLocalRange === true;
691695
const useTrustedEnvProxy = params.useTrustedEnvProxy;
692-
const ssrfPolicy: SsrFPolicy | undefined =
693-
allowRfc2544BenchmarkRange || allowIpv6UniqueLocalRange
694-
? {
695-
...(allowRfc2544BenchmarkRange ? { allowRfc2544BenchmarkRange } : {}),
696-
...(allowIpv6UniqueLocalRange ? { allowIpv6UniqueLocalRange } : {}),
697-
}
698-
: undefined;
699696
let parsedUrl: URL;
700697
try {
701698
parsedUrl = new URL(params.url);
@@ -711,8 +708,12 @@ async function runWebFetch(params: WebFetchRuntimeParams): Promise<Record<string
711708
const cacheDiscriminators = [
712709
`user-agent:${sha256Hex(params.userAgent)}`,
713710
params.providerCacheKey ? `provider:${params.providerCacheKey}` : "",
711+
dangerouslyAllowPrivateNetwork ? "allow-private-network" : "",
714712
allowRfc2544BenchmarkRange ? "allow-rfc2544" : "",
715713
allowIpv6UniqueLocalRange ? "allow-ipv6-ula" : "",
714+
ssrfPolicy?.allowedHostnames?.length
715+
? `allowed-hostnames:${sha256Hex(ssrfPolicy.allowedHostnames.join("\n"))}`
716+
: "",
716717
useTrustedEnvProxy ? "trusted-env-proxy" : "",
717718
headersCacheKey ? `headers:${headersCacheKey}` : "",
718719
].filter(Boolean);

0 commit comments

Comments
 (0)