PrivateNetworkGuard

SSRF guard for outbound HTTP requests whose target host is derived from untrusted input — e.g. a did:web identifier (did:web:example.com → https://example.com/...) or an OID4VP/OID4VCI request_uri / credential_offer_uri.

Such hosts are attacker-controlled by design, so before connecting the caller must reject any host that resolves to an address used to reach the local machine, the internal network, or a cloud metadata endpoint (e.g. 169.254.169.254). This guard is the deny-list of those ranges.

It does NOT defend against DNS rebinding or redirect-to-internal on its own — for those the host must be re-checked on each connection hop (e.g. via an HTTP-client DNS interceptor). It is the mandatory pre-flight check on the initial, untrusted host.

Functions

Link copied to clipboard

True if address falls in a range that an outbound request to a public endpoint must never target: loopback, wildcard/any-local, link-local (incl. the 169.254.169.254 cloud-metadata IP and IPv6 fe80::/10), private/site-local (10/8, 172.16/12, 192.168/16), multicast, IPv6 unique-local (fc00::/7), IPv4 ranges that are not publicly routable (0/8, CGNAT 100.64/10, 192.0.0/24, 198.18/15, 240/4), and IPv6 forms that embed an IPv4 address (IPv4-compatible, NAT64 64:ff9b::/96, 6to4 2002::/16), judged by the embedded address.

Link copied to clipboard

Resolves host and returns a human-readable rejection reason if it is disallowed or cannot be resolved, or null if every resolved address is a permitted public address.