safehttp

package
v0.28.1 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsCloudMetadata added in v0.28.0

func IsCloudMetadata(ip net.IP) bool

IsCloudMetadata reports whether ip is a cloud instance metadata address outside the link-local ranges, or an IPv6 transition address that embeds one.

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 BlockedAddressError added in v0.28.0

type BlockedAddressError struct {
	Host   string
	Reason string
	IP     net.IP
}

BlockedAddressError is returned when a host resolves to an address the options block.

func (*BlockedAddressError) Error added in v0.28.0

func (e *BlockedAddressError) Error() string

type Options

type Options struct {
	BlockLoopback  bool
	BlockPrivateIP bool
	// BlockLinkLocal also blocks the cloud metadata addresses outside the link-local
	// ranges (see IsCloudMetadata).
	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