Repository navigation
feat: add per-agent web_fetch ssrf overrides - #67421
Takhoffman wants to merge 1 commit into
Conversation
🔒 Aisle Security AnalysisWe found 2 potential security issue(s) in this PR:
1. 🟠 SSRF policy bypass via unsafe shallow merge of global and agent SSRF policies
Description
Impact:
Vulnerable code: return {
...globalPolicy,
...agentPolicy,
};This is particularly risky because TypeScript objects frequently include keys with RecommendationMerge SSRF policies with security-preserving semantics:
Example (ignore export function mergeSsrFPolicies(globalPolicy?: SsrFPolicy, agentPolicy?: SsrFPolicy): SsrFPolicy | undefined {
if (!globalPolicy && !agentPolicy) return undefined;
const merged: SsrFPolicy = {
...globalPolicy,
...Object.fromEntries(Object.entries(agentPolicy ?? {}).filter(([, v]) => v !== undefined)),
};
// Optional: enforce ceiling semantics for allowlists
if (globalPolicy?.hostnameAllowlist && agentPolicy?.hostnameAllowlist) {
const global = new Set(globalPolicy.hostnameAllowlist);
merged.hostnameAllowlist = agentPolicy.hostnameAllowlist.filter((p) => global.has(p));
}
return merged;
}Also add tests covering 2. 🟠 SSRF policy bypass via attacker-controlled agent selection (per-agent web_fetch SSRF overrides)
DescriptionPer-agent Key points:
Vulnerable code (policy merge): return {
...globalFetch,
ssrfPolicy: mergeSsrFPolicies(globalFetch?.ssrfPolicy, agentFetch.ssrfPolicy),
};If any agent is configured with a relaxed SSRF policy for administrative/trusted use, a less-trusted user who can choose RecommendationEnsure untrusted callers cannot influence which agent’s tool configuration is used when executing Options:
Example: only allow agent SSRF overrides to tighten the global policy: // Pseudocode: do not let agent override widen access.
const effective = intersectSsrFPolicies(globalFetch?.ssrfPolicy, agentFetch?.ssrfPolicy);And/or validate that the selected agent is permitted for this client before loading Analyzed PR: #67421 at commit Last updated on: 2026-04-15T23:01:35Z |
Greptile SummaryThis PR adds per-agent
Confidence Score: 4/5Hold for fix: the array-replacement bug in One P1 finding in the core merge logic ( src/infra/net/ssrf.ts —
|
| export function mergeSsrFPolicies( | ||
| globalPolicy?: SsrFPolicy, | ||
| agentPolicy?: SsrFPolicy, | ||
| ): SsrFPolicy | undefined { | ||
| if (!globalPolicy && !agentPolicy) { | ||
| return undefined; | ||
| } | ||
| return { | ||
| ...globalPolicy, | ||
| ...agentPolicy, | ||
| }; | ||
| } |
There was a problem hiding this comment.
Global
allowedHostnames exceptions are silently dropped by agent override
mergeSsrFPolicies uses a plain spread, which replaces array fields entirely. When an agent defines its own allowedHostnames: ["agent-host.internal"], the global list (e.g., ["monitoring.internal"]) is completely discarded. Any agent call to a globally-excepted private host will then be blocked by SSRF even though the operator explicitly allowed it globally.
The PR description says "merge" and the test is named "allows narrow hostname exceptions from a named agent" — both imply additive semantics, but the implementation replaces. The same replacement applies to hostnameAllowlist, where an agent can silently drop a global access restriction.
Fix: union array fields rather than overwriting them.
export function mergeSsrFPolicies(
globalPolicy?: SsrFPolicy,
agentPolicy?: SsrFPolicy,
): SsrFPolicy | undefined {
if (!globalPolicy && !agentPolicy) {
return undefined;
}
return {
...globalPolicy,
...agentPolicy,
allowedHostnames: [
...(globalPolicy?.allowedHostnames ?? []),
...(agentPolicy?.allowedHostnames ?? []),
],
hostnameAllowlist: [
...(globalPolicy?.hostnameAllowlist ?? []),
...(agentPolicy?.hostnameAllowlist ?? []),
],
};
}Prompt To Fix With AI
This is a comment left during a code review.
Path: src/infra/net/ssrf.ts
Line: 73-84
Comment:
**Global `allowedHostnames` exceptions are silently dropped by agent override**
`mergeSsrFPolicies` uses a plain spread, which *replaces* array fields entirely. When an agent defines its own `allowedHostnames: ["agent-host.internal"]`, the global list (e.g., `["monitoring.internal"]`) is completely discarded. Any agent call to a globally-excepted private host will then be blocked by SSRF even though the operator explicitly allowed it globally.
The PR description says "merge" and the test is named "allows narrow hostname exceptions from a named agent" — both imply additive semantics, but the implementation replaces. The same replacement applies to `hostnameAllowlist`, where an agent can silently drop a global access restriction.
Fix: union array fields rather than overwriting them.
```ts
export function mergeSsrFPolicies(
globalPolicy?: SsrFPolicy,
agentPolicy?: SsrFPolicy,
): SsrFPolicy | undefined {
if (!globalPolicy && !agentPolicy) {
return undefined;
}
return {
...globalPolicy,
...agentPolicy,
allowedHostnames: [
...(globalPolicy?.allowedHostnames ?? []),
...(agentPolicy?.allowedHostnames ?? []),
],
hostnameAllowlist: [
...(globalPolicy?.hostnameAllowlist ?? []),
...(agentPolicy?.hostnameAllowlist ?? []),
],
};
}
```
How can I resolve this? If you propose a fix, please make it concise.| export function serializeSsrFPolicy(policy?: SsrFPolicy): string { | ||
| return JSON.stringify({ | ||
| allowPrivateNetwork: policy?.allowPrivateNetwork === true, | ||
| dangerouslyAllowPrivateNetwork: policy?.dangerouslyAllowPrivateNetwork === true, | ||
| allowRfc2544BenchmarkRange: policy?.allowRfc2544BenchmarkRange === true, | ||
| allowedHostnames: policy?.allowedHostnames ?? [], | ||
| hostnameAllowlist: policy?.hostnameAllowlist ?? [], | ||
| }); | ||
| } |
There was a problem hiding this comment.
Array order affects cache key but not SSRF enforcement
JSON.stringify preserves insertion order, so allowedHostnames: ["a", "b"] and allowedHostnames: ["b", "a"] produce distinct cache keys even though normalizeHostnameSet / normalizeHostnameAllowlist treat them identically. Two fetches with semantically identical policies could miss each other's cache entries. Sorting before serializing removes this inconsistency.
| export function serializeSsrFPolicy(policy?: SsrFPolicy): string { | |
| return JSON.stringify({ | |
| allowPrivateNetwork: policy?.allowPrivateNetwork === true, | |
| dangerouslyAllowPrivateNetwork: policy?.dangerouslyAllowPrivateNetwork === true, | |
| allowRfc2544BenchmarkRange: policy?.allowRfc2544BenchmarkRange === true, | |
| allowedHostnames: policy?.allowedHostnames ?? [], | |
| hostnameAllowlist: policy?.hostnameAllowlist ?? [], | |
| }); | |
| } | |
| export function serializeSsrFPolicy(policy?: SsrFPolicy): string { | |
| return JSON.stringify({ | |
| allowPrivateNetwork: policy?.allowPrivateNetwork === true, | |
| dangerouslyAllowPrivateNetwork: policy?.dangerouslyAllowPrivateNetwork === true, | |
| allowRfc2544BenchmarkRange: policy?.allowRfc2544BenchmarkRange === true, | |
| allowedHostnames: [...(policy?.allowedHostnames ?? [])].sort(), | |
| hostnameAllowlist: [...(policy?.hostnameAllowlist ?? [])].sort(), | |
| }); | |
| } |
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/infra/net/ssrf.ts
Line: 86-94
Comment:
**Array order affects cache key but not SSRF enforcement**
`JSON.stringify` preserves insertion order, so `allowedHostnames: ["a", "b"]` and `allowedHostnames: ["b", "a"]` produce distinct cache keys even though `normalizeHostnameSet` / `normalizeHostnameAllowlist` treat them identically. Two fetches with semantically identical policies could miss each other's cache entries. Sorting before serializing removes this inconsistency.
```suggestion
export function serializeSsrFPolicy(policy?: SsrFPolicy): string {
return JSON.stringify({
allowPrivateNetwork: policy?.allowPrivateNetwork === true,
dangerouslyAllowPrivateNetwork: policy?.dangerouslyAllowPrivateNetwork === true,
allowRfc2544BenchmarkRange: policy?.allowRfc2544BenchmarkRange === true,
allowedHostnames: [...(policy?.allowedHostnames ?? [])].sort(),
hostnameAllowlist: [...(policy?.hostnameAllowlist ?? [])].sort(),
});
}
```
How can I resolve this? If you propose a fix, please make it concise.|
Expanded explanation with examples, since I want the PR thread to read more like the implementation walkthrough. What this changesThis PR makes agents: {
list: [
{
id: "ops",
tools: {
web: {
fetch: {
ssrfPolicy: {
dangerouslyAllowPrivateNetwork: true,
allowedHostnames: ["matrix.home.arpa"],
hostnameAllowlist: ["*.corp.example"],
allowRfc2544BenchmarkRange: true,
},
},
},
},
},
],
}The global setting at The effective runtime rule is: effective = {
...global.tools.web.fetch.ssrfPolicy,
...agent.tools.web.fetch.ssrfPolicy,
}That means agent fields override global fields when present. Why this existsBefore this change, This PR keeps the default posture restrictive, but allows explicit audited exceptions for specific named agents. Concrete exampleIf config looks like this: tools: {
web: {
fetch: {
ssrfPolicy: {
allowedHostnames: ["safe.example"],
},
},
},
},
agents: {
list: [
{
id: "ops",
tools: {
web: {
fetch: {
ssrfPolicy: {
dangerouslyAllowPrivateNetwork: true,
},
},
},
},
},
],
}Then the behavior is:
Runtime detailsThis PR changes In practice:
Cache safetyThis PR also fixes the cache boundary. Previously, the Conceptually: cacheKey = `fetch:${url}:${extractMode}:${maxChars}:${serializeSsrFPolicy(effectivePolicy)}`That prevents a broader-permission agent from warming cache entries that a stricter agent could then reuse. Audit behavior
The tiering is:
The wording is intentional:
Validation includedFocused verification passed with: pnpm exec vitest src/config/schema.test.ts src/config/schema.help.quality.test.ts src/config/schema.base.generated.test.ts src/agents/tools/web-fetch.ssrf.test.ts src/security/audit-web-fetch-ssrf.test.tsThe full commit hook also passed, including the repo Important non-goalThis does not generalize per-agent overrides for all In this pass, the only supported per-agent override is: agents.list[].tools.web.fetch.ssrfPolicyNot timeout, max chars, provider selection, or other |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0e6d4c8498
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| return { | ||
| ...globalPolicy, | ||
| ...agentPolicy, |
There was a problem hiding this comment.
Normalize merged SSRF alias flags before evaluating access
mergeSsrFPolicies currently does a shallow spread, so legacy and new private-network flags can conflict across scopes instead of overriding each other. For example, with global allowPrivateNetwork: true and agent dangerouslyAllowPrivateNetwork: false, the merged policy still allows private-network fetches because the legacy true survives; this makes a per-agent tightening attempt ineffective and can leave SSRF protections broader than intended.
Useful? React with 👍 / 👎.
| if (isPrivateNetworkAllowedByPolicy(effectivePolicy)) { | ||
| findings.push({ | ||
| checkId: `agents.${agent.id}.tools.web_fetch.ssrf_policy.private_network_enabled`, | ||
| severity: "warn", | ||
| title: `Agent ${agent.id} widens web_fetch SSRF access`, |
There was a problem hiding this comment.
Gate agent SSRF warning on baseline-to-agent widening
This warning fires whenever the agent’s effective policy allows private-network access, even if the global baseline already allows it; that means an agent with an unrelated override (for example only hostname exceptions) can be reported as “widens web_fetch SSRF access” while an agent with no override is not. The result is misleading audit output and noisy per-agent warns that do not represent an actual widening introduced by that agent.
Useful? React with 👍 / 👎.
|
@clawsweeper yo |
|
🦞🦞 I asked ClawSweeper to answer this maintainer mention in the next review comment. Tiny claws, bounded scope: this is a read-only assist pass unless it produces one of the existing structured safe-action markers. Request: yo |
|
Codex review: needs real behavior proof before merge. Reviewed August 2, 2026, 3:15 PM ET / 19:15 UTC. ClawSweeper reviewWhat this changesThe branch adds Merge readiness⛔ Blocked until real behavior proof is added - 12 items remain This protected draft should remain open for maintainer handling, not automated cleanup. Its central per-agent SSRF capability is still a product and security-boundary decision, while the April branch is conflict-stale, retains an obsolete shallow policy merge, omits current IPv6 fake-IP compatibility, and has no after-fix runtime proof. Priority: P2 Review scores
Verification
How this fits together
flowchart LR
A[Operator config] --> B[Active agent routing]
B --> C[Effective web-fetch policy]
A --> C
C --> D[SSRF guard]
D --> E[Outbound HTTP request]
C --> F[Policy-aware cache]
E --> G[Tool result]
Decision needed
Why: The answer defines a durable outbound-network authorization contract; it cannot be resolved safely by mechanically rebasing a stale feature branch. Before merge
Findings
Agent review detailsSecurityNeeds attention: No standalone exploit was established, but the diff adds a named-agent route for widening outbound SSRF privileges without a maintainer-confirmed authorization contract. PR surfaceSource +205, Tests +320, Generated +137. Total +662 across 13 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Decide whether named agents are an approved authorization boundary for SSRF widening, then implement the capability on current Do we have a high-confidence way to reproduce the issue? Not applicable: this PR proposes a new configuration and authorization capability rather than correcting already-defined broken behavior. The current-main source review does establish the compatibility paths the proposed feature would need to preserve. Is this the best way to solve the issue? No. The stale branch is not the best implementation path because it duplicates older merge logic and omits current IPv6 compatibility; the better path starts from current main after maintainers choose the security boundary. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 920a265d8179. LabelsLabel changes:
Label justifications:
EvidenceSecurity concerns:
What I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (1 earlier review cycle)
|
|
+1 on the motivation for this PR — I'm an openclaw operator hitting exactly the use case the description names ("trusted internal hosts, localhost"). My setup: an openclaw gateway agent runs a periodic heartbeat that checks the health of an HTTP service I run on the same machine ( The schema-level exposure of Happy to test the merged code against my loopback-monitoring use case once it lands and report back if useful — figured the additional concrete-use-case data point might be helpful for the security review thread. Either way, thanks for working on this. |
|
ClawSweeper PR egg 🎁 Pass real behavior proof to wake the egg and unlock a hatchable treat. Where did the egg go?
|
|
Thanks for the PR. We're closing pull requests opened before April 2026 that have gone stale against current This draft has had no commits since April, CI is failing, and it still lacks the behavior proof needed for a security-boundary change to SSRF policy; the config and web_fetch code it touches have moved a lot since then. If per-agent SSRF exceptions are still needed, please open a fresh PR against current main with live proof. |
Summary
This PR makes
web_fetchSSRF policy configurable per named agent at:The global setting at
tools.web.fetch.ssrfPolicystill exists, but it now acts as the default baseline, not a hard ceiling.The effective runtime rule is:
That means agent fields override global fields when present.
Why
Before this change,
web_fetchSSRF behavior was effectively global-only. That made it awkward to keep the safe default restrictive while allowing a small number of trusted agents to reach internal hosts, localhost, or fake-IP proxy ranges.This keeps the default posture restrictive while allowing explicit audited exceptions for specific named agents.
Example
If config looks like this:
Then the behavior is:
opsis explicitly allowed to reach private-network targets withweb_fetchopenclaw security auditRuntime Details
This PR changes
web_fetchruntime resolution so the active agent’s SSRF policy is threaded into tool construction.In practice:
createOpenClawTools(...)resolves the current agent and passes that agent’s tool config intocreateWebFetchTool(...)createWebFetchTool(...)merges global and agentssrfPolicyrunWebFetch(...)evaluates requests against that merged effective policyCache Safety
This PR also fixes the cache boundary.
Previously, the
web_fetchcache key only reflected the RFC2544 flag. After this change, the cache key includes the full effective SSRF policy.Conceptually:
That prevents a broader-permission agent from warming cache entries that a stricter agent could then reuse.
Audit Behavior
openclaw security auditnow reports both global and per-agentweb_fetchSSRF posture.Severity is tiered:
warnfor broad widening such asdangerouslyAllowPrivateNetwork=trueinfofor narrower exceptions such asallowedHostnames,hostnameAllowlist, orallowRfc2544BenchmarkRange=trueThe wording is intentional:
tools.web.fetch.ssrfPolicyis described as the default baselineScope
In this pass, the only supported per-agent override is:
This does not yet generalize per-agent overrides for unrelated
web_fetchsettings like timeout, max chars, or provider selection.Testing
pnpm exec vitest src/config/schema.test.ts src/config/schema.help.quality.test.ts src/config/schema.base.generated.test.ts src/agents/tools/web-fetch.ssrf.test.ts src/security/audit-web-fetch-ssrf.test.tsgit commithook (pnpm checksuite)