safehttp

package
v0.27.0-rc2 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsLinkLocal added in v0.27.0

func IsLinkLocal(ip net.IP) bool

IsLinkLocal reports whether ip is a link-local address or an IPv6 transition address that embeds one.

func IsLoopback added in v0.27.0

func IsLoopback(ip net.IP) bool

IsLoopback reports whether ip is a loopback address, the unspecified address (which connects to the local host), or an IPv6 transition address that embeds a loopback address. An embedded 0.0.0.0 does not count: a translator would deliver it to its own host, not ours.

func IsPrivate added in v0.27.0

func IsPrivate(ip net.IP) bool

IsPrivate reports whether ip is a private address or an IPv6 transition address that embeds one.

func NewClient

func NewClient(options Options) *http.Client

NewClient returns an HTTP client that can block selected local address ranges.

func NewSafeTransport

func NewSafeTransport(options Options) http.RoundTripper

func ValidateURL added in v0.27.0

func ValidateURL(ctx context.Context, rawURL string, options Options) error

ValidateURL applies the same address policy used when making HTTP requests. Callers must still use a policy-enforcing transport when they connect, since DNS can change between validation and the request.

Types

type Options

type Options struct {
	BlockLoopback  bool
	BlockPrivateIP bool
	BlockLinkLocal bool
	AllowList      []string
	Timeout        time.Duration
	Headers        http.Header
	TokenSource    oauth2.TokenSource
	// DialRetryTimeout bounds retries of transient TCP failures before any HTTP bytes are sent.
	DialRetryTimeout time.Duration
}

Jump to

Keyboard shortcuts

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