Documentation
¶
Overview ¶
Package safehttp builds HTTP clients for fetching user-chosen URLs. Every connection they open, including the ones that follow redirects, must target a public unicast address.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrBlockedDestination = errors.New("destination is not a public address")
ErrBlockedDestination reports a connection refused because its address is not public.
Functions ¶
func DialControl ¶
DialControl returns a net.Dialer Control function that refuses, after DNS resolution, every address allow rejects. Nil allow means IsPublicIP. Rejections wrap ErrBlockedDestination.
func IsPublicIP ¶
IsPublicIP reports whether ip is a public unicast address. It rejects loopback, private and ULA (fc00::/7), unspecified, link-local (which holds the 169.254.169.254 cloud metadata address), multicast and CGNAT addresses.
Types ¶
type Config ¶
type Config struct {
// Timeout bounds the dial and the whole request; zero means no limit.
Timeout time.Duration
// MaxRedirects is the number of redirects followed before failing.
MaxRedirects int
// Allow decides which dialed addresses are accepted. Nil means IsPublicIP.
// Only tests that talk to loopback servers set it.
Allow func(net.IP) bool
}
Config sets the limits of a client returned by NewClient.