package netpolicy

Import Path
	github.com/pancsta/d2/lib/netpolicy (on go.dev)

Dependency Relation
	imports 8 packages, and imported by one package

Involved Source Files Package netpolicy applies a network-boundary policy to HTTP clients used to fetch untrusted resources.
Package-Level Type Names (only one)
/* sort by: | */
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. AllowPrivateNetworks bool func FromContext(ctx context.Context) Policy func NewHTTPClient(base *http.Client, policy Policy) (*http.Client, error) func WithPolicy(ctx context.Context, policy Policy) context.Context
Package-Level Functions (total 3)
FromContext returns the policy stored in ctx, or the public-only zero value.
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.
WithPolicy records a policy in ctx for render pipelines that construct their asset resolver below a public API boundary.
Package-Level Variables (only one)
ErrBlockedAddress means a request resolved to a non-public address.