Documentation
¶
Overview ¶
Package netguard owns the outbound-address policy: which destinations the router may dial on behalf of untrusted input (client-supplied URLs, plugin requests, third-party proxy feeds). Every outbound path that dials a caller-chosen host goes through this package, so the blocked ranges exist in one place only.
Index ¶
- Variables
- func CheckURL(target *url.URL) error
- func DialContext(dialer *net.Dialer, resolver Resolver) func(ctx context.Context, network, address string) (net.Conn, error)
- func IsLocalHostname(host string) bool
- func IsPublicAddress(address netip.Addr) bool
- func IsPublicIP(ip net.IP) bool
- func NewHTTPClient(timeout time.Duration) *http.Client
- func PublicHostLiteral(host string) (literal bool, public bool)
- func ResolvePublic(ctx context.Context, resolver Resolver, host string, ipv4Only bool) (net.IP, error)
- type Resolver
Constants ¶
This section is empty.
Variables ¶
var ErrBlockedAddress = errors.New("destination address is not public")
ErrBlockedAddress reports a destination outside the public unicast space.
Functions ¶
func CheckURL ¶
CheckURL validates scheme and host of one URL without DNS. Dial-time resolution still applies through the guarded transport.
func DialContext ¶
func DialContext(dialer *net.Dialer, resolver Resolver) func(ctx context.Context, network, address string) (net.Conn, error)
DialContext returns a dial function that resolves the target through ResolvePublic and dials the pinned address.
func IsLocalHostname ¶
IsLocalHostname reports hostnames that name the local machine or a local zone. They are refused before resolution: their answers are host-defined.
func IsPublicAddress ¶
IsPublicAddress reports whether address is a globally routable unicast address. IPv4-mapped IPv6 addresses are unmapped first.
func NewHTTPClient ¶
NewHTTPClient returns a client that only reaches public http(s) destinations: every dial pins a validated public address, every redirect hop re-checks scheme and host, and environment proxies are ignored (a proxy would dial the target on the client's behalf, bypassing the pin).
func PublicHostLiteral ¶
PublicHostLiteral classifies host without DNS: literal reports whether host is an IP literal, public whether that literal (or, for hostnames, the name itself) may be dialed. Hostnames still need ResolvePublic at dial time.
func ResolvePublic ¶
func ResolvePublic(ctx context.Context, resolver Resolver, host string, ipv4Only bool) (net.IP, error)
ResolvePublic resolves host and returns the first public address. IP literals are checked directly. ipv4Only restricts both literals and answers to IPv4. Callers dial the returned IP, never the name again, which closes DNS rebinding between check and dial.