Repository navigation
Description
Summary
pkg/vmcp/session opens a persistent connection to every backend during
session initialize (the MCP handshake plus capability listing). These
session-init dials use http.DefaultTransport and carry no
net.Dialer.Control hook, and NewSessionFactory exposes no option to
inject one. This is asymmetric with the per-call backend client in
pkg/vmcp/client, which already offers WithDialControl for exactly this
purpose.
The consequence is a gap for any embedder that installs a dial guard (for
example, an SSRF / DNS-rebinding guard that refuses dials resolving into
private IP ranges) on the backend client: the guard covers the aggregator
and tool-call paths, but it does not cover the session-init dials the
session factory performs. If a backend endpoint is operator- or
attacker-influenceable, session initialize will dial it — and run the
handshake and capability listing against it — regardless of the guard
installed elsewhere.
Why this matters
The dial-control hook fires after DNS resolution and before the TCP
handshake, receiving the resolved peer IP. That is what defeats
DNS-rebinding: a hostname can pass a name-based check and then resolve to a
blocked IP. Because the session-init path has no such hook, there is
currently no way to enforce a private-address (or any other) dial policy on
the connections opened at session creation.
Investigation (current main, v0.47.0)
pkg/vmcp/session/factory.go—NewSessionFactory(registry, opts ...MultiSessionFactoryOption)
exposes onlyWithMaxBackendInitConcurrency,WithBackendInitTimeout,
WithRequestTimeoutResolver, andWithRevisionLookup. There is no
dial-control option.pkg/vmcp/session/internal/backend/mcp_session.go—createMCPClient
builds the transport chain frombase := http.RoundTripper(http.DefaultTransport)
for both thestreamable-httpandssebranches. The default transport
has nonet.Dialer.Control, so the resolved peer IP is never inspected.- Precedent already in-tree:
pkg/vmcp/client/client.godefines
WithDialControl(control func(network, address string, c syscall.RawConn) error) Option,
plumbed throughbackendDialerandnewBackendTransportonto the
per-backend*http.Transport. Its doc comment documents the caveats an
embedder must understand (per-TCP-dial not per-request; proxy transparency;
both IP families). pkg/networkingalready provides the building blocks
(NewPrivateIPBlockingDialContext,protectedDialerControl,
IsPrivateIP) an embedder would use to construct such a control.
Proposed change
- Add
session.WithDialControl(control func(network, address string, c syscall.RawConn) error) MultiSessionFactoryOption,
mirroring the signature and doc caveats ofvmcpclient.WithDialControl
exactly. - Thread it into
backend.NewHTTPConnectoras anHTTPConnectorOptionand
intocreateMCPClient, so that when set, the base transport is built from
a cloned*http.TransportwhoseDialContextuses a
net.Dialer{Control: control}— instead of barehttp.DefaultTransport—
for both thestreamable-httpandssebranches. - Reuse the same dialer/transport construction the client package already
uses (backendDialer/newBackendTransport) so the two paths stay in
sync; consider extracting a small shared helper rather than duplicating. - Optionally wire the option in
pkg/vmcp/cli/serve.gowhere the session
factory is constructed, so a production deployment can opt into a guard.
Done when
- A
MultiSessionFactoryOptionexists to supply a dial control to
NewSessionFactory. - When the control is set, it fires on session-init backend dials for
bothstreamable-httpandssetransports — pinned by a test that
installs a deny-all control and asserts the backend receives zero
requests duringinitialize. - When the control is unset, behavior is byte-for-byte identical to
today (default transport, no hook). - The option's signature matches
net.Dialer.Controland the existing
vmcpclient.WithDialControlexactly, and carries the same caveat
documentation.
Activity
tgrunnagle commentedon Sep 8, 2026
Related: #6546 — both stem from the same
MultiSessionFactoryownership boundary over per-session backend connections (dial control on the way in; teardown on the way out).Add dial-control option to vMCP session factory (#6547)