Documentation
¶
Overview ¶
Package httpclient builds outbound HTTP clients for URLs that users control (webhooks, link previews, avatars by URL). Safe refuses to connect to loopback, private, link-local (cloud metadata), multicast and other internal addresses. The check runs on the resolved IP at connect time, so DNS rebinding and redirects to internal hosts are blocked too.
resp, err := httpclient.Safe(httpclient.Options{}).Get(userURL)
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrBlockedAddress = errors.New("httpclient: destination address is not allowed")
ErrBlockedAddress is returned when the destination is an internal address.
View Source
var ErrBodyTooLarge = errors.New("httpclient: response body too large")
ErrBodyTooLarge is returned by reads past Options.MaxBody.
Functions ¶
Types ¶
type Options ¶
type Options struct {
// Timeout bounds the whole request (default 10s).
Timeout time.Duration
// MaxBody bounds response bodies; reads past it fail (default 10 MiB).
MaxBody int64
// MaxRedirects (default 5).
MaxRedirects int
// Allow lists extra prefixes that may be reached (e.g. an internal
// service network). Use sparingly.
Allow []netip.Prefix
}
Options tune Safe.
Click to show internal directories.
Click to hide internal directories.