pub fn is_loopback_host(host: &str) -> boolExpand description
Returns true if host is a loopback target: an IP literal in the loopback range
(127.0.0.0/8, ::1) or the well-known hostname localhost (case-insensitive).
Accepts IPv6 literals with or without the bracket notation used in URL authorities
(::1 and [::1] both match), since callers typically extract host from a parsed
url::Url — Url::host_str() retains the brackets, but Url::host() does not.
This is a syntactic check only — it does not perform DNS resolution, so it cannot
be spoofed by a malicious DNS response and carries no SSRF risk of its own. Callers
use it to grant loopback targets a narrow trust carve-out (e.g. allowing plain HTTP
to a local daemon) without weakening SSRF protection for any other hostname, which
still goes through resolve_and_validate.
§Examples
use zeph_common::net::is_loopback_host;
assert!(is_loopback_host("127.0.0.1"));
assert!(is_loopback_host("::1"));
assert!(is_loopback_host("[::1]"));
assert!(is_loopback_host("localhost"));
assert!(is_loopback_host("LOCALHOST"));
assert!(!is_loopback_host("example.com"));
assert!(!is_loopback_host("10.0.0.1"));