This is an automated email from the ASF dual-hosted git repository.
markt-asf pushed a commit to branch 10.1.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/10.1.x by this push:
new 4021d45b7c Improve the detection of cross-context dispatches
4021d45b7c is described below
commit 4021d45b7cfdecdd236582c28276b801c5ad88e7
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 1b26db8b20..c419fedd2a 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;
@@ -462,7 +464,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);
}
@@ -797,9 +799,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 5b9032ec5f..5234729643 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -235,6 +235,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]