Documentation
¶
Overview ¶
Package realclientip resolves the effective client IP of an admin-UI request behind trusted reverse proxies (RISK-019, ADR-0045).
A Resolver owns one trusted-proxy set. ClientIP returns the direct peer unless that peer is itself a configured trusted proxy; only then does it read X-Forwarded-For and return the rightmost hop that is not a trusted proxy. That gate is the whole security argument: a direct attacker cannot forge a victim's IP through X-Forwarded-For, because the attacker's own peer address is not in the trusted set. An empty set (the zero value) never trusts the header.
Package main owns the single application instance, persistence of the set in admin settings, and every call site. This package holds no package-level state, starts no goroutines and does no I/O or logging.
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 holds one trusted-proxy set. The zero value is ready to use and trusts no proxy. It is safe for concurrent use and must not be copied after first use.
func (*Resolver) ClientIP ¶
ClientIP returns the effective client IP for an admin-UI per-IP decision. It returns the direct peer unless that peer is a configured trusted proxy, in which case it returns the rightmost X-Forwarded-For hop that is not itself a trusted proxy (the real client behind the proxy chain). See the package comment for the security rationale.
func (*Resolver) SetTrustedProxies ¶
SetTrustedProxies replaces the trusted-proxy set. An empty/blank list clears it (the safe default: no X-Forwarded-For is ever trusted). Returns an error WITHOUT mutating state if any entry is invalid.
func (*Resolver) TrustedProxies ¶
TrustedProxies returns the current trusted-proxy set as strings.