Class UriUtils

java.lang.Object
org.keycloak.common.util.UriUtils

public class UriUtils extends Object
Author:
Stian Thorgersen
  • Constructor Details

    • UriUtils

      public UriUtils()
  • Method Details

    • getOrigin

      public static String getOrigin(URI uri)
    • getOrigin

      public static String getOrigin(String uri)
    • isOrigin

      public static boolean isOrigin(String url)
    • originEquals

      public static boolean originEquals(String originA, String originB)
    • schemeAndHostEqual

      public static boolean schemeAndHostEqual(URI uriA, URI uriB)
    • schemeHostAndPortEqual

      public static boolean schemeHostAndPortEqual(URI uriA, URI uriB)
    • rawUserInfoEqual

      public static boolean rawUserInfoEqual(URI uriA, URI uriB)
      Compare user-info case-sensitively, including registry-name authorities where URI.getRawUserInfo() is left null by Java.
    • hasExplicitPort

      public static boolean hasExplicitPort(URI uri)
      Whether the URI authority includes an explicit port separator (including an empty port). Used for port-wildcard redirect prefixes such as https://example.com:*. IPv6 literals are handled so colons inside [...] are not treated as a port.
    • isAuthoritySafeForWildcards

      public static boolean isAuthoritySafeForWildcards(URI uri)
      Whether the URI authority is safe for wildcard redirect matching.

      Allows hosts Java parses normally and RFC 3986 registry-names (e.g. underscores) that leave URI.getHost() null, while rejecting authorities with user-info or invalid ports. See CVE-2026-7504.

    • getHost

      public static String getHost(String uri)
    • parseQueryParameters

      public static MultivaluedHashMap<String,String> parseQueryParameters(String queryString, boolean decode)
    • parseQueryParameters

      public static MultivaluedHashMap<String,String> parseQueryParameters(String queryString, boolean decodeNames, boolean decodeValues)
      Parses a query string, decoding parameter names and values independently. Names are decoded while parsing so that occurrences of the same decoded name (e.g. %53AMLResponse and SAMLResponse) keep their order of appearance in the query string.
      Parameters:
      queryString - raw query string
      decodeNames - whether to URL-decode parameter names
      decodeValues - whether to URL-decode parameter values
      Returns:
      the parsed parameters
    • decodeQueryString

      public static MultivaluedHashMap<String,String> decodeQueryString(String queryString)
    • stripQueryParam

      public static String stripQueryParam(String url, String name)
    • checkUrl

      public static void checkUrl(SslRequired sslRequired, String url, String name) throws IllegalArgumentException
      Throws:
      IllegalArgumentException