Documentation
¶
Overview ¶
Package outbound provides the guarded HTTP transport for calls to destinations that someone other than the operator chooses, such as an organization's connector URL or the authorization server it names.
The transport refuses internal destinations after name resolution, at connect time, so DNS rebinding cannot pass: loopback, RFC 1918 and RFC 4193 private ranges, link-local with the cloud metadata address, unspecified, CGNAT and every other address that is not globally reachable, including the IPv4-mapped IPv6 forms of these. It connects to exactly the addresses it checked. Only https is sent, except to a listed private destination.
It works behind an HTTP proxy taken from HTTP_PROXY, HTTPS_PROXY and NO_PROXY (and their lowercase forms), read when the transport is built. A proxied connection is a CONNECT tunnel to the checked IP, never to the hostname, so the proxy does not resolve the host again; the configured proxy's own address is the only address reached without a check. A host that NO_PROXY matches is dialed directly and keeps the full guard. A proxy that admits destinations by domain name only refuses a CONNECT to an IP; list such hosts in NO_PROXY.
The same transport serves mcp-oauth's own guarded clients (the JWKS and token exchange clients of providers/oidc and the client ID metadata document fetch), so their behaviour does not drift.
Use NewClient, or set CheckRedirect on your own http.Client: net/http keeps custom headers such as X-API-Key on every redirect.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrRefusedDestination = egress.ErrRefusedDestination
ErrRefusedDestination is wrapped by every error for a destination the guard refused: an internal address, or plain http to a host that is not a listed private destination. Retrying the same request cannot succeed.
Functions ¶
func CheckRedirect ¶
CheckRedirect is the redirect policy for a client on the guarded transport. Once a redirect chain leaves the first request's origin (scheme, host and port), every request header is dropped except Accept, Accept-Encoding, Accept-Language, Cache-Control, Content-Type, Mcp-Protocol-Version and User-Agent: no Authorization, Cookie, Proxy-Authorization or custom credential header such as X-API-Key reaches another origin. A redirect that would resend a request body to another origin (307 or 308) is refused, whatever the method. The Transport applies the same rule again after the client has added its cookie jar's cookies, and for a client with another redirect policy. Same-origin redirects keep every header. The chain stops after 10 redirects. A redirect target goes through the same guard as the first request, so a redirect to an internal address is refused like a direct call.
Types ¶
type Options ¶
type Options struct {
// PrivateHosts are platform-managed exceptions: hostnames that may
// resolve to RFC 1918, RFC 4193 and RFC 6598 addresses and may be reached over plain
// http. Loopback, link-local (the metadata address) and unspecified
// addresses stay refused for them. Hosts match case-insensitively and
// ignore one trailing dot. Empty by default.
PrivateHosts []string
// RootCAs, when non-nil, replaces the system pool for verifying
// destination certificates.
RootCAs *x509.CertPool
// InterceptingProxyCA is the PEM-encoded CA of a TLS-intercepting proxy,
// trusted in addition to RootCAs (or the system pool) for destinations,
// and in addition to the system pool for the HTTPS proxy itself. It is an explicit
// opt-in: such a proxy decrypts the traffic and sees every credential sent
// through it. The CA is trusted for every destination of the transport.
// Without it, a proxy that intercepts TLS fails verification.
InterceptingProxyCA []byte
// DialTimeout bounds each connection set-up, through the proxy included;
// zero means 10 seconds.
DialTimeout time.Duration
}
Options configures the guarded transport. The zero value allows public HTTPS destinations only and verifies them against the system trust store.
type Transport ¶
type Transport struct {
// contains filtered or unexported fields
}
Transport is the guarded http.RoundTripper.
func NewTransport ¶
NewTransport returns the guarded transport for opts. It fails only when InterceptingProxyCA holds no certificate or the system pool cannot be loaded to add it to.
func (*Transport) CloseIdleConnections ¶
func (t *Transport) CloseIdleConnections()
CloseIdleConnections closes the transport's idle connections.