Documentation
¶
Overview ¶
Package netpolicy applies a network-boundary policy to HTTP clients used to fetch untrusted resources.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrBlockedAddress = errors.New("network policy blocked a non-public address")
ErrBlockedAddress means a request resolved to a non-public address.
Functions ¶
func CloneDefaultTransport ¶
func CloneDefaultTransport(base http.RoundTripper) *http.Transport
CloneDefaultTransport returns independent transport settings. If the process default was replaced with a custom RoundTripper, use standard defaults.
func NewHTTPClient ¶
NewHTTPClient clones base and applies policy without mutating the caller's client or transport. Public-only clients resolve each hostname themselves, reject the entire resolution if any address is non-public, and pass only a validated numeric address to a policy-owned transport dialer. Caller proxy, dial, and alternate-protocol hooks are not retained. Every new connection resolves and validates its destination, so redirects and DNS rebinding cannot bypass the policy.
A public-only client requires a standard *http.Transport. Custom protocol RoundTrippers can opt into trusted private-network behavior explicitly.
Types ¶
type Policy ¶
type Policy struct {
AllowPrivateNetworks bool
}
Policy controls which network destinations an HTTP client may reach. The zero value permits only public IP addresses. AllowPrivateNetworks is intended for trusted diagrams in environments that deliberately serve assets from a private network.
func FromContext ¶
FromContext returns the policy stored in ctx, or the public-only zero value.