This is an automated email from the ASF dual-hosted git repository.

markt-asf pushed a commit to branch 11.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/11.0.x by this push:
     new a078b52409 Improve the detection of cross-context dispatches
a078b52409 is described below

commit a078b52409a1db0e5547987e4293b4e6df8e804d
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 ae3846fcc4..eebcc87f72 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -242,6 +242,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]

Reply via email to