Help us shape the future of Go! Take the 2026 Go Developer Survey

clientip

package
v0.40.22 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package clientip decides which address a request really came from.

Rivolt sits behind Cloudflare and an in-cluster load balancer, so the connection's peer address is the balancer (a 10.42.x.x pod address), the same for every visitor. The visitor's address arrives in CF-Connecting-IP, which is only believable when the connection came from a proxy we trust: a private-range address (our own balancer; it masquerades, so Cloudflare's edge is never the direct peer) or a Cloudflare edge address. From anyone else every forwarding header is ignored, so a client cannot choose its own rate-limit bucket, logged address or session address by sending CF-Connecting-IP, X-Forwarded-For, X-Real-IP or True-Client-IP.

Middleware replaces chi's RealIP, which trusted those headers from anyone.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Middleware

func Middleware(next http.Handler) http.Handler

Middleware sets r.RemoteAddr to the real client address ("ip:port" form, port taken from the connection) and keeps the connection's own peer address in the context (see Peer).

func Peer

func Peer(r *http.Request) string

Peer is the address of the connection itself (the proxy that connected), whatever Middleware rewrote RemoteAddr to. Trust decisions about the proxy (for example the trusted-proxy SSO headers) must use this, not RemoteAddr.

func Resolve

func Resolve(peer, cfConnectingIP string) (ip string, ok bool)

Resolve returns the client address for a connection from peer ("ip:port" or a bare IP) carrying the given CF-Connecting-IP value. ok is false when the peer is not a trusted proxy or the header is not a valid address: the caller keeps the peer.

Types

This section is empty.

Jump to

Keyboard shortcuts

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