Class BackUrlTokenService
- java.lang.Object
-
- fr.paris.lutece.plugins.mylutece.modules.oauth2.service.BackUrlTokenService
-
public final class BackUrlTokenService extends java.lang.ObjectBuilds and verifies the "back url" carried through the OIDC prompt=none round-trip (parameterbck_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 onSecurityUtil.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 throughSecurityUtil.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.StringbuildToken(java.lang.String strUrl)Build a server-signed token wrapping the given internal url, to be transported as thebck_prompt_urlparameter.static java.lang.StringverifyToken(java.lang.String strToken, javax.servlet.http.HttpServletRequest request)Verify a token produced bybuildToken(String)and return the internal url it carries.
-
-
-
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 thebck_prompt_urlparameter.- 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 bybuildToken(String)and return the internal url it carries.- Parameters:
strToken- the token read from thebck_prompt_urlrequest parameterrequest- the current request (used for theSecurityUtil.isInternalRedirectUrlSafe(java.lang.String, javax.servlet.http.HttpServletRequest)second check)- Returns:
- the verified internal url, or
nullif the token is missing, malformed, has an invalid signature, is expired or resolves to an unsafe url
-
-