From 6abe91f9fd3bf6884332201c06b7dcb0c439e431 Mon Sep 17 00:00:00 2001 From: Adam Rauch Date: Fri, 13 Nov 2026 15:02:31 -0800 Subject: [PATCH 1/5] GH Issue 1813: Rename getBaseServerURL to getBaseServerURLWithContextPath Also build full URLs with getURIString() instead of concatenating getBaseServerURI(), and make URLHelper.isSameOrigin() public. --- .../announcements/model/AnnouncementDigestProvider.java | 2 +- .../org/labkey/announcements/model/AnnouncementManager.java | 2 +- announcements/src/org/labkey/announcements/rss.jsp | 2 +- api/src/org/labkey/api/util/ExceptionUtil.java | 2 +- api/src/org/labkey/api/util/URLHelper.java | 3 ++- .../org/labkey/api/util/emailTemplate/EmailTemplate.java | 2 +- api/src/org/labkey/api/view/ActionURL.java | 6 +++--- core/src/org/labkey/core/login/LoginController.java | 2 +- .../labkey/core/notification/NotificationServiceImpl.java | 2 +- core/src/org/labkey/core/view/styleGuide.jsp | 2 +- .../src/org/labkey/filecontent/view/fileDigestNotify.jsp | 2 +- study/src/org/labkey/study/view/sendParticipantGroup.jsp | 2 +- 12 files changed, 15 insertions(+), 14 deletions(-) diff --git a/announcements/src/org/labkey/announcements/model/AnnouncementDigestProvider.java b/announcements/src/org/labkey/announcements/model/AnnouncementDigestProvider.java index 31c814e3d3f..bc8a1506aeb 100644 --- a/announcements/src/org/labkey/announcements/model/AnnouncementDigestProvider.java +++ b/announcements/src/org/labkey/announcements/model/AnnouncementDigestProvider.java @@ -324,7 +324,7 @@ public DailyDigestBean(Container c, User recipient, Settings settings, Permissio this.announcementModels = announcementModels; this.boardPath = c.getPath(); this.boardURL = AnnouncementsController.getBeginURL(c); - this.siteUrl = ActionURL.getBaseServerURL(); + this.siteUrl = ActionURL.getBaseServerURLWithContextPath(); this.removeURL = new ActionURL(AnnouncementsController.EmailPreferencesAction.class, c); this.includeGroups = perm.includeGroups(); } diff --git a/announcements/src/org/labkey/announcements/model/AnnouncementManager.java b/announcements/src/org/labkey/announcements/model/AnnouncementManager.java index ff6394a293d..b4db2ecc599 100644 --- a/announcements/src/org/labkey/announcements/model/AnnouncementManager.java +++ b/announcements/src/org/labkey/announcements/model/AnnouncementManager.java @@ -1393,7 +1393,7 @@ public EmailNotificationBean(Container c, this.threadParentURL = AnnouncementsController.getThreadURL(c, recipient, parent); this.boardPath = c.getPath(); this.boardURL = AnnouncementsController.getBeginURL(c); - this.siteURL = ActionURL.getBaseServerURL(); + this.siteURL = ActionURL.getBaseServerURLWithContextPath(); this.announcementModel = a; this.parentModel = parent; this.isResponse = isResponse; diff --git a/announcements/src/org/labkey/announcements/rss.jsp b/announcements/src/org/labkey/announcements/rss.jsp index db9096de5e2..7783086096d 100644 --- a/announcements/src/org/labkey/announcements/rss.jsp +++ b/announcements/src/org/labkey/announcements/rss.jsp @@ -29,7 +29,7 @@ <%=h(laf.getShortName())%>: <%=h(laf.getDescription())%> - <%=h(ActionURL.getBaseServerURL())%> + <%=h(ActionURL.getBaseServerURLWithContextPath())%> <%=h(laf.getShortName())%>: <%=h(laf.getDescription())%> <% for (AnnouncementModel ann : bean.announcementModels) diff --git a/api/src/org/labkey/api/util/ExceptionUtil.java b/api/src/org/labkey/api/util/ExceptionUtil.java index 1d43f616286..818e2d16b8e 100644 --- a/api/src/org/labkey/api/util/ExceptionUtil.java +++ b/api/src/org/labkey/api/util/ExceptionUtil.java @@ -1300,7 +1300,7 @@ private static void renderErrorPage(Throwable ex, int responseStatus, String mes if (errorView == null) { // context can be null for configuration exceptions depending on how far server got through initialization - errorView = PageConfig.Template.Body.getTemplate(new ViewContext(request, response, new ActionURL(ActionURL.getBaseServerURL())), new ErrorView(renderer), pageConfig); + errorView = PageConfig.Template.Body.getTemplate(new ViewContext(request, response, new ActionURL(ActionURL.getBaseServerURLWithContextPath())), new ErrorView(renderer), pageConfig); } addDependenciesAndRender(responseStatus, pageConfig, errorView, ex, request, response); diff --git a/api/src/org/labkey/api/util/URLHelper.java b/api/src/org/labkey/api/util/URLHelper.java index c5aa9161780..a0de313be27 100644 --- a/api/src/org/labkey/api/util/URLHelper.java +++ b/api/src/org/labkey/api/util/URLHelper.java @@ -189,7 +189,7 @@ public boolean isLocalUri(ViewContext currentContext) } // Scheme check is here for test SAML redirect, which is to the same host ("localhost") but a different scheme - private boolean isSameOrigin(URLHelper other) + public boolean isSameOrigin(URLHelper other) { return getHost().equalsIgnoreCase(other.getHost()) && getScheme().equalsIgnoreCase(other.getScheme()) && getEffectivePort() == other.getEffectivePort(); } @@ -223,6 +223,7 @@ public String getURIString(boolean allowSubstSyntax) } + /** Scheme, host, and port only; no context path. Use getURIString() for a full URL. */ public String getBaseServerURI() { return getBaseServer(getScheme(), getHost(), getPort()).toString(); diff --git a/api/src/org/labkey/api/util/emailTemplate/EmailTemplate.java b/api/src/org/labkey/api/util/emailTemplate/EmailTemplate.java index 3865d6b8736..cbf8f28a7f7 100644 --- a/api/src/org/labkey/api/util/emailTemplate/EmailTemplate.java +++ b/api/src/org/labkey/api/util/emailTemplate/EmailTemplate.java @@ -159,7 +159,7 @@ public boolean isEditableIn(Container c) replacements.add("folderName", String.class, "Name of the folder that generated the email, if it is scoped to a folder", ContentType.Plain, c -> c.isRoot() ? null : c.getName()); replacements.add("folderPath", String.class, "Full path of the folder that generated the email, if it is scoped to a folder", ContentType.Plain, c -> c.isRoot() ? null : c.getPath()); replacements.add("folderURL", String.class, "URL to the folder that generated the email, if it is scoped to a folder", ContentType.Plain, c -> c.isRoot() ? null : PageFlowUtil.urlProvider(ProjectUrls.class).getStartURL(c).getURIString()); - replacements.add("homePageURL", String.class, "The home page of this installation", ContentType.Plain, c -> ActionURL.getBaseServerURL()); // TODO: Use AppProps.getHomePageUrl() instead? + replacements.add("homePageURL", String.class, "The home page of this installation", ContentType.Plain, c -> ActionURL.getBaseServerURLWithContextPath()); // TODO: Use AppProps.getHomePageUrl() instead? } public EmailTemplate(@NotNull String name, String description, String subject, String body, @NotNull ContentType contentType, Scope scope) diff --git a/api/src/org/labkey/api/view/ActionURL.java b/api/src/org/labkey/api/view/ActionURL.java index 4bf9155f4b7..c97dfb1e1be 100644 --- a/api/src/org/labkey/api/view/ActionURL.java +++ b/api/src/org/labkey/api/view/ActionURL.java @@ -141,17 +141,17 @@ public String getHost() return super.getHost(); } - private static String getBaseServerURL(String scheme, String host, int port) + private static String getBaseServerURLWithContextPath(String scheme, String host, int port) { StringBuilder sb = getBaseServer(scheme, host, port); sb.append(AppProps.getInstance().getContextPath()); return sb.toString(); } - public static String getBaseServerURL() + public static String getBaseServerURLWithContextPath() { AppProps props = AppProps.getInstance(); - return getBaseServerURL(props.getScheme(), props.getServerName(), props.getServerPort()); + return getBaseServerURLWithContextPath(props.getScheme(), props.getServerName(), props.getServerPort()); } diff --git a/core/src/org/labkey/core/login/LoginController.java b/core/src/org/labkey/core/login/LoginController.java index a2724985e76..e9a4809cc14 100644 --- a/core/src/org/labkey/core/login/LoginController.java +++ b/core/src/org/labkey/core/login/LoginController.java @@ -972,7 +972,7 @@ private Pair resetPasswordResponse(User user, @Nullable String LookAndFeelProperties laf = LookAndFeelProperties.getInstance(c); Message msg = MailHelper.createMessage(laf.getSystemEmailAddress(), user.getEmail()); msg.setSubject(laf.getShortName() + " Password Reset Attempt Failed"); - msg.setText(failureEmailMessage + "\n\nThe " + laf.getCompanyName() + " " + laf.getShortName() + " home page is " + ActionURL.getBaseServerURL() + "."); + msg.setText(failureEmailMessage + "\n\nThe " + laf.getCompanyName() + " " + laf.getShortName() + " home page is " + ActionURL.getBaseServerURLWithContextPath() + "."); MailHelper.send(msg, user, c); } catch (MessagingException e) diff --git a/core/src/org/labkey/core/notification/NotificationServiceImpl.java b/core/src/org/labkey/core/notification/NotificationServiceImpl.java index 467ab76c53b..05f50f4767d 100644 --- a/core/src/org/labkey/core/notification/NotificationServiceImpl.java +++ b/core/src/org/labkey/core/notification/NotificationServiceImpl.java @@ -145,7 +145,7 @@ public Notification sendMessageForRecipient(Container c, User createdByUser, Use { if (recipient != null) { - String fullUrlStr = linkUrl.getBaseServerURI() + linkUrl; + String fullUrlStr = linkUrl.getURIString(); // create the notification message email MailHelper.MultipartMessage m = MailHelper.createMultipartMessage(); diff --git a/core/src/org/labkey/core/view/styleGuide.jsp b/core/src/org/labkey/core/view/styleGuide.jsp index f1c892620fd..5c5c3bcf031 100644 --- a/core/src/org/labkey/core/view/styleGuide.jsp +++ b/core/src/org/labkey/core/view/styleGuide.jsp @@ -278,7 +278,7 @@

Context Content

- <% HtmlString helpText = DOM.createHtmlFragment("Go to home: ", DOM.A(DOM.at(DOM.Attribute.href, ActionURL.getBaseServerURL()), "Server Home")); %> + <% HtmlString helpText = DOM.createHtmlFragment("Go to home: ", DOM.A(DOM.at(DOM.Attribute.href, ActionURL.getBaseServerURLWithContextPath()), "Server Home")); %> diff --git a/filecontent/src/org/labkey/filecontent/view/fileDigestNotify.jsp b/filecontent/src/org/labkey/filecontent/view/fileDigestNotify.jsp index 8e2759c566e..1d973c56ee2 100644 --- a/filecontent/src/org/labkey/filecontent/view/fileDigestNotify.jsp +++ b/filecontent/src/org/labkey/filecontent/view/fileDigestNotify.jsp @@ -42,7 +42,7 @@ %> - + <%=PageFlowUtil.getStylesheetIncludes(form.getContainer()) %> diff --git a/study/src/org/labkey/study/view/sendParticipantGroup.jsp b/study/src/org/labkey/study/view/sendParticipantGroup.jsp index 0bd115c1bca..39119660fb8 100644 --- a/study/src/org/labkey/study/view/sendParticipantGroup.jsp +++ b/study/src/org/labkey/study/view/sendParticipantGroup.jsp @@ -72,7 +72,7 @@

Message link: -
<%=h(sendGroupUrl.getBaseServerURI() + PageFlowUtil.decode(sendGroupUrl.toString()))%>
+
<%=h(PageFlowUtil.decode(sendGroupUrl.getURIString()))%>

From b735b8ee54223b94c1969b39695e42eeddf7d4b1 Mon Sep 17 00:00:00 2001 From: Adam Rauch Date: Fri, 13 Nov 2026 15:47:12 -0800 Subject: [PATCH 2/5] GH Issue 1813: Use the full URL in plain-text notification emails Also make URLHelper.isSameOrigin() private again now that TargetedMS no longer uses it. --- api/src/org/labkey/api/util/URLHelper.java | 2 +- .../org/labkey/core/notification/NotificationServiceImpl.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/api/src/org/labkey/api/util/URLHelper.java b/api/src/org/labkey/api/util/URLHelper.java index a0de313be27..2adf59f8646 100644 --- a/api/src/org/labkey/api/util/URLHelper.java +++ b/api/src/org/labkey/api/util/URLHelper.java @@ -189,7 +189,7 @@ public boolean isLocalUri(ViewContext currentContext) } // Scheme check is here for test SAML redirect, which is to the same host ("localhost") but a different scheme - public boolean isSameOrigin(URLHelper other) + private boolean isSameOrigin(URLHelper other) { return getHost().equalsIgnoreCase(other.getHost()) && getScheme().equalsIgnoreCase(other.getScheme()) && getEffectivePort() == other.getEffectivePort(); } diff --git a/core/src/org/labkey/core/notification/NotificationServiceImpl.java b/core/src/org/labkey/core/notification/NotificationServiceImpl.java index 05f50f4767d..1e7aa9eba56 100644 --- a/core/src/org/labkey/core/notification/NotificationServiceImpl.java +++ b/core/src/org/labkey/core/notification/NotificationServiceImpl.java @@ -152,7 +152,7 @@ public Notification sendMessageForRecipient(Container c, User createdByUser, Use m.setFrom(LookAndFeelProperties.getInstance(c).getSystemEmailAddress()); m.addRecipients(Message.RecipientType.TO, recipient.getEmail()); m.setSubject(subject); - m.setTextContent(body + "\n" + linkUrl); + m.setTextContent(body + "\n" + fullUrlStr); // replicate the message body as html with an tag String html = "" + From 97ce40f2b524886d704ff555997be521e6d8c926 Mon Sep 17 00:00:00 2001 From: Adam Rauch Date: Fri, 13 Nov 2026 16:02:58 -0800 Subject: [PATCH 3/5] GH Issue 1813: Fold the private getBaseServerURLWithContextPath overload into its caller --- api/src/org/labkey/api/view/ActionURL.java | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/api/src/org/labkey/api/view/ActionURL.java b/api/src/org/labkey/api/view/ActionURL.java index c97dfb1e1be..fd45b706ae5 100644 --- a/api/src/org/labkey/api/view/ActionURL.java +++ b/api/src/org/labkey/api/view/ActionURL.java @@ -141,20 +141,14 @@ public String getHost() return super.getHost(); } - private static String getBaseServerURLWithContextPath(String scheme, String host, int port) - { - StringBuilder sb = getBaseServer(scheme, host, port); - sb.append(AppProps.getInstance().getContextPath()); - return sb.toString(); - } - public static String getBaseServerURLWithContextPath() { AppProps props = AppProps.getInstance(); - return getBaseServerURLWithContextPath(props.getScheme(), props.getServerName(), props.getServerPort()); + return getBaseServer(props.getScheme(), props.getServerName(), props.getServerPort()) + .append(props.getContextPath()) + .toString(); } - public ActionURL() { this(true); From f339640d9a9c473a9b9fc99dd5c09eae1c767b69 Mon Sep 17 00:00:00 2001 From: Adam Rauch Date: Fri, 13 Nov 2026 16:17:11 -0800 Subject: [PATCH 4/5] GH Issue 1813: Render the fallback error page with the existing view context The fabricated context's ActionURL only fed a container lookup that AppTemplate discards. --- api/src/org/labkey/api/util/ExceptionUtil.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/api/src/org/labkey/api/util/ExceptionUtil.java b/api/src/org/labkey/api/util/ExceptionUtil.java index 818e2d16b8e..a26402a2826 100644 --- a/api/src/org/labkey/api/util/ExceptionUtil.java +++ b/api/src/org/labkey/api/util/ExceptionUtil.java @@ -1299,8 +1299,7 @@ private static void renderErrorPage(Throwable ex, int responseStatus, String mes if (errorView == null) { - // context can be null for configuration exceptions depending on how far server got through initialization - errorView = PageConfig.Template.Body.getTemplate(new ViewContext(request, response, new ActionURL(ActionURL.getBaseServerURLWithContextPath())), new ErrorView(renderer), pageConfig); + errorView = PageConfig.Template.Body.getTemplate(context, new ErrorView(renderer), pageConfig); } addDependenciesAndRender(responseStatus, pageConfig, errorView, ex, request, response); From 876115a3ab945497601c2b4dbdfb4bbda974d22c Mon Sep 17 00:00:00 2001 From: Adam Rauch Date: Sat, 14 Nov 2026 09:44:58 -0800 Subject: [PATCH 5/5] GH Issue 1813: Escape and stop decoding notification links HTML-escape the link in notification emails and show the participant group link exactly as it is sent. --- .../org/labkey/core/notification/NotificationServiceImpl.java | 2 +- study/src/org/labkey/study/view/sendParticipantGroup.jsp | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/core/src/org/labkey/core/notification/NotificationServiceImpl.java b/core/src/org/labkey/core/notification/NotificationServiceImpl.java index 1e7aa9eba56..5e03faf548f 100644 --- a/core/src/org/labkey/core/notification/NotificationServiceImpl.java +++ b/core/src/org/labkey/core/notification/NotificationServiceImpl.java @@ -157,7 +157,7 @@ public Notification sendMessageForRecipient(Container c, User createdByUser, Use // replicate the message body as html with an tag String html = "" + PageFlowUtil.filter(body, true, true) + - "
" + fullUrlStr + "" + + "
" + PageFlowUtil.filter(fullUrlStr) + "" + ""; m.setEncodedHtmlContent(html); diff --git a/study/src/org/labkey/study/view/sendParticipantGroup.jsp b/study/src/org/labkey/study/view/sendParticipantGroup.jsp index 39119660fb8..93a8c3c680b 100644 --- a/study/src/org/labkey/study/view/sendParticipantGroup.jsp +++ b/study/src/org/labkey/study/view/sendParticipantGroup.jsp @@ -19,7 +19,6 @@ <%@ page import="org.labkey.api.data.Container" %> <%@ page import="org.labkey.api.security.SecurityUrls" %> <%@ page import="org.labkey.api.study.Study" %> -<%@ page import="org.labkey.api.util.PageFlowUtil" %> <%@ page import="org.labkey.api.view.ActionURL" %> <%@ page import="org.labkey.api.view.HttpView" %> <%@ page import="org.labkey.api.view.JspView" %> @@ -72,7 +71,7 @@

Message link: -
<%=h(PageFlowUtil.decode(sendGroupUrl.getURIString()))%>
+
<%=h(sendGroupUrl.getURIString())%>