Expand description
Outbound address policy: address classification and the SSRF guard behind every
crate::Client and [crate::AsyncClient] request.
The classification mirrors rightkit-browser’s policy.rs (classify_ip,
AddressClass) with the same semantics, so a browser page and an HTTP call reach the
same verdict for the same address. A test cross-checks the two tables.
How the guard works:
- The host of the request URL (and of every redirect hop) is resolved once, by this crate’s resolver. Each resolved address is classified. One denied address denies the whole host.
- Only the vetted addresses are handed to the connector, so the socket opens to an address that was checked. There is no second lookup between check and connect.
- Names that resolve to no address are denied.
Default (public-web) policy denies loopback, RFC 1918, link-local (including
169.254.169.254), CGNAT 100.64/10, multicast, reserved, unspecified and broadcast
addresses, IPv6 ULA fc00::/7 and link-local fe80::/10, and IPv6 forms that embed an
IPv4 address (mapped, compatible, NAT64 64:ff9b::/96, 6to4 2002::/16) by the class of
the embedded IPv4 address. Link-local and cloud-metadata destinations cannot be allowed
by any hook.
Structs§
- Address
Denial - Why an address or host was refused. Converts to
crate::HttpError::AddressDenied. - Address
Policy - Outbound address policy carried by
crate::ClientConfig::address_policy. - IpNet
- A CIDR range such as
10.0.0.0/8orfd00::/8. - Parse
IpNet Error IpNettext or prefix length was invalid.- Parsed
Host Ip - A host string that is an IP address, as parsed by
parse_host_ip.
Enums§
- Address
Class - Address class of a destination. Everything except
Publicis denied by default. - Host
IpKind - How a host string spelled an IP address.
Functions§
- classify_
ip - Classify one address. IPv6 forms that embed an IPv4 address take the embedded class.
- embedded_
v4 - The IPv4 address embedded in an IPv6 address (see
embedded_v4s): the first non-public one when several layouts are possible, otherwise the first. - embedded_
v4s - Every IPv4 address an IPv6 address can embed: IPv4-mapped
::ffff:a.b.c.d, the deprecated IPv4-compatible::a.b.c.d, NAT6464:ff9b::/96, 6to42002::/16, and the local-use NAT64 space64:ff9b:1::/48(RFC 8215). The local-use prefix may be deployed at several lengths (RFC 6052 section 2.2), so each of the /48, /56, /64 and /96 layouts is returned.::,::1and non-embedding addresses return nothing. - parse_
host_ ip - Parse a host string as an IP address the way
inet_atonand system resolvers do, and say how it was spelled. The input is a host as it appears in a URL: ASCII case does not matter, IPv6 may be bracketed, and one trailing dot is allowed (and makes an IPv4 spelling non-canonical). - parse_
legacy_ ipv4 - Parse an IPv4 address with the
inet_atonrules described atparse_host_ip. This accepts every spelling, canonical or not, and does not accept a trailing dot, brackets or IPv6; useparse_host_ipwhen the spelling matters.