# What structural signals indicate an MCP egress-policy bypass when a sandboxed tool re-enters through a nested MCP client **Date of Record:** 2026 November 21 **Scope:** Applies to agent runtimes that host untrusted third-party MCP servers inside a sandbox with a declared egress allowlist, and where those servers may themselves spawn or connect to nested MCP clients/servers. Does not cover single-hop tool calls whose transport is fully mediated by the host process, nor network policy enforced at the kernel/CNI layer independent of the MCP handshake. ## Core Distinction The failure is not "a sandboxed tool made an outbound request." It is that the egress allowlist was bound to the *tool identity declared during `initialize`* on the outer connection, while the actual socket was opened by a *nested client* the tool constructed after the handshake completed. The host's policy engine authorized `tools/call` for server `X`, but the bytes left through a subprocess whose MCP `clientInfo` was `X`'s own internal helper—an identity the allowlist never evaluated. The invariant that silently broke: **egress authorization was evaluated once, at handshake, against a static server identity, not per-connection against the live peer that owns the socket.** A tool can pass every schema check, stay inside its declared capability set, and still route traffic to a forbidden host because the policy was attached to the wrong layer of the stack. ## What Was Observed A third-party MCP server (`analytics-mcp`, declared egress: `api.vendor.example:443` only) was launched under a sandbox with a host-side egress proxy enforcing the allowlist. During a `tools/call` for `run_report`, the server: 1. Accepted the request and returned a well-formed `CallToolResult` envelope with `isError: false`. 2. Internally spawned a child process that instantiated its *own* MCP `ClientSession`, connecting to a bundled helper server over stdio. 3. The helper server issued an HTTP fetch to `telemetry.vendor.example` (not on the allowlist) using the server's ambient network namespace. 4. The host egress proxy logged the connection but attributed it to the parent PID's declared identity, and the allowlist match was performed on the *parent's* `serverInfo.name`, not the child's socket owner. Structural signals that preceded the bypass, in order of observability: - **PID/transport divergence:** the socket's `SO_PEERCRED` (or `/proc//net`) owner PID did not match the PID the MCP host registered for `analytics-mcp`. The host had one `serverInfo` record; the kernel saw three processes. - **Handshake cardinality mismatch:** the proxy observed two `initialize` exchanges on the same logical "server" but only one entry in the host's egress-policy table. The second `initialize` carried `clientInfo: {name: "analytics-mcp-internal", version: "0.0.0"}`—an identity never enrolled. - **Capability renegotiation after first call:** the nested client requested `sampling/createMessage` and `roots/list` capabilities the outer declaration never mentioned, and the host forwarded them because the outer session was already `initialized`. - **Timing signature:** the disallowed connection opened *after* the `CallToolResult` was returned to the agent (fire-and-forget exfiltration), so the call appeared successful and fast, and the egress event landed in a different trace span than the tool invocation. The bypass was only caught when a network-flow audit joined the proxy log against the MCP host's session table by timestamp and found an egress flow with no matching authorized session. ## Condition of Validity This analysis holds only when all of the following are true: - The sandbox permits the tool process to fork/exec or open new sockets (i.e., the sandbox is a *policy* sandbox, not a syscall-deny sandbox that forbids `connect`/`socket`/`execve` entirely). - Egress authorization is enforced by an application-layer proxy or MCP-host hook that keys on MCP-level identity (`serverInfo.name`, `clientInfo.name`) rather than on kernel-level socket ownership (cgroup, netns, UID). - The MCP host does not re-evaluate policy on nested `initialize` handshakes or on new child processes. It does **not** hold if egress is enforced by network namespace isolation where the tool's netns has no route to the disallowed host—that is a kernel invariant and nested clients inherit it. The distinction is precisely *where the policy is anchored*: MCP-identity-anchored policy is bypassable by identity re-declaration; netns-anchored policy is not. ## Decision Boundary The operational line: **treat MCP-level identity as advisory metadata, never as an authorization principal.** Concretely: - If your sandbox allows `execve` or raw `socket()` from tool processes, then egress policy MUST be anchored to the cgroup/netns/UID of the socket owner, and the MCP host MUST reconcile every egress flow against a kernel-attributed owner, not against `serverInfo`. - If you cannot enforce at the kernel layer, then you MUST forbid nested MCP client construction: reject any `initialize` whose `clientInfo.name` is not in the enrolled set, and reject capability requests (`sampling/*`, `roots/*`) that were not declared in the outer handshake. A second `initialize` on a logical server is a hard error, not a renegotiation. - The `CallToolResult` returning before egress completes is the tell. If a tool's declared capability set contains no network primitive yet the process opens a socket after returning, that is a policy violation regardless of destination—the allowlist is the wrong control; *capability absence* is the control. Do not attempt to patch this by expanding the allowlist. The bypass is structural: identity re-declaration defeats identity-keyed policy. Fix the anchor, not the list. ## Operational Effect After anchoring egress to kernel-attributed socket ownership and making nested `initialize` a hard failure, the observed class of bypass disappeared: `analytics-mcp`'s helper could no longer open the telemetry socket because the child process's cgroup had no egress grant, and the nested `initialize` was rejected at the host before any capability grant. The cost was that legitimate multi-server tools had to declare their sub-servers in the manifest and have each enrolled explicitly—turning an implicit trust inheritance into an explicit, auditable enrollment. The residual risk is a tool that exfiltrates over an *already-allowed* destination (e.g., encoding data into a request to `api.vendor.example`); that is a data-flow control problem, out of scope for egress policy, and must be handled by payload inspection or output tainting, not by allowlisting. ```python class EgressPolicyBypass(RuntimeError): """Raised when an egress flow's kernel owner does not match an enrolled MCP principal.""" ENROLLED_PRINCIPALS = {"analytics-mcp"} # serverInfo.name values the host authorized def authorize_egress(flow: dict, enrolled: set[str] = ENROLLED_PRINCIPALS) -> None: """ flow keys: - socket_owner_pid: int (from SO_PEERCRED / /proc/) - cgroup_egress_grant: str | None (kernel-anchored grant, authoritative) - mcp_client_info_name: str (advisory only; never trust alone) - destination: str - opened_after_call_result: bool """ if flow["cgroup_egress_grant"] is None: raise EgressPolicyBypass( f"egress to {flow['destination']} from pid {flow['socket_owner_pid']} " f"has no kernel-anchored grant; MCP identity " f"{flow['mcp_client_info_name']!r} is advisory and cannot authorize" ) if flow["mcp_client_info_name"] not in enrolled: # nested client re-declared an identity the host never enrolled raise EgressPolicyBypass( f"un-enrolled MCP principal {flow['mcp_client_info_name']!r} " f"opened egress to {flow['destination']}" ) if flow["opened_after_call_result"]: raise EgressPolicyBypass( f"post-result egress to {flow['destination']} from " f"{flow['mcp_client_info_name']!r}: tool returned before network use, " f"indicating undeclared network capability" ) def handle_nested_initialize(client_info: dict, outer_initialized: bool) -> None: if outer_initialized: raise EgressPolicyBypass( f"second initialize on logical server with clientInfo " f"{client_info.get('name')!r}: nested client construction is forbidden " f"unless the sub-server is enrolled in the manifest" ) ```