Class SsrfUrlValidator


  • public final class SsrfUrlValidator
    extends Object
    Validates that a (client-supplied) URL is safe for the server to fetch, to prevent server-side request forgery (SSRF).

    A URL is considered safe only when it uses the http or https scheme (which rules out file://, ftp://, gopher:// and similar variants) and none of the host's resolved addresses point at a loopback, wildcard, link-local (incl. cloud metadata 169.254.0.0/16), private/site-local, multicast or IPv6 unique-local address.

    This class is intentionally free of any configuration/framework dependency so it can be reused from any module; callers that need a runtime "allow any URL" escape hatch should read their own system property and short-circuit before calling isSafeRemoteUrl(String).

    • Method Detail

      • isSafeRemoteUrl

        public static boolean isSafeRemoteUrl​(String url)
        Parameters:
        url - the URL to check.
        Returns:
        true if the URL is safe for the server to fetch, false otherwise.