Class HttpEgressGuard

java.lang.Object
com.agentforge4j.util.net.HttpEgressGuard
All Implemented Interfaces:
OutboundEgressGuard

public final class HttpEgressGuard extends Object implements OutboundEgressGuard
Default OutboundEgressGuard: classifies a target URI as eligible only when its scheme is http/https and its host resolves entirely to public addresses. Any private, loopback, link-local, cloud-metadata (169.254.169.254), carrier-grade-NAT, unique-local, or wildcard address — or a host that cannot be resolved — yields a denied EgressCheckResult.

This is the network-safety sibling of Validate.requireWithinBase (path-traversal): a small, dependency-light primitive shared by every module that makes tool-driven outbound calls. It classifies and never enforces — it does not throw a policy exception; the denied result carries a non-secret host/reason description, never a request body, header, or secret. Callers own the reaction.

DNS-rebinding: the guard resolves the host and re-checks every resolved address immediately before the caller issues the request (resolve-and-recheck). It does not pin the resolved IP for the connection, so a host that re-resolves to a non-public address between this check and the actual connect is a known residual time-of-check/time-of-use gap; IP-pinning is a future hardening step.

allowPrivateNetworks: when constructed with true the private, loopback, link-local, and metadata classifications are lifted wholesale — a development-only escape hatch that disables the cloud-metadata-IP protection. The http/https scheme allowlist is never lifted.

  • Constructor Details

    • HttpEgressGuard

      public HttpEgressGuard(boolean allowPrivateNetworks)
      Parameters:
      allowPrivateNetworks - when true, lifts the private/loopback/link-local/metadata blocks (development only); the scheme allowlist still applies
  • Method Details