Documentation
¶
Overview ¶
Package safehttp makes HTTP requests to addresses that come from users, such as webhooks, link previews and images, without letting them reach the app's own network (server-side request forgery):
client := safehttp.New(safehttp.Options{})
res, err := client.Get(userURL)
The client only connects to public addresses, checked on the address it actually dials, so a name that resolves to 127.0.0.1 or 10.0.0.5, or a redirect to one, is refused. It ignores proxy settings, which would connect on its behalf, and limits time, redirects, ports and the size of response bodies.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrBlocked = errors.New("safehttp: blocked")
ErrBlocked is returned, wrapped, for a request to an address or port the client doesn't allow.
var ErrTooLarge = errors.New("safehttp: response body too large")
ErrTooLarge is returned while reading a response body past MaxBody.
Functions ¶
Types ¶
type Options ¶
type Options struct {
// Timeout limits a whole request, redirects and body included; the
// default is 10 seconds.
Timeout time.Duration
// MaxBody limits response bodies; the default is 10 MiB.
MaxBody int64
// MaxRedirects is how many redirects are followed; the default is 5,
// and -1 follows none.
MaxRedirects int
// Ports are the ports it may connect to; the default is 80 and 443.
Ports []string
// Allow lists addresses it may connect to although they aren't public,
// such as a service of your own on the private network.
Allow []netip.Prefix
}
Options configure a client. The zero value is a safe default.