Documentation
¶
Overview ¶
Package clientip resolves the real client address of a request that may have passed through load balancers or proxies.
A WAF that keys rate limits and IP lists on the wrong address is worse than none, so forwarding headers are only trusted when the request arrives from a configured trusted proxy, and X-Forwarded-For is walked right to left.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Resolver ¶
type Resolver struct {
// contains filtered or unexported fields
}
Resolver resolves client IPs. The zero value trusts no proxies and always returns the peer address.
func NewResolver ¶
NewResolver returns a Resolver that trusts forwarding headers set by peers in the given CIDR prefixes (for example the cloud load balancer ranges). Plain addresses are accepted and treated as single-host prefixes.
func (*Resolver) Resolve ¶
Resolve returns the client address for a request received from peer.
If peer is not a trusted proxy, peer is the client. Otherwise the X-Forwarded-For chain is walked from right to left, skipping trusted proxies; the first untrusted address is the client. If every hop is trusted, the leftmost valid address is returned. A malformed entry stops the walk, and the last valid address seen is returned.
The Forwarded header (RFC 7239) is not consulted yet.