This is an automated email from the ASF dual-hosted git repository. markt-asf pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/tomcat.git
commit f0ad0912174e144d295ae53230b543b27ab04e7a Author: Mark Thomas <[email protected]> AuthorDate: Thu Jun 4 14:46:04 2026 +0100 Improve the detection of cross-context dispatches --- java/org/apache/catalina/core/ApplicationDispatcher.java | 9 ++++++--- webapps/docs/changelog.xml | 4 ++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/java/org/apache/catalina/core/ApplicationDispatcher.java b/java/org/apache/catalina/core/ApplicationDispatcher.java index 2dc17975a9..5c257619e6 100644 --- a/java/org/apache/catalina/core/ApplicationDispatcher.java +++ b/java/org/apache/catalina/core/ApplicationDispatcher.java @@ -18,6 +18,7 @@ package org.apache.catalina.core; import java.io.IOException; import java.io.PrintWriter; +import java.nio.charset.StandardCharsets; import jakarta.servlet.AsyncContext; import jakarta.servlet.DispatcherType; @@ -42,6 +43,7 @@ import org.apache.catalina.connector.Request; import org.apache.catalina.connector.RequestFacade; import org.apache.catalina.connector.Response; import org.apache.catalina.connector.ResponseFacade; +import org.apache.catalina.util.URLEncoder; import org.apache.coyote.BadRequestException; import org.apache.coyote.CloseNowException; import org.apache.tomcat.util.ExceptionUtils; @@ -384,7 +386,7 @@ final class ApplicationDispatcher implements AsyncDispatcher, RequestDispatcher } else { // Handle an HTTP path based include - String contextPath = context.getPath(); + String contextPath = context.getEncodedPath(); if (requestURI != null) { wrequest.setAttribute(INCLUDE_REQUEST_URI, requestURI); } @@ -698,9 +700,10 @@ final class ApplicationDispatcher implements AsyncDispatcher, RequestDispatcher Object contextPath = houterRequest.getAttribute(INCLUDE_CONTEXT_PATH); if (contextPath == null) { // Forward - contextPath = houterRequest.getContextPath(); + contextPath = URLEncoder.DEFAULT.encode(houterRequest.getServletContext().getContextPath(), + StandardCharsets.UTF_8); } - crossContext = !context.getPath().equals(contextPath); + crossContext = !context.getEncodedPath().equals(contextPath); } wrapper = new ApplicationHttpRequest(hcurrent, context, crossContext); } else { diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index 56b590c57b..ad3a1c5fb3 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -338,6 +338,10 @@ <bug>70048</bug>: Correctly handle asynchronous requests in <code>PersistentValve</code>. (markt) </fix> + <fix> + Improve the detection of cross-context dispatches when using a + <code>RequestDispatcher</code>. (markt) + </fix> </changelog> </subsection> <subsection name="Coyote"> --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
