Documentation
¶
Overview ¶
Package clientnet classifies authenticated frontend peer and proxy addresses.
Index ¶
- func ClientNet(r *http.Request, trusted ...netip.Prefix) (netip.Addr, bool)
- func ForwardedHost(r *http.Request) string
- func ForwardedPrefix(r *http.Request) string
- func ForwardedProto(r *http.Request) string
- func IsPublicIP(ip net.IP) bool
- func JoinPrefix(forwardedPrefix, mountPrefix string) string
- func LAN(ip netip.Addr) bool
- func ParsePlexDirectHost(host string) (ip net.IP, hash string, ok bool)
- func ParseProxyEntry(raw string) (netip.Prefix, error)
- func ProxyPrefixes(cidrs []string) []netip.Prefix
- func RedirectPath(forwardedPrefix, mountPrefix, targetPath string) string
- func SanitizeHost(host string) string
- func SanitizePrefix(raw string) string
- func TrustedPeer(r *http.Request, trusted ...netip.Prefix) bool
- type RequestOrigin
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ClientNet ¶
ClientNet classifies the peer and returns its client address. Forwarding headers are trusted only from loopback or explicitly configured proxies. Malformed chains fail closed. A public hop cannot be hidden by a preceding client-supplied private address.
func ForwardedHost ¶
ForwardedHost returns the sanitized first X-Forwarded-Host entry.
func ForwardedPrefix ¶
ForwardedPrefix returns the sanitized first X-Forwarded-Prefix entry.
func ForwardedProto ¶
ForwardedProto returns the first X-Forwarded-Proto value if it is "http" or "https".
func IsPublicIP ¶
IsPublicIP reports whether ip is a globally routable unicast address.
func JoinPrefix ¶
JoinPrefix combines a reverse-proxy prefix with an Ether mount prefix without duplicating mountPrefix when forwardedPrefix already ends with it on a path segment boundary.
func ParsePlexDirectHost ¶
ParsePlexDirectHost parses "<ip-label>.<hash>.plex.direct" hosts.
func ParseProxyEntry ¶
ParseProxyEntry parses one trusted proxy IP address (treated as /32 or /128) or CIDR prefix. Wildcard ranges (0.0.0.0/0, ::/0) are rejected so any internet peer cannot spoof forwarding headers.
func ProxyPrefixes ¶
ProxyPrefixes parses configured proxy IPs and networks. Invalid entries grant no trust.
func RedirectPath ¶
RedirectPath builds a safe relative redirect Location combining any trusted X-Forwarded-Prefix, mountPrefix, and targetPath (which should start with "/").
func SanitizeHost ¶
SanitizeHost validates and trims an HTTP Host or X-Forwarded-Host value.
func SanitizePrefix ¶
SanitizePrefix validates a reverse-proxy path prefix such as "/media" or "/ether/app", stripping trailing slashes and rejecting open-redirect or traversal forms ("//evil.com", "/../x", control characters, queries).
Types ¶
type RequestOrigin ¶
type RequestOrigin struct {
Scheme string // "http" or "https"
Host string // sanitized host or host:port
Prefix string // sanitized X-Forwarded-Prefix ("" or "/foo/bar", never trailing slash)
Proxied bool // true when trusted X-Forwarded-{Proto,Host,Prefix} headers were applied
}
RequestOrigin describes the scheme, host, and optional reverse-proxy prefix a client used to reach Ether on an HTTP request.
func Origin ¶
Origin derives the client-visible origin for r. Forwarded headers (X-Forwarded-Proto, X-Forwarded-Host, X-Forwarded-Prefix) are honoured only when the direct connecting peer is loopback or within trusted.
func (RequestOrigin) BaseURL ¶
func (o RequestOrigin) BaseURL(mountPrefix string) string
BaseURL returns "scheme://host[+prefix]" without a trailing slash, combining any trusted X-Forwarded-Prefix with mountPrefix without duplicating an already-present trailing mount segment.
func (RequestOrigin) CanonicalBase ¶
func (o RequestOrigin) CanonicalBase(mountPrefix string) string
CanonicalBase returns BaseURL normalized for deduplication: lowercased host and omitted redundant default ports (:80 for http, :443 for https).
func (RequestOrigin) Hostname ¶
func (o RequestOrigin) Hostname() string
Hostname returns the host without any port or IPv6 brackets.
func (RequestOrigin) Port ¶
func (o RequestOrigin) Port() int
Port returns the explicit port carried on Host, or 0 if none was specified.