struct Amber::Support::TrustedProxyNetwork

Overview

One entry of the server.trusted_proxies setting: a single IP address or a CIDR block, such as "127.0.0.1", "10.0.0.0/8", or "fd00::/8".

Addresses are compared as 128-bit values. IPv4 addresses and blocks are mapped into ::ffff:0:0/96, so a peer that reaches a dual-stack listener as ::ffff:127.0.0.1 still matches the block 127.0.0.0/8.

network = Amber::Support::TrustedProxyNetwork.parse("10.0.0.0/8")
network.includes?(Socket::IPAddress.new("10.1.2.3", 0))    # => true
network.includes?(Socket::IPAddress.new("192.168.0.1", 0)) # => false

Defined in:

amber/support/trusted_proxy_network.cr

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.parse(notation : String) : self #

Parses notation into a network, raising Amber::Exceptions::ConfigurationError when it is not an IP address or CIDR block.


[View source]

Class Method Detail

def self.parse?(notation : String) : self | Nil #

Parses notation into a network, returning nil when it is not an IP address or CIDR block.


[View source]
def self.read_only_slice(list_of_networks : Array(TrustedProxyNetwork)) : Slice(TrustedProxyNetwork) #

Copies list_of_networks into a slice that raises on any write.


[View source]

Instance Method Detail

def covers_every_address? : Bool #

Returns true when this network covers every IPv4 address or every IPv6 address, as 0.0.0.0/0, ::/0 and ::/80 do. Such an entry would make every client a trusted proxy.


[View source]
def includes?(address : Socket::Address) : Bool #

Returns true when address falls inside this network. Peers that are not IP sockets (for example UNIX sockets) never match.


[View source]
def notation : String #

The entry as it was written in the configuration.


[View source]