Documentation
¶
Overview ¶
Package clientip resolves the real client IP of an HTTP request. X-Forwarded-For is honored ONLY when the direct peer is a configured trusted proxy, so a client cannot spoof XFF to forge its address for the login guard or the rate limiter.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Key ¶
Key normalizes an IP to a rate-limit / lockout key: an IPv4 address maps to itself (/32), an IPv6 address maps to its /64 network — so an attacker cannot rotate addresses within a single (typically /64) allocation to mint unbounded distinct keys and evade per-IP limits or the auto-block.
func ParseCIDRs ¶
ParseCIDRs parses a comma-separated CIDR list, skipping blank/invalid entries.
Types ¶
type Resolver ¶
type Resolver struct {
// contains filtered or unexported fields
}
Resolver derives a request's client IP against a set of trusted-proxy CIDRs.
func NewResolver ¶
NewResolver builds a Resolver from a comma-separated CIDR list (env KEN_TRUSTED_PROXIES). An empty/blank list means "no proxy" — RemoteAddr is always used and XFF is ignored.
func (*Resolver) IP ¶
IP returns the request's client IP. When the direct peer is a trusted proxy the rightmost X-Forwarded-For hop that is a valid IP and not itself a trusted proxy is used (across all XFF header lines); otherwise RemoteAddr's host is returned and XFF is ignored.
func (*Resolver) TrustedPeer ¶
TrustedPeer reports whether the request's direct peer (RemoteAddr) is one of the configured trusted proxies — i.e. whether this request's X-Forwarded-* headers may be believed. With no trusted proxies configured it is always false.