Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ClientIP ¶ added in v0.6.1
ClientIP resolves the address of the client that sent a request. The TCP peer address is the answer unless the peer is one of the trusted proxies, in which case the X-Forwarded-For header is consulted.
A reverse proxy appends the address it saw to the end of the header, after whatever value the client supplied. Only the entries to the right of the client-supplied part were written by infrastructure we trust, so the header is read from right to left. Entries naming a trusted proxy are hops of our own infrastructure and are skipped, and the first remaining entry that parses as an IP address is the client. Entries to its left can be forged and are never read.
A header from a peer that is not trusted is ignored, since anyone can send one. When no usable entry exists the peer address is returned. An unparseable peer address resolves to 0.0.0.0.
func MaskIP ¶
MaskIP returns a masked version of the IP address for grouping purposes. IPv4 addresses are masked to /24 (zeroing the last octet). IPv6 addresses are masked to /48.
This is useful for rate limiting and freebie tracking where we want to group requests from the same network segment rather than individual IPs, reducing abuse potential from users with multiple addresses.
func ParseTrustedProxies ¶ added in v0.6.1
ParseTrustedProxies parses a list of CIDR blocks and single IP addresses into the networks of the reverse proxies whose forwarding headers can be trusted. A bare address is a network of exactly one host. An empty list returns no networks, which means no proxy is trusted.
Types ¶
This section is empty.