trustedproxy

package
v0.75.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 23, 2026 License: BSD-3-Clause Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractHostIP

func ExtractHostIP(hostPort string) netip.Addr

ExtractHostIP parses the IP from a host:port string and returns it unmapped.

Types

type List

type List struct {
	// contains filtered or unexported fields
}

List holds a parsed set of trusted upstream proxy prefixes and answers trust questions against it. The zero value (and a nil *List) is a valid, empty list that never trusts any address, so callers can use it without a nil check.

func FromPrefixes

func FromPrefixes(prefixes []netip.Prefix) *List

FromPrefixes wraps an already-parsed set of prefixes in a List.

func Parse

func Parse(raw string) (*List, error)

Parse parses a comma-separated list of CIDR prefixes or bare IPs into a List. Bare IPs are converted to single-host prefixes (/32 or /128). An empty input yields an empty List that trusts nothing.

func (*List) Contains

func (l *List) Contains(addr netip.Addr) bool

Contains reports whether the given address falls within any trusted prefix.

func (*List) Empty

func (l *List) Empty() bool

Empty reports whether the list contains no prefixes.

func (*List) IsTrusted

func (l *List) IsTrusted(remoteAddr string) bool

IsTrusted reports whether the given host:port or bare IP falls within the list.

func (*List) ResolveClientIP

func (l *List) ResolveClientIP(remoteAddr, xff string) netip.Addr

ResolveClientIP extracts the real client IP from X-Forwarded-For using the list. It walks the XFF chain right-to-left, skipping IPs that match trusted prefixes; the first untrusted IP is the real client. If the list is empty or remoteAddr is not trusted, it returns the remoteAddr IP directly, ignoring any forwarding headers.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL