realclientip

package
v1.0.521 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: MIT Imports: 5 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

func (r *Resolver) ClientIP(req *http.Request) string

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

func (r *Resolver) SetTrustedProxies(cidrs []string) error

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

func (r *Resolver) TrustedProxies() []string

TrustedProxies returns the current trusted-proxy set as strings.

Jump to

Keyboard shortcuts

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