Class BackUrlTokenService


  • public final class BackUrlTokenService
    extends java.lang.Object
    Builds and verifies the "back url" carried through the OIDC prompt=none round-trip (parameter bck_prompt_url).

    The back url is a request parameter that ends up in a sendRedirect, so it is a classic open-redirect sink. Instead of relying solely on SecurityUtil.isInternalRedirectUrlSafe(java.lang.String, javax.servlet.http.HttpServletRequest) (a deny-list whose robustness depends on the deployed core version and configuration), the url is wrapped in a server-signed token : base64url(url).expiry.hmacSHA256(base64url(url).expiry).

    The HMAC is computed with the application crypto key (CryptoService.hmacSHA256(String), key stored in the Datastore, therefore stable across restarts and shared across cluster nodes). Any value forged or tampered with by a client fails the signature check and is rejected, which closes the open redirect regardless of the core version. A short time-to-live bounds replay. The decoded url is still passed through SecurityUtil.isInternalRedirectUrlSafe(java.lang.String, javax.servlet.http.HttpServletRequest) as a second line of defense.

    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String buildToken​(java.lang.String strUrl)
      Build a server-signed token wrapping the given internal url, to be transported as the bck_prompt_url parameter.
      static java.lang.String verifyToken​(java.lang.String strToken, javax.servlet.http.HttpServletRequest request)
      Verify a token produced by buildToken(String) and return the internal url it carries.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • buildToken

        public static java.lang.String buildToken​(java.lang.String strUrl)
        Build a server-signed token wrapping the given internal url, to be transported as the bck_prompt_url parameter.
        Parameters:
        strUrl - the internal url to protect (server-side value)
        Returns:
        the signed token, or an empty string if the url is blank
      • verifyToken

        public static java.lang.String verifyToken​(java.lang.String strToken,
                                                   javax.servlet.http.HttpServletRequest request)
        Verify a token produced by buildToken(String) and return the internal url it carries.
        Parameters:
        strToken - the token read from the bck_prompt_url request parameter
        request - the current request (used for the SecurityUtil.isInternalRedirectUrlSafe(java.lang.String, javax.servlet.http.HttpServletRequest) second check)
        Returns:
        the verified internal url, or null if the token is missing, malformed, has an invalid signature, is expired or resolves to an unsafe url