remoteip

package
v1.24.1 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrIPSpoofAttack = errors.New("ip spoofing attack detected")
)

Functions

This section is empty.

Types

type RemoteIPParser

type RemoteIPParser struct {
	// TrustedProxies is a list of IP addresses or CIDR ranges that are considered trusted proxies
	TrustedProxies []string
	// CheckIPSpoofing enables the IP spoofing check between X-Forwarded-For and Client-IP headers
	CheckIPSpoofing bool
}

RemoteIPParser extracts and validates the client's true IP address from HTTP request headers. This is a port of the Rails code: https://github.com/rails/rails/blob/v8.0.2/actionpack/lib/action_dispatch/middleware/remote_ip.rb#L109-L167

func NewRemoteIPParser

func NewRemoteIPParser(trustedProxies []string) *RemoteIPParser

NewRemoteIPParser creates a new RemoteIPParser with the list of trusted proxies. If the list is empty, it will use the default trusted proxies.

func (*RemoteIPParser) GetIP

func (p *RemoteIPParser) GetIP(r *http.Request) (string, error)

GetIP extracts the client's true IP address from the request following a similar approach to Rails' calculate_ip method.

Jump to

Keyboard shortcuts

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