Skip to content

feat: add per-agent web_fetch ssrf overrides - #67421

Closed
Takhoffman wants to merge 1 commit into
mainfrom
codex/agent-web-fetch-ssrf-overrides
Closed

Takhoffman wants to merge 1 commit into
mainfrom
codex/agent-web-fetch-ssrf-overrides

Conversation

@Takhoffman

@Takhoffman Takhoffman commented Apr 15, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This PR makes web_fetch SSRF policy configurable per named agent at:

agents: {
  list: [
    {
      id: "ops",
      tools: {
        web: {
          fetch: {
            ssrfPolicy: {
              dangerouslyAllowPrivateNetwork: true,
              allowedHostnames: ["matrix.home.arpa"],
              hostnameAllowlist: ["*.corp.example"],
              allowRfc2544BenchmarkRange: true,
            },
          },
        },
      },
    },
  ],
}

The global setting at tools.web.fetch.ssrfPolicy still exists, but it now acts as the default baseline, not a hard ceiling.

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

Before this change, web_fetch SSRF 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:

tools: {
  web: {
    fetch: {
      ssrfPolicy: {
        allowedHostnames: ["safe.example"],
      },
    },
  },
},
agents: {
  list: [
    {
      id: "ops",
      tools: {
        web: {
          fetch: {
            ssrfPolicy: {
              dangerouslyAllowPrivateNetwork: true,
            },
          },
        },
      },
    },
  ],
}

Then the behavior is:

  • most agents still use the restrictive global default
  • ops is explicitly allowed to reach private-network targets with web_fetch
  • that widening is surfaced in openclaw security audit

Runtime Details

This PR changes web_fetch runtime 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 into createWebFetchTool(...)
  • createWebFetchTool(...) merges global and agent ssrfPolicy
  • runWebFetch(...) evaluates requests against that merged effective policy

Cache Safety

This PR also fixes the cache boundary.

Previously, the web_fetch cache key only reflected the RFC2544 flag. After this change, the cache key includes the full effective SSRF policy.

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

openclaw security audit now reports both global and per-agent web_fetch SSRF posture.

Severity is tiered:

  • warn for broad widening such as dangerouslyAllowPrivateNetwork=true
  • info for narrower exceptions such as allowedHostnames, hostnameAllowlist, or allowRfc2544BenchmarkRange=true

The wording is intentional:

  • global tools.web.fetch.ssrfPolicy is described as the default baseline
  • named-agent widening is described as a security-sensitive exception
  • agent findings name the agent id directly

Scope

In this pass, the only supported per-agent override is:

agents.list[].tools.web.fetch.ssrfPolicy

This does not yet generalize per-agent overrides for unrelated web_fetch settings 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.ts
  • git commit hook (pnpm check suite)

@Takhoffman
Takhoffman requested a review from a team as a code owner April 15, 2026 22:58
@aisle-research-bot

aisle-research-bot Bot commented Apr 15, 2026 •

Copy link
Copy Markdown

🔒 Aisle Security Analysis

We found 2 potential security issue(s) in this PR:

# Severity Title
1 🟠 High SSRF policy bypass via unsafe shallow merge of global and agent SSRF policies
2 🟠 High SSRF policy bypass via attacker-controlled agent selection (per-agent web_fetch SSRF overrides)
1. 🟠 SSRF policy bypass via unsafe shallow merge of global and agent SSRF policies
Property Value
Severity High
CWE CWE-284
Location src/infra/net/ssrf.ts:73-84

Description

mergeSsrFPolicies() merges SSRF policies using object spread. This treats explicit undefined values (common when constructing objects programmatically) as an override, which can accidentally erase restrictive global SSRF settings.

Impact:

  • If a restrictive global policy sets hostnameAllowlist to a non-empty list, an agent policy object containing { hostnameAllowlist: undefined } will overwrite it.
  • In SSRF enforcement, an empty/undefined hostnameAllowlist means "allow all hostnames" (matchesHostnameAllowlist() returns true when the allowlist is empty).
  • Result: the effective runtime policy can become more permissive than intended, enabling SSRF to internal/private resources depending on other policy flags and DNS resolution outcomes.

Vulnerable code:

return {
  ...globalPolicy,
  ...agentPolicy,
};

This is particularly risky because TypeScript objects frequently include keys with undefined values when built from optional inputs (even if JSON config cannot express undefined).

Recommendation

Merge SSRF policies with security-preserving semantics:

  1. Ignore undefined overrides (treat them as “not specified”).
  2. Decide an explicit security model for lists:
    • If the global policy is a hard ceiling, use intersection for hostnameAllowlist/allowedHostnames.
    • If the global policy is a baseline, use union but never allow an agent to clear global allowlists unless an explicit clear* flag is provided.

Example (ignore undefined, and keep global hostname allowlist as a ceiling via intersection):

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 {hostnameAllowlist: undefined} and {hostnameAllowlist: []} behaviors to ensure they cannot unexpectedly widen SSRF access.

2. 🟠 SSRF policy bypass via attacker-controlled agent selection (per-agent web_fetch SSRF overrides)
Property Value
Severity High
CWE CWE-918
Location src/agents/tools/web-fetch.ts:98-114

Description

Per-agent web_fetch SSRF policy overrides are merged into the effective fetch policy based on the active agent, but the active agent can be derived from a client-controlled sessionKey (e.g., agent:<id>:...). This can allow an untrusted client to select an agent configured with a more permissive SSRF policy (e.g., dangerouslyAllowPrivateNetwork, hostname allowlists), enabling access to internal/private network resources.

Key points:

  • Input / control: sessionKey is supplied by the client; it may include an agent: prefix and is parsed to derive agentId.
  • Policy selection: createOpenClawTools resolves sessionAgentId from the session key and loads that agent's tool config.
  • Policy merge: createWebFetchTool merges global SSRF policy with the agent's override via mergeSsrFPolicies, potentially relaxing restrictions.

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 sessionKey may be able to use that agent's policy to bypass SSRF protections.

Recommendation

Ensure untrusted callers cannot influence which agent’s tool configuration is used when executing web_fetch.

Options:

  1. Enforce authorization / allowlist agent IDs per requester before accepting an agent:-prefixed sessionKey.
  2. Disallow per-agent SSRF relaxations (e.g., dangerouslyAllowPrivateNetwork, private-network allow, hostname exceptions) unless the request is from an admin/trusted scope.
  3. Make SSRF policy only more restrictive when merging (intersection), not more permissive.

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


Analyzed PR: #67421 at commit 0e6d4c8

Last updated on: 2026-04-15T23:01:35Z

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: L maintainer Maintainer-authored PR labels Apr 15, 2026
@greptile-apps

greptile-apps Bot commented Apr 15, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds per-agent web_fetch SSRF policy overrides at agents.list[].tools.web.fetch.ssrfPolicy, wires them into tool construction via resolveEffectiveFetchConfig, isolates cache entries by effective policy, and adds schema, help, and audit coverage.

  • mergeSsrFPolicies silently drops global array exceptions: the plain object spread in src/infra/net/ssrf.ts replaces allowedHostnames and hostnameAllowlist arrays entirely rather than unioning them. An agent that defines its own allowedHostnames: [\"agent-host\"] will lose the operator's globally-excepted private hosts (e.g., \"monitoring.internal\"), causing unexpected SSRF blocks. The fix is to explicitly union the arrays before merging scalar flags.

Confidence Score: 4/5

Hold for fix: the array-replacement bug in mergeSsrFPolicies causes global allowedHostnames exceptions to be silently dropped for agents with custom policies, which is a real SSRF enforcement defect on the changed path.

One P1 finding in the core merge logic (mergeSsrFPolicies) — the spread operator replaces array fields instead of unioning them, so global hostname exceptions are silently lost whenever an agent defines its own. All other changes (schema, help, audit, cache key, config types) are clean and well-structured. Score is 4 instead of 5 because this P1 must be resolved before the SSRF override feature behaves as documented.

src/infra/net/ssrf.ts — mergeSsrFPolicies and serializeSsrFPolicy

Security Review

  • allowedHostnames replacement in policy merge (src/infra/net/ssrf.ts, mergeSsrFPolicies): When a per-agent policy includes allowedHostnames, the spread operator replaces the global list entirely. A globally-excepted private-network hostname is silently removed from the effective policy for that agent, making SSRF checks stricter than the operator intended. The reverse also applies: a global hostnameAllowlist restriction can be bypassed when an agent sets its own list.
Prompt To Fix All 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.

---

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.

Reviews (1): Last reviewed commit: "feat: add per-agent web_fetch ssrf overr..." | Re-trigger Greptile

Comment thread src/infra/net/ssrf.ts
Comment on lines +73 to +84
export function mergeSsrFPolicies(
globalPolicy?: SsrFPolicy,
agentPolicy?: SsrFPolicy,
): SsrFPolicy | undefined {
if (!globalPolicy && !agentPolicy) {
return undefined;
}
return {
...globalPolicy,
...agentPolicy,
};
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 security 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.

Comment thread src/infra/net/ssrf.ts
Comment on lines +86 to +94
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 ?? [],
});
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Suggested change
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.

Copy link
Copy Markdown
Contributor Author

Expanded explanation with examples, since I want the PR thread to read more like the implementation walkthrough.

What this changes

This PR makes web_fetch SSRF policy configurable per named agent at:

agents: {
  list: [
    {
      id: "ops",
      tools: {
        web: {
          fetch: {
            ssrfPolicy: {
              dangerouslyAllowPrivateNetwork: true,
              allowedHostnames: ["matrix.home.arpa"],
              hostnameAllowlist: ["*.corp.example"],
              allowRfc2544BenchmarkRange: true,
            },
          },
        },
      },
    },
  ],
}

The global setting at tools.web.fetch.ssrfPolicy still exists, but it now acts as the default baseline, not a hard ceiling.

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 exists

Before this change, web_fetch SSRF 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 PR keeps the default posture restrictive, but allows explicit audited exceptions for specific named agents.

Concrete example

If 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:

  • most agents still use the restrictive global default
  • ops is explicitly allowed to reach private-network targets with web_fetch
  • that widening is surfaced in openclaw security audit

Runtime details

This PR changes web_fetch runtime 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 into createWebFetchTool(...)
  • createWebFetchTool(...) merges global and agent ssrfPolicy
  • runWebFetch(...) evaluates requests against that merged effective policy

Cache safety

This PR also fixes the cache boundary.

Previously, the web_fetch cache key only reflected the RFC2544 flag. After this change, the cache key includes the full effective SSRF policy.

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

openclaw security audit now reports both global and per-agent web_fetch SSRF posture.

The tiering is:

  • warn for broad widening such as dangerouslyAllowPrivateNetwork=true
  • info for narrower exceptions such as allowedHostnames, hostnameAllowlist, or allowRfc2544BenchmarkRange=true

The wording is intentional:

  • global tools.web.fetch.ssrfPolicy is described as the default baseline
  • named-agent widening is described as a security-sensitive exception
  • agent findings name the agent id directly

Validation included

Focused 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.ts

The full commit hook also passed, including the repo pnpm check stack.

Important non-goal

This does not generalize per-agent overrides for all web.fetch settings yet.

In this pass, the only supported per-agent override is:

agents.list[].tools.web.fetch.ssrfPolicy

Not timeout, max chars, provider selection, or other web_fetch settings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread src/infra/net/ssrf.ts
Comment on lines +80 to +82
return {
...globalPolicy,
...agentPolicy,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

Comment thread src/security/audit.ts
Comment on lines +1154 to +1158
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`,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

@Takhoffman

Copy link
Copy Markdown
Contributor Author

@clawsweeper yo

@clawsweeper

clawsweeper Bot commented May 2, 2026

Copy link
Copy Markdown
Contributor

🦞🦞
ClawSweeper is taking a look at your question.

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

@clawsweeper

clawsweeper Bot commented May 2, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed August 2, 2026, 3:15 PM ET / 19:15 UTC.

ClawSweeper review

What this changes

The branch adds agents.list[].tools.web.fetch.ssrfPolicy so selected agents can extend the global web_fetch SSRF policy with private-network and hostname exceptions.

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
Reviewed head: 0e6d4c84987b5ae7e746d052484ce9c03cbf6053
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The draft has a credible use case, but its stale implementation has two P1 compatibility blockers and lacks the required real runtime proof.
Proof confidence 🧂 unranked krab (1/6) Needs real behavior proof before merge: The PR body reports focused tests and a commit hook, but no after-fix runtime evidence shows a configured agent fetching an allowed private target while another agent remains blocked. Provide redacted terminal output or logs; redact IP addresses, API keys, phone numbers, and non-public endpoints. Updating the PR body should trigger a fresh review, or a maintainer can comment @clawsweeper re-review. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Patch quality 🦪 silver shellfish (2/6) Security review found an item that needs attention.

Verification

Check Result Evidence
Real behavior Needs proof Needs real behavior proof before merge: The PR body reports focused tests and a commit hook, but no after-fix runtime evidence shows a configured agent fetching an allowed private target while another agent remains blocked. Provide redacted terminal output or logs; redact IP addresses, API keys, phone numbers, and non-public endpoints. Updating the PR body should trigger a fresh review, or a maintainer can comment @clawsweeper re-review. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed 6 items Current canonical SSRF policy model: Current main owns policy comparison and merging in the shared SSRF module. Its merge accumulates enabled flags and unions hostname collections, rather than replacing global arrays with agent arrays.
Current IPv6 fake-IP compatibility: Current main exposes allowIpv6UniqueLocalRange in the web-fetch schema and has a regression test proving the setting permits fake-IP IPv6 ULA answers only when configured.
Stale branch replaces the shared merge semantics: The PR's mergeSsrFPolicies is a two-policy object spread, so an agent hostname list replaces a configured global list instead of retaining the canonical additive policy behavior.
Findings 2 actionable findings [P1] Use the canonical additive SSRF policy merge
[P1] Retain IPv6 fake-IP SSRF compatibility
Security Needs attention Define the trust boundary for agent-specific widening: The branch merges an active agent's policy into web_fetch, including private-network access. Before merge, maintainers need an explicit supported trust model for selecting that agent and proof that non-privileged agent paths cannot inherit the wider policy.

How this fits together

web_fetch builds a request policy for the active agent, checks the URL and its resolved addresses through the SSRF guard, then fetches and caches the response. The proposed setting would make that outbound-network policy differ by agent while preserving a global default.

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]
Loading

Decision needed

Question Recommendation
Should a named agent selected through OpenClaw's existing runtime routing be permitted to widen web_fetch SSRF access beyond the global operator default? Sponsor an explicit authorized-agent design: Adopt the capability only with a current-main implementation that states the trusted agent-selection boundary and proves allowed and denied agents remain isolated.

Why: The answer defines a durable outbound-network authorization contract; it cannot be resolved safely by mechanically rebasing a stale feature branch.

Before merge

  • Add real behavior proof - Needs real behavior proof before merge: The PR body reports focused tests and a commit hook, but no after-fix runtime evidence shows a configured agent fetching an allowed private target while another agent remains blocked. Provide redacted terminal output or logs; redact IP addresses, API keys, phone numbers, and non-public endpoints. Updating the PR body should trigger a fresh review, or a maintainer can comment @clawsweeper re-review. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Use the canonical additive SSRF policy merge (P1) - This helper replaces global hostname arrays with agent arrays. Current main's shared merge unions hostname sets and preserves enabled flags, so rebasing this version would create a parallel policy model and can drop a configured global exception. Reuse the current owner and add merged-policy regression coverage.
  • Retain IPv6 fake-IP SSRF compatibility (P1) - The newly introduced schema shape omits allowIpv6UniqueLocalRange, which current main supports for fake-IP proxy deployments. A rebase that replaces the current schema with this stale field set would reject an existing supported configuration; include that field and cover the agent-effective policy path.
  • Resolve security concern: Define the trust boundary for agent-specific widening - The branch merges an active agent's policy into web_fetch, including private-network access. Before merge, maintainers need an explicit supported trust model for selecting that agent and proof that non-privileged agent paths cannot inherit the wider policy.
  • Resolve merge risk (P1) - Merging the old policy helper would replace current canonical additive merge semantics, allowing an agent-level hostname list to discard global hostname entries and creating inconsistent effective policies.
  • Resolve merge risk (P1) - The branch's schema omits the current IPv6 ULA fake-IP opt-in, so rebasing without an explicit compatibility pass could make existing tools.web.fetch.ssrfPolicy.allowIpv6UniqueLocalRange configurations invalid.
  • Resolve merge risk (P1) - The feature deliberately grants selected agents a wider outbound-network boundary; maintainers must define which routing and requester contexts are authorized to select such an agent.
  • Resolve merge risk (P1) - The PR body provides test claims but no redacted after-fix runtime output proving a privileged agent succeeds while a restrictive agent remains blocked.
  • Improve patch quality - Rebase onto current main and use the shared SSRF merge and current policy/cache contracts.
  • Improve patch quality - Add regression coverage for global-plus-agent policy composition, including IPv6 ULA fake-IP compatibility.
  • Improve patch quality - Post redacted runtime proof showing one authorized agent succeeds and a restrictive agent remains blocked.

Findings

  • [P1] Use the canonical additive SSRF policy merge — src/infra/net/ssrf.ts:73-84
  • [P1] Retain IPv6 fake-IP SSRF compatibility — src/config/zod-schema.agent-runtime.ts:336-347
  • [high] Define the trust boundary for agent-specific widening — src/agents/tools/web-fetch.ts:112
Agent review details

Security

Needs 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 surface

Source +205, Tests +320, Generated +137. Total +662 across 13 files.

View PR surface stats
Area Files Added Removed Net
Source 8 226 21 +205
Tests 4 323 3 +320
Docs 0 0 0 0
Config 0 0 0 0
Generated 1 141 4 +137
Other 0 0 0 0
Total 13 690 28 +662

Review metrics

Metric Value Why it matters
Privileged configuration surface 1 new per-agent policy group with 5 proposed fields The new agent-scoped configuration changes outbound-network privileges and needs explicit fresh-install and upgrade review.

Stored data model

Persistent data-model change detected: serialized state: src/infra/net/ssrf.ts, unknown-data-model-change: src/config/schema.base.generated.ts, unknown-data-model-change: src/config/schema.help.ts, unknown-data-model-change: src/config/schema.test.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Rebuild on current policy ownership (recommended)
    Rebase onto current main, use the shared additive merge, retain IPv6 ULA and cache behavior, and add focused compatibility coverage before merging.
  2. Pause for authorization direction
    Keep the draft paused until maintainers decide whether per-agent routing may safely grant wider private-network access.

Technical review

Best possible solution:

Decide whether named agents are an approved authorization boundary for SSRF widening, then implement the capability on current main through the canonical shared policy merge, preserve existing fake-IP and cache contracts, and document the operator-facing trust model.

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:

  • [P1] Use the canonical additive SSRF policy merge — src/infra/net/ssrf.ts:73-84
    This helper replaces global hostname arrays with agent arrays. Current main's shared merge unions hostname sets and preserves enabled flags, so rebasing this version would create a parallel policy model and can drop a configured global exception. Reuse the current owner and add merged-policy regression coverage.
    Confidence: 0.97
  • [P1] Retain IPv6 fake-IP SSRF compatibility — src/config/zod-schema.agent-runtime.ts:336-347
    The newly introduced schema shape omits allowIpv6UniqueLocalRange, which current main supports for fake-IP proxy deployments. A rebase that replaces the current schema with this stale field set would reject an existing supported configuration; include that field and cover the agent-effective policy path.
    Confidence: 0.98

Overall correctness: patch is incorrect
Overall confidence: 0.97

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 920a265d8179.

Labels

Label changes:

  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦪 silver shellfish.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🧂 unranked krab, so this older rating label is no longer current.

Label justifications:

  • P2: This is a bounded operator feature with concrete demand, but it is not a demonstrated urgent regression.
  • merge-risk: 🚨 compatibility: The stale schema and policy merge conflict with current supported web-fetch SSRF behavior, including IPv6 fake-IP compatibility.
  • merge-risk: 🚨 security-boundary: The feature intentionally allows particular agents to access destinations blocked by the default SSRF guard.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦪 silver shellfish.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The PR body reports focused tests and a commit hook, but no after-fix runtime evidence shows a configured agent fetching an allowed private target while another agent remains blocked. Provide redacted terminal output or logs; redact IP addresses, API keys, phone numbers, and non-public endpoints. Updating the PR body should trigger a fresh review, or a maintainer can comment @clawsweeper re-review. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Evidence

Security concerns:

  • [high] Define the trust boundary for agent-specific widening — src/agents/tools/web-fetch.ts:112
    The branch merges an active agent's policy into web_fetch, including private-network access. Before merge, maintainers need an explicit supported trust model for selecting that agent and proof that non-privileged agent paths cannot inherit the wider policy.
    Confidence: 0.87

What I checked:

  • Current canonical SSRF policy model: Current main owns policy comparison and merging in the shared SSRF module. Its merge accumulates enabled flags and unions hostname collections, rather than replacing global arrays with agent arrays. (src/infra/net/ssrf.ts:77, 920a265d8179)
  • Current IPv6 fake-IP compatibility: Current main exposes allowIpv6UniqueLocalRange in the web-fetch schema and has a regression test proving the setting permits fake-IP IPv6 ULA answers only when configured. (src/config/zod-schema.agent-runtime.ts:435, 920a265d8179)
  • Stale branch replaces the shared merge semantics: The PR's mergeSsrFPolicies is a two-policy object spread, so an agent hostname list replaces a configured global list instead of retaining the canonical additive policy behavior. (src/infra/net/ssrf.ts:73, 0e6d4c84987b)
  • Stale branch omits current IPv6 setting: The PR schema adds private-network and hostname fields but does not include allowIpv6UniqueLocalRange, so a rebase that preserves this old schema shape would remove a currently supported web-fetch compatibility setting. (src/config/zod-schema.agent-runtime.ts:336, 0e6d4c84987b)
  • Feature-history provenance: The current IPv6 fake-IP compatibility dates to 9b6670d5c924e2889e288c028588dbfab39e855d (fix(ssrf): allow IPv6 fake-ip SSRF opt-in, 2026-04-29T20:31:17+01:00); current web_fetch cache and trusted-proxy work also followed the draft. (src/infra/net/ssrf.ts:51, 9b6670d5c924)
  • Current main cache contract: Current main discriminates cached fetches by the two supported SSRF compatibility flags, trusted proxy use, request headers, user agent, and provider; a rebased policy extension must preserve this owner-boundary behavior. (src/agents/tools/web-fetch.ts:708, 920a265d8179)

Likely related people:

  • Jeff: Authored the current IPv6 fake-IP SSRF opt-in that the stale schema must preserve. (role: introduced current compatibility behavior; confidence: high; commits: 9b6670d5c924; files: src/infra/net/ssrf.ts, src/agents/tools/web-fetch.ts, src/config/zod-schema.agent-runtime.ts)
  • Peter Steinberger: Authored the later trusted-environment proxy handling in the web_fetch path and has the strongest recent history signal in the shared SSRF/web-fetch area. (role: recent area contributor; confidence: medium; commits: 66336bf7c846, 74f3ec1223ee; files: src/agents/tools/web-fetch.ts, src/infra/net/ssrf.ts)
  • Tak Hoffman: Authored this draft and appears in file-history sampling for the affected SSRF/web-fetch surface; included for routing, not as sole ownership. (role: prior contributor to the affected area; confidence: medium; commits: 0e6d4c84987b; files: src/agents/openclaw-tools.ts, src/agents/tools/web-fetch.ts, src/infra/net/ssrf.ts)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (1 earlier review cycle)
  • reviewed 2026-07-30T20:19:24.383Z sha 0e6d4c8 :: needs real behavior proof before merge. :: [P1] Rebase onto the canonical SSRF policy merge | [P1] Preserve IPv6 ULA fake-IP compatibility

@clarktjanson-hub

Copy link
Copy Markdown

+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 (http://127.0.0.1:3000/health and a small queue-summary endpoint). The service exposes monitoring data only on loopback, by design — it's not reachable from elsewhere on the LAN. The heartbeat fail-closes correctly on every cycle right now (which is the desired behavior given the SSRF guard's defaults), but it means I have no autonomous monitoring path until the agent's web_fetch can be opted-in to loopback for that specific destination.

The schema-level exposure of allowedHostnames and dangerouslyAllowPrivateNetwork at the per-agent layer is precisely the seam I need. Configuring a single agent (the heartbeat one) with a narrow allowlist for 127.0.0.1 would close the gap without weakening the guard's posture for any other agent or tool call.

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 clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. 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.

@clawsweeper clawsweeper Bot added 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. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Jun 14, 2026
@clawsweeper clawsweeper Bot added status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. 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: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Jun 28, 2026
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Jul 30, 2026
@steipete

Copy link
Copy Markdown
Contributor

Thanks for the PR. We're closing pull requests opened before April 2026 that have gone stale against current main.

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.

@steipete steipete closed this Oct 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling maintainer Maintainer-authored PR 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: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: L status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants