Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,15 @@ public static boolean handleRedirect(final HttpServletRequest request, final Htt
if (redirect != null) {
// and redirect ensuring the response is sent to the client
try {
response.sendRedirect(redirect);
final String redirectTarget = (redirect.startsWith("/") && !redirect.contains("://")) ? redirect : "/";
response.sendRedirect(redirectTarget);
} catch (Exception e) {
// expected: IOException and IllegalStateException
final String sanitizedRedirect = sanitizeForLog(redirect);
LoggerFactory.getLogger(DefaultAuthenticationFeedbackHandler.class)
.error(
"handleRedirect: Failed to send redirect to " + redirect
+ ", aborting request without redirect",
"handleRedirect: Failed to send redirect to {}, aborting request without redirect",
sanitizedRedirect,
e);
}

Expand Down Expand Up @@ -130,14 +132,22 @@ private static String getValidatedRedirectTarget(final HttpServletRequest reques

// absolute target (in the servlet context)
if (!AuthUtil.isRedirectValid(request, redirect)) {
final String sanitizedRedirect = sanitizeForLog(redirect);
LoggerFactory.getLogger(DefaultAuthenticationFeedbackHandler.class)
.error("handleRedirect: Redirect target '{}' is invalid, redirecting to '/'", redirect);
.error("handleRedirect: Redirect target '{}' is invalid, redirecting to '/'", sanitizedRedirect);
redirect = "/";
}

return redirect;
}

private static String sanitizeForLog(final String value) {
if (value == null) {
return null;
}
return value.replace("\r", "\\r").replace("\n", "\\n");
}

/**
* This default implementation does nothing.
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,15 @@ public static boolean handleRedirect(final HttpServletRequest request, final Htt
if (redirect != null) {
// and redirect ensuring the response is sent to the client
try {
response.sendRedirect(redirect);
final String redirectTarget = (redirect.startsWith("/") && !redirect.contains("://")) ? redirect : "/";
response.sendRedirect(redirectTarget);
} catch (Exception e) {
// expected: IOException and IllegalStateException
final String sanitizedRedirect = sanitizeForLog(redirect);
LoggerFactory.getLogger(DefaultJakartaAuthenticationFeedbackHandler.class)
.error(
"handleRedirect: Failed to send redirect to " + redirect
+ ", aborting request without redirect",
"handleRedirect: Failed to send redirect to {}, aborting request without redirect",
sanitizedRedirect,
e);
}

Expand Down Expand Up @@ -130,14 +132,22 @@ private static String getValidatedRedirectTarget(final HttpServletRequest reques

// absolute target (in the servlet context)
if (!AuthUtil.isRedirectValid(request, redirect)) {
final String sanitizedRedirect = sanitizeForLog(redirect);
LoggerFactory.getLogger(DefaultJakartaAuthenticationFeedbackHandler.class)
.error("handleRedirect: Redirect target '{}' is invalid, redirecting to '/'", redirect);
.error("handleRedirect: Redirect target '{}' is invalid, redirecting to '/'", sanitizedRedirect);
redirect = "/";
}

return redirect;
}

private static String sanitizeForLog(final String value) {
if (value == null) {
return null;
}
return value.replace("\r", "\\r").replace("\n", "\\n");
}

/**
* This default implementation does nothing.
* <p>
Expand Down