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

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


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

commit ab4f0d5ec64421ccca91435c4afabdbeba0ee03b
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 cf82f3e7d9..840e641be9 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 java.security.AccessController;
 import java.security.PrivilegedActionException;
 import java.security.PrivilegedExceptionAction;
@@ -45,6 +46,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;
@@ -469,7 +471,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);
             }
@@ -806,9 +808,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 858a74b1d0..546c1e2d3c 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -231,6 +231,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