# Runtime outbound URL protection

1. **Registry key** 48 immutable consumers, five trust classes, exact configured origin
2. **Policy decision** normalized URL and origin, every A and AAAA answer, exact exception, reason code
   
   Refused: sanitized reason code, no raw retry
3. **Managed transport** dials the approved IP, original Host, SNI and certificate name, manual redirects, bounded body

## Components

| Component | Does | Does not |
| --- | --- | --- |
| `openprogram/host/security/url_policy.py` | URL and origin normalization; scheme, userinfo, host and port validation; full A/AAAA classification; exact owner exceptions; stable sanitized reason codes | Send requests or infer a caller's trust class |
| `openprogram/host/security/safe_http.py` | Immutable consumer registry; sync and async peer-constrained transports; Host and SNI preservation; manual redirects; credential, header, MIME, decoded-body, encoding, timeout, proxy and atomic-download enforcement | Accept caller-created policy objects or expose `verify=False` |
| Consumer adapters | Select one registry key; for configured services or callbacks, supply the exact owner-configured origin | Implement a second private-address classifier or retry through a raw client |
| `runtime_http_audit.py`, `doctor`, `scripts/checks/check_runtime_http.py` | Bounded sanitized denial state, owner exception and proxy reporting, AST inventory, SDK disposition, stale exclusion detection | Display userinfo, query, fragment, credentials, peer bodies or token-bearing paths |

## Trust classes

| Class (`URLTrustClass`) | Targets | Consumers |
| --- | --- | --- |
| `untrusted_public` | Arbitrary public URLs; every resolved address must be global | 4 |
| `fixed_public_service` | A service origin shipped with the product | 23 |
| `configured_service` | The exact origin the owner configured, private or local allowed | 18 |
| `loopback_callback` | A local callback | 1 |
| `owner_tool` | `tool.web_fetch.owner`, `tool.image_result.download.owner`: no address, port or method limits. Chosen only for a turn of the owner while `security.outbound_url.model_tools` is `open`, the default. | 2 |

## What is and is not covered

| Surface | Treatment |
| --- | --- |
| Arbitrary and derived URLs | `web_fetch`, attachments, generated assets, image result downloads, catalogs, marketplaces, updater metadata: managed clients, public or exact-service policy |
| Fixed and configured APIs | Web search, image APIs, channel REST, TTS, provider listing, probes and OAuth, Web model listing, MCP HTTP and SSE, local probes: fixed or owner-configured exact origins |
| Third-party SDKs | See [SDK dispositions](#sdk) |
| Owner control-plane liveness probes | Narrow loopback-only exclusions, inventoried; not Runtime URL fetches |
| Outside this design | Browser navigation, popups, Service Workers and page subresources (browser-control design and any owner egress isolation). Sandboxed code, plugins, external provider CLIs, package managers (sandbox, plugin trust, child-process and installation boundaries). |

The feature matrix scores this as partial for that reason.

## Transport and policy rules

| Area | Rule |
| --- | --- |
| Public requests | Only registry-declared methods, schemes and ports. All resolved addresses must be global. Rejected: metadata, loopback, private, link-local, CGNAT, multicast, reserved, unspecified, documentation and test, mapped, ambiguous, malformed. DNS failure closes. |
| Dialling | Sync and async `httpcore` backends dial only the approved IP tuple, verify the actual socket peer, and keep the normalized hostname for Host, SNI and certificate validation |
| Connection pools | Identity includes consumer, trust class, normalized origin, approved IPs, proxy identity |
| Redirects | Manual, each hop a new decision. Cross-origin configured-service redirects fail; public credentials are stripped. |
| Privacy | URL userinfo is rejected. Logs and public errors keep no query, fragment, token path, cookie or peer-controlled body; errors are origin-only. |
| Bounds | Headers, MIME, content encoding, decoded bytes, connect, read, write, pool and overall timeouts, temporary files |
| Downloads | Replace the destination only after full validation, flush, `fsync` and cleanup-safe completion |

### SDK dispositions

| Disposition | Consumers | Enforcement |
| --- | --- | --- |
| Injected transport | `provider.openai.sdk`, `provider.anthropic.sdk`, `provider.google.sdk`, `mcp.configured.http`, `mcp.configured.sse` | The SDK receives a scoped managed client or factory |
| Exact origin | Telegram, WeChat, Feishu, Matrix, Slack, Discord, fixed and configured TTS, other REST consumers | Origin frozen before credentials attach; redirects cannot move credentials |
| Derived URL extraction | Attachment, generated-asset and image-result consumers | The SDK or response yields a URL; Runtime transfers it through a dedicated managed consumer |
| Disabled | `provider.amazon_bedrock.sdk`, `channel.slack.gateway_sdk`, `channel.discord.gateway_sdk`, `tts.edge_sdk` | Fails with `UNMANAGED_TRANSPORT` before importing or using the SDK. Bedrock covers the stream and model-list entries, before any boto3 credential or client activity. |

### Owner exceptions and policy proxy

- **Owner exception**: A registered consumer plus exactly one normalized origin or canonical private or local CIDR. Rejects wildcards, suffixes, credentials, unknown fields, public and default-route networks, metadata, link-local ranges, and forms the consumer does not allow. Changed only through owner-authenticated settings.
- **Policy proxy**: Usable only with owner configuration `enforces_target_policy: true`. Runtime evaluates the target first, constrains the proxy peer separately, reports delegation through doctor and audit, and never retries direct.

**Static checks and inventory exclusions**

`scripts/checks/check_runtime_http.py` fails on an unregistered raw call, an active unmanaged SDK transport, a registry entry without a classified consumer, or a stale exclusion. `doctor` labels: `runtime-http-registry`, `runtime-http-owner-exceptions`, `runtime-http-policy-proxy`, `runtime-http-recent-denials`, `runtime-http-unmanaged-transport`.

| Exclusion | Owner and narrow reason |
| --- | --- |
| `security/safe_http.py` | Managed transport; the only direct `httpcore` pool and proxy construction |
| `programs/applications/browser/app_endpoint.py` | Browser control; loopback probe of the App's CDP endpoint |
| `cli/commands/capabilities/mcp.py` | Owner control plane; authenticated backend opener only |
| `cli/ink.py`, `cli/commands/maintenance/doctor.py`, `cli/commands/maintenance/rescue.py` | Owner control plane; exact loopback worker liveness socket only |
| `machines/peer.py`, `computer_use/providers/paired.py`, `security/remote_access.py` | Owner control plane; pairing with, probing and forwarding computer_use calls to an OpenProgram the owner linked, on the addresses its link names, with its device credential, no proxy or redirects; a UDP socket that only reads the LAN address |
| `interfaces/server/web_push.py` | Owner control plane; one encrypted notice per POST to a browser push service on an allow-listed https host (Apple, Google, Mozilla, Microsoft), no proxy or redirects |

Publication requires policy and address tests, real sync and async socket and TLS peer tests, DNS-rebinding prevention, redirect and credential-origin tests, response, decompression and timeout cleanup, all consumers migrated, zero active unmanaged transports, owner-only exact exceptions, doctor, audit and static enforcement, and the consumer compatibility contract.

## Design choices

| Choice | Mechanism | Reason |
| --- | --- | --- |
| Adopted | One pure URL and IP policy; all DNS answers must pass; every redirect reevaluated; origin-only errors; bounded decoded bodies | Covers target, redirect, credential and resource boundaries consistently |
| Adopted | Distinct trust classes | Owner-configured local services stay usable without giving public consumers private-network access |
| Adopted | Permission and network layering (Claude Code, CodeBuddy), structured deny reasons (Codex), fixed channel-media allowlists (CodeBuddy) | Permission answers who may request; transport policy answers which peer gets the connection and credentials |
| Modified | Hermes's process-wide `allow_private_urls` becomes an exact consumer plus origin or CIDR | Metadata and link-local targets stay non-exceptable |
| Modified | OpenClaw browser interception and Codex's whole-process proxy | Browser controls are a separate gate; a policy proxy is optional, owner-declared, peer constrained, visible in doctor, with no direct fallback |
| Rejected | URL-string-only checks, one DNS preflight, implicit redirects, inherited environment proxies, disabling TLS verification, raw fallback | Each leaves a target, rebinding, credential or bypass path |
| Rejected | User confirmation or hostname allow and deny as target enforcement | Neither validates every resolved address nor constrains the peer |
| Rejected | Public-only for every client | Breaks configured local model endpoints, MCP servers, intranet services |
| Rejected | Counting Origin and Host checks, CORS, owner authentication, browser checks or sandbox networking as this protection | Those guard other directions or execution boundaries |

**How other projects compare**

From fixed audited snapshots; what a snapshot does not confirm is described as unconfirmed, not absent.

| Project | URL-fetch evidence | Network or permission boundary | Taken |
| --- | --- | --- | --- |
| [Hermes](https://github.com/NousResearch/hermes-agent/blob/main/tools/url_safety.py) | Shared `url_safety` for web, browser, vision, gateway media. DNS failure closed; loopback, RFC1918, link-local, CGNAT, metadata, reserved, multicast, unspecified rejected; hop-by-hop redirects; sanitized URLs; streamed limits. | [`allow_private_urls`](https://hermes-agent.nousresearch.com/docs/user-guide/security/) relaxes several entries together; application checks do not replace OS isolation. | Shared fail-closed validation, full address set, redirect checks, sanitization, limits. Global switch made exact. |
| [OpenClaw](https://docs.openclaw.ai/gateway/security) | Private, internal and special-use targets denied by default, exact or wildcard exceptions, checks before navigation, interaction-generated loads and final URLs. Documents speculative navigation and subresource risk. | Request interception is not a network firewall: redirects, popups, Service Workers and background resources can still need egress isolation or a policy proxy. | Strict defaults, explicit exceptions. Browser interception is a separate boundary. |
| Claude Code | `WebFetch(domain:...)` allow and deny. The hostname goes to [Anthropic's safety blocklist](https://code.claude.com/docs/en/data-usage) first, cached five minutes; the owner may disable it. | [Bash sandbox](https://code.claude.com/docs/en/sandboxing) uses a Seatbelt or bubblewrap HTTP and SOCKS proxy inherited by children. It trusts the client hostname and does not inspect TLS, so broad domains and fronting stay risks. | Layered tool authorization, child-process egress policy. Hostname permission rejected as connect-time evidence. |
| [Codex](https://github.com/openai/codex/blob/main/codex-rs/network-proxy/README.md) | Does not substitute one WebFetch string check for a network boundary. | `codex-network-proxy`: HTTP and SOCKS5, exact or restricted wildcard domains, private-resolution rejection, limited read-only methods, MITM header hooks, Unix-socket control, structured audit; OS sandbox limits loopback bypass. | Structured deny reasons, audit, managed-policy concepts. Consumer-aware safe clients kept. |
| CodeBuddy 2.109.3 | `WebFetch` applies Security Center domain policy, rejects IP literals, `localhost` and some private ranges. WeCom media: official CDN allowlist, no redirects. | Sandbox `allowedDomains` intersects WebFetch permission. Full A/AAAA validation, peer binding and hop-by-hop redirects unconfirmed. | Fixed channel allowlists, intersection of permission and network policy. Literal-IP-only protection rejected. |
| Gemini CLI | [Documents](https://github.com/google-gemini/gemini-cli/blob/main/docs/reference/tools.md) that `web_fetch` can reach localhost and private networks; Plan Mode can require confirmation. Core 0.35.3 has IP and DNS utilities, not a general boundary. | Confirmation is a permission decision; it does not constrain the peer. | Explicit risk documentation. Confirmation rejected as enforcement. |
| OpenCode | `webfetch` permissions on the full URL: allow, ask, deny. [Documentation](https://opencode.ai/v2/docs/permissions) does not establish private-IP classification, full DNS results, hop-by-hop redirects or peer binding. | `shell` uses the host user's network; string rules are best effort. | Uniform resource permissions. A permitted URL still passes transport policy. |
| pi-mono | No built-in arbitrary-URL fetch confirmed; network comes from shell, installers, extensions. | No OS egress policy confirmed. Third-party `pi-sandbox` not counted. | Not an SSRF reference. Supports keeping third-party code outside this protection. |
| pi-ai | Protocol reference source, no Runtime URL consumer. | Not applicable. | Excluded. |
| weclaw | Messaging bridge to external agents; no independent URL fetch confirmed. | Inherits the launched CLI's tools and network. | Channel media and process launch are its relevant boundaries; not a safe-HTTP reference. |
| cc-internal, cx-internal, gm-internal | Wrap upstream launchers or reuse Gemini CLI; no independent strengthening confirmed. | Inherit upstream behaviour; added authentication or endpoints create no SSRF boundary. | Only their extra endpoints, credential forwarding and configuration audited; not counted as independent designs. |
| [OWASP](https://cheatsheetseries.owasp.org/cheatsheets/Server_Side_Request_Forgery_Prevention_Cheat_Sheet.html) | Separates known-service allowlisting from arbitrary-public validation, restricts protocols, validates every A/AAAA result. | One DNS preflight still has pinning and time-of-check risk; network controls recommended too. | Separate trust classes, connect-time peer constraints. Single preflight rejected. |

## Implementation status

Runtime-owned HTTP is implemented. Separate boundaries still to do:

| Boundary | Needed before claiming it |
| --- | --- |
| Browser navigation and page traffic | Policy and tests for navigation, popups, Service Workers, background resources, redirects, downloads, CDP and profiles across every backend; an enforcing egress boundary where interception is not enough |
| Plugin and arbitrary-code networking | Trust and sandbox stay separate; an OS or policy-proxy egress boundary if these need restricted network |
| Disabled SDK network features | Enable only after the SDK takes managed transport injection, or an enforcing policy proxy has equivalent tests |

[Execution authority and sandbox](https://fzkuji.github.io/OpenProgram/docs/reference/design/runtime/security/sandbox-architecture.html) · [Network proxy](https://fzkuji.github.io/OpenProgram/docs/reference/design/providers/requests/network-proxy.html) · [Feature matrix](https://fzkuji.github.io/OpenProgram/docs/reference/design/framework-comparison/feature-matrix.html)
