From 8a2c947d3a8bdc949f320503784a8ee159302fcb Mon Sep 17 00:00:00 2001 From: Adam Rauch Date: Mon, 4 Aug 2025 13:56:07 -0700 Subject: [PATCH 1/4] Temporary logging to investigate redirect problems --- api/src/org/labkey/api/view/HttpView.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/api/src/org/labkey/api/view/HttpView.java b/api/src/org/labkey/api/view/HttpView.java index 9f42c046753..226a4165613 100644 --- a/api/src/org/labkey/api/view/HttpView.java +++ b/api/src/org/labkey/api/view/HttpView.java @@ -22,6 +22,7 @@ import jakarta.servlet.http.HttpServletResponseWrapper; import org.apache.commons.lang3.ObjectUtils; import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.labkey.api.action.HasViewContext; @@ -32,6 +33,7 @@ import org.labkey.api.util.MemTracker; import org.labkey.api.util.URLHelper; import org.labkey.api.util.UnexpectedException; +import org.labkey.api.util.logging.LogHelper; import org.labkey.api.view.template.ClientDependency; import org.labkey.api.view.template.PageConfig; import org.springframework.beans.PropertyValues; @@ -592,9 +594,12 @@ protected void renderInternal(Object model, PrintWriter out) throws IOException } } + private static final Logger LOG = LogHelper.getLogger(HttpView.class, "Info to help debug redirect problems"); + public static HttpView redirect(URLHelper url, boolean allowAbsoluteUrl) { String redirectUrl = (!allowAbsoluteUrl || url.isLocalUri(getRootContext())) ? url.getLocalURIString() : url.getURIString(); + LOG.info("Redirecting to '{}' allowAbsoluteUrl='{}' isLocalUri()={} local='{}' URI='{}'", redirectUrl, allowAbsoluteUrl, url.isLocalUri(getRootContext()), url.getLocalURIString(), url.getURIString()); return redirect(redirectUrl); } From 933d8071b4cce2c3bb7d16985ffb2fc09377bc1c Mon Sep 17 00:00:00 2001 From: Adam Rauch Date: Mon, 4 Aug 2025 20:07:22 -0700 Subject: [PATCH 2/4] Try to fix test SAML redirect --- api/src/org/labkey/api/util/URLHelper.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/api/src/org/labkey/api/util/URLHelper.java b/api/src/org/labkey/api/util/URLHelper.java index f766917f996..1a1fc4a5888 100644 --- a/api/src/org/labkey/api/util/URLHelper.java +++ b/api/src/org/labkey/api/util/URLHelper.java @@ -182,9 +182,10 @@ public static StringBuilder getBaseServer(String scheme, String host, int port) public boolean isLocalUri(ViewContext currentContext) { return getHost() == null - || currentContext == null - || currentContext.getActionURL() == null - || getHost().equalsIgnoreCase(currentContext.getActionURL().getHost()); + || currentContext == null + || currentContext.getActionURL() == null + // Scheme check is here for test SAML redirect, which is to the same host ("localhost") but a different scheme + || getHost().equalsIgnoreCase(currentContext.getActionURL().getHost()) && getScheme().equalsIgnoreCase(currentContext.getActionURL().getScheme()); } public String getURIString() From 8b5723c1b252db3d75360af893cd7d7187c96c1d Mon Sep 17 00:00:00 2001 From: Adam Rauch Date: Tue, 5 Aug 2025 08:24:44 -0700 Subject: [PATCH 3/4] Remove temporary logging --- api/src/org/labkey/api/view/HttpView.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/api/src/org/labkey/api/view/HttpView.java b/api/src/org/labkey/api/view/HttpView.java index 226a4165613..9f42c046753 100644 --- a/api/src/org/labkey/api/view/HttpView.java +++ b/api/src/org/labkey/api/view/HttpView.java @@ -22,7 +22,6 @@ import jakarta.servlet.http.HttpServletResponseWrapper; import org.apache.commons.lang3.ObjectUtils; import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.labkey.api.action.HasViewContext; @@ -33,7 +32,6 @@ import org.labkey.api.util.MemTracker; import org.labkey.api.util.URLHelper; import org.labkey.api.util.UnexpectedException; -import org.labkey.api.util.logging.LogHelper; import org.labkey.api.view.template.ClientDependency; import org.labkey.api.view.template.PageConfig; import org.springframework.beans.PropertyValues; @@ -594,12 +592,9 @@ protected void renderInternal(Object model, PrintWriter out) throws IOException } } - private static final Logger LOG = LogHelper.getLogger(HttpView.class, "Info to help debug redirect problems"); - public static HttpView redirect(URLHelper url, boolean allowAbsoluteUrl) { String redirectUrl = (!allowAbsoluteUrl || url.isLocalUri(getRootContext())) ? url.getLocalURIString() : url.getURIString(); - LOG.info("Redirecting to '{}' allowAbsoluteUrl='{}' isLocalUri()={} local='{}' URI='{}'", redirectUrl, allowAbsoluteUrl, url.isLocalUri(getRootContext()), url.getLocalURIString(), url.getURIString()); return redirect(redirectUrl); } From 1dfdcdcb47293ca535ea1b0ae41db12ceae79c99 Mon Sep 17 00:00:00 2001 From: Adam Rauch Date: Tue, 5 Aug 2025 10:47:07 -0700 Subject: [PATCH 4/4] Parens --- api/src/org/labkey/api/util/URLHelper.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/src/org/labkey/api/util/URLHelper.java b/api/src/org/labkey/api/util/URLHelper.java index 1a1fc4a5888..cff34c4d2be 100644 --- a/api/src/org/labkey/api/util/URLHelper.java +++ b/api/src/org/labkey/api/util/URLHelper.java @@ -185,7 +185,7 @@ public boolean isLocalUri(ViewContext currentContext) || currentContext == null || currentContext.getActionURL() == null // Scheme check is here for test SAML redirect, which is to the same host ("localhost") but a different scheme - || getHost().equalsIgnoreCase(currentContext.getActionURL().getHost()) && getScheme().equalsIgnoreCase(currentContext.getActionURL().getScheme()); + || (getHost().equalsIgnoreCase(currentContext.getActionURL().getHost()) && getScheme().equalsIgnoreCase(currentContext.getActionURL().getScheme())); } public String getURIString()