netpolicy

package
v0.10.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 27, 2026 License: MPL-2.0 Imports: 8 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package netpolicy applies a network-boundary policy to HTTP clients used to fetch untrusted resources.

Index

Constants

This section is empty.

Variables

View Source
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

func NewHTTPClient(base *http.Client, policy Policy) (*http.Client, error)

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.

func WithPolicy

func WithPolicy(ctx context.Context, policy Policy) context.Context

WithPolicy records a policy in ctx for render pipelines that construct their asset resolver below a public API boundary.

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

func FromContext(ctx context.Context) Policy

FromContext returns the policy stored in ctx, or the public-only zero value.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL