Documentation
¶
Overview ¶
Package netguard keeps outbound calls to URLs that instance admins configure — webhooks, custom OAuth/OIDC providers, SAML metadata, privacy destinations — off the server's own network, and parses the network lists (trusted proxies, allowed networks) the operator configures.
The check runs on the address actually dialled, after DNS resolution, so a name that resolves to a public address when saved and an internal one later (DNS rebinding), or a redirect to an internal URL, is refused too.
Index ¶
- Variables
- func Allowed(addr netip.Addr, allow Networks) bool
- func CheckHost(ctx context.Context, host string, allow Networks) error
- func ClientIP(remoteAddr string, xff []string, trusted Networks) string
- func Control(allow Networks) func(string, string, syscall.RawConn) error
- func IsPublic(addr netip.Addr) bool
- func Transport(base http.RoundTripper, allow Networks) *http.Transport
- type Networks
Constants ¶
This section is empty.
Variables ¶
var ErrNotPublic = errors.New("address is not public")
ErrNotPublic is what a guarded dial fails with for an address outside the public internet and outside the allowed networks.
Functions ¶
func Allowed ¶
Allowed reports whether a guarded call may reach addr: a public address, or one in allow.
func CheckHost ¶
CheckHost resolves host, when a URL is saved, so an admin learns straight away that it points inside the network. The dial-time check is the one that holds.
func ClientIP ¶
ClientIP is the address of the caller of a request that reached the server from remoteAddr carrying the X-Forwarded-For header lines xff, in the order they arrived. A proxy may append its hop as a line of its own rather than to the existing value (HAProxy's option forwardfor), so every line counts: read alone, the first line is whatever the client wrote.
X-Forwarded-For is written by whoever sends the request, so it is believed only as far as proxies the operator trusts vouch for it: when the peer is a trusted proxy, the header is read from the right, skipping trusted proxies, and the first address that is not one is the client. An untrusted peer is the client itself, whatever the header says. With trusted = "*" every hop is trusted and the leftmost address is the client (the previous behaviour, and upstream's).
Types ¶
type Networks ¶
type Networks struct {
// contains filtered or unexported fields
}
Networks is a set of addresses given as a comma-separated list of IPs and CIDRs, or "*" for every address. The zero value contains nothing.
func MustParseNetworks ¶
MustParseNetworks is ParseNetworks for constants.
func ParseNetworks ¶
ParseNetworks parses "10.0.0.0/8, 192.168.1.5, ::1" or "*". Blank is empty.