Class OutboundUriPolicy

java.lang.Object
com.revetsec.OutboundUriPolicy

@Immutable public final class OutboundUriPolicy extends Object
Decides which URIs Revetsec may send requests to.

Revetsec applies the policy to every URI it is about to fetch, such as an issuer, a JSON Web Key Set and every endpoint named in remote metadata, before any request is sent. There are two presets: defaultInstance(), which rejects the addresses and names it knows to reach a machine's own metadata or configuration services, and publicAddressesOnlyInstance(), which also rejects the local, private-use and special-use addresses and names it lists. Neither list is exhaustive.

Hostnames are never resolved. The policy looks only at the text of the URI. It classifies IP address literals, including the all-digit form (https://2852039166/ is 169.254.169.254), and IPv4 addresses embedded in IPv4-mapped, IPv4-compatible, IPv4-translated and NAT64 IPv6 addresses, and it recognizes special-use and private-use names by their text, folding ASCII letters only and ignoring one trailing dot. A URI whose host URI cannot parse, including the short dotted forms https://127.1/ and https://169.254.43518/ that InetAddress would accept, has no host and is rejected.

The policy cannot see where a DNS name points, so no policy stops a hostname that resolves to a private or metadata address, or a name whose DNS answer changes between checks (DNS rebinding). A network-specific NAT64 prefix and an explicit address mapping (RFC 7757) look like ordinary IPv6 addresses, so the policy cannot tell where they lead either. When the URIs come from someone you do not control, such as a tenant-supplied issuer, send Revetsec's traffic through an egress proxy that enforces the destinations you allow, by configuring it on the HttpClient you give Revetsec.

Since:
1.0.0
Author:
Mark Allen
  • Method Details

    • defaultInstance

      Returns the default policy.

      It permits an absolute https or http URI whose host is a DNS name or an IP address literal, except:

      • a link-local literal: 169.254.0.0/16, which includes the common cloud metadata address 169.254.169.254, and fe80::/10;
      • an any-local literal: 0.0.0.0/8 (so https://0/ is rejected) and ::;
      • the known cloud metadata endpoints as of 2026-09-27: the addresses 100.100.100.200 (Alibaba Cloud), 168.63.129.16 (Azure WireServer), fd00:ec2::254 (Amazon EC2), fd00:ec2::23 (Amazon EKS Pod Identity) and fd20:ce::254 (Google Compute Engine, over IPv6), and Google Compute Engine's names metadata.google.internal and metadata.goog and every name under them. The list is not exhaustive;
      • any address in the RFC 8215 local-use NAT64 prefix 64:ff9b:1::/48;
      • an IPv4-mapped, IPv4-compatible, IPv4-translated or NAT64 Well-Known Prefix IPv6 literal around one of the IPv4 addresses above.
      It also rejects a URI with no parseable host; a host that looks numeric but is not a well-formed address literal, such as 0xa9fea9fe or 0251.254.169.254, which the JDK refuses by default but passes to the platform resolver when jdk.net.allowAmbiguousIPAddressLiterals is true, and which a proxy or resolver that uses inet_aton reads as 169.254.169.254; and an IPv6 literal with a zone ID.

      Loopback, private, shared (carrier-grade NAT), unique local, 6to4, Teredo, multicast, reserved and other non-global addresses are permitted, and so are localhost and other local names. Revetsec's HTTP layer separately requires https, except that a builder may explicitly allow plain http for tests, to a loopback literal or exactly localhost only.

      Returns:
      the default policy; always the same instance
      Since:
      1.0.0
    • publicAddressesOnlyInstance

      Returns the policy that permits only globally reachable destinations, as far as the URI's text shows.

      It permits an absolute https or http URI whose host is either:

      • an IPv4 literal outside the blocks listed below, or an IPv4-mapped (::ffff:0:0/96) or NAT64 Well-Known Prefix (64:ff9b::/96) IPv6 literal around one. IPv4 is checked against a list, so a block that IANA marks as not globally reachable after 2026-09-27 is permitted until Revetsec lists it;
      • an IPv6 literal in the global unicast block 2000::/3, except 2001::/23 as a whole (which includes Teredo, 2001::/32), 6to4 (2002::/16) and the documentation blocks 2001:db8::/32 and 3fff::/20. Everything outside 2000::/3 is rejected, so an IPv6 block allocated for a special purpose in the future is rejected too;
      • a DNS name of at least two labels that is none of the names listed below. Other special-use names, such as example.com, are permitted.
      On top of everything defaultInstance() rejects, it therefore rejects:
      • loopback, in every form (127.0.0.0/8, ::1 and the IPv6 forms around a loopback IPv4 address);
      • the private-use blocks 10.0.0.0/8, 172.16.0.0/12 and 192.168.0.0/16, the shared address space 100.64.0.0/10 and unique local addresses (fc00::/7);
      • the IPv4 blocks that IANA's special-purpose registry marked as not globally reachable as of 2026-09-27, such as the documentation and benchmarking blocks, and the deprecated 6to4 relay anycast block 192.88.99.0/24;
      • multicast and reserved space: 224.0.0.0/4, 240.0.0.0/4, 255.255.255.255 and ff00::/8;
      • 6to4 and Teredo as a whole: the IPv4 address inside them is a tunnel endpoint, not the destination;
      • IPv4-compatible (::/96) and IPv4-translated (::ffff:0:0:0/96) literals, whatever the IPv4 address inside;
      • the names localhost and every name under it, every single-label name (which a resolver may complete with its search domains), and local, internal, test, invalid, example, onion and alt and every name under them;
      • arpa, the domain reserved for Internet infrastructure (RFC 3172), and every name under it, such as home.arpa, the other special-use names there (service.arpa, ipv4only.arpa, resolver.arpa and others) and the reverse-mapping zones in-addr.arpa and ip6.arpa.
      A name is matched in any ASCII case, with or without one trailing dot, and a suffix only on a label boundary: idp.internal. is rejected, idp.evilinternal is not.

      This policy does not resolve names either, so a public name that points at a private address still passes; see OutboundUriPolicy. An identity provider reached through a private DNS zone, such as a name under .internal, needs defaultInstance() and, where the URIs are not your own, an egress proxy.

      Returns:
      the public-addresses-only policy; always the same instance
      Since:
      1.0.0
    • permits

      Returns whether this policy permits a request to uri.

      The URI must be absolute, with the scheme https or http in any case and a host that URI.getHost() can parse; a URI without one, such as https://127.1/ (whose host URI cannot parse), is rejected. The host is never resolved. The port, path, query and user information are not examined.

      Parameters:
      uri - the URI Revetsec is about to send a request to
      Returns:
      true if the policy permits the request
      Throws:
      NullPointerException - if uri is null
      Since:
      1.0.0
    • toString

      Returns a description of this policy.
      Overrides:
      toString in class Object
      Returns:
      a description of this policy
      Since:
      1.0.0