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

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

commit 7e8466318799573909a03b1e9021a8a5f1a57767
Author: Dimitris Soumis <[email protected]>
AuthorDate: Tue Jun 9 14:08:39 2026 +0300

    Add showReport attribute in ProxyErrorReportValve.
---
 .../catalina/valves/ProxyErrorReportValve.java     | 27 ++++---
 .../catalina/valves/TestProxyErrorReportValve.java | 87 ++++++++++++++++++++++
 webapps/docs/config/valve.xml                      | 12 +++
 3 files changed, 114 insertions(+), 12 deletions(-)

diff --git a/java/org/apache/catalina/valves/ProxyErrorReportValve.java 
b/java/org/apache/catalina/valves/ProxyErrorReportValve.java
index a13acf9ba4..a2c34a36ac 100644
--- a/java/org/apache/catalina/valves/ProxyErrorReportValve.java
+++ b/java/org/apache/catalina/valves/ProxyErrorReportValve.java
@@ -176,8 +176,8 @@ public class ProxyErrorReportValve extends ErrorReportValve 
{
         }
         try {
             stringBuilder.append("requestUri=");
-            stringBuilder
-                    .append(URLEncoder.encode(request.getDecodedRequestURI(), 
request.getConnector().getURIEncoding()));
+            stringBuilder.append(
+                URLEncoder.encode(request.getDecodedRequestURI(), 
request.getConnector().getURIEncoding()));
             stringBuilder.append("&statusCode=");
             stringBuilder.append(URLEncoder.encode(String.valueOf(statusCode), 
"UTF-8"));
         } catch (UnsupportedEncodingException e) {
@@ -199,19 +199,22 @@ public class ProxyErrorReportValve extends 
ErrorReportValve {
             description = smClient.getString("errorReportValve.noDescription");
         }
         try {
-            stringBuilder.append("&statusDescription=");
-            stringBuilder.append(URLEncoder.encode(description, "UTF-8"));
             stringBuilder.append("&statusReason=");
             stringBuilder.append(URLEncoder.encode(reason, "UTF-8"));
 
-            String message = response.getMessage();
-            if (message != null) {
-                stringBuilder.append("&message=");
-                stringBuilder.append(URLEncoder.encode(message, "UTF-8"));
-            }
-            if (throwable != null) {
-                stringBuilder.append("&throwable=");
-                stringBuilder.append(URLEncoder.encode(throwable.toString(), 
"UTF-8"));
+            if (isShowReport()) {
+                stringBuilder.append("&statusDescription=");
+                stringBuilder.append(URLEncoder.encode(description, "UTF-8"));
+
+                String message = response.getMessage();
+                if (message != null) {
+                    stringBuilder.append("&message=");
+                    stringBuilder.append(URLEncoder.encode(message, "UTF-8"));
+                }
+                if (throwable != null) {
+                    stringBuilder.append("&throwable=");
+                    
stringBuilder.append(URLEncoder.encode(throwable.toString(), "UTF-8"));
+                }
             }
         } catch (UnsupportedEncodingException e) {
             // Ignore
diff --git a/test/org/apache/catalina/valves/TestProxyErrorReportValve.java 
b/test/org/apache/catalina/valves/TestProxyErrorReportValve.java
index ab5201199f..b4dc29ad7a 100644
--- a/test/org/apache/catalina/valves/TestProxyErrorReportValve.java
+++ b/test/org/apache/catalina/valves/TestProxyErrorReportValve.java
@@ -17,6 +17,9 @@
 package org.apache.catalina.valves;
 
 import java.io.IOException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 
 import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest;
@@ -248,6 +251,90 @@ public class TestProxyErrorReportValve extends 
TomcatBaseTest {
     }
 
 
+    @Test
+    public void testRedirectShowReportFalse() throws Exception {
+        Tomcat tomcat = getTomcatInstance();
+        StandardHost host = (StandardHost) tomcat.getHost();
+        host.setErrorReportValveClass(PROXY_VALVE);
+
+        Context ctx = getProgrammaticRootContext();
+
+        Tomcat.addServlet(ctx, "sendError", new SendErrorServlet(
+                HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Server broke"));
+        ctx.addServletMappingDecoded("/", "sendError");
+
+        Tomcat.addServlet(ctx, "errorPage", new ErrorPageServlet());
+        ctx.addServletMappingDecoded("/error-page", "errorPage");
+
+        tomcat.start();
+
+        ProxyErrorReportValve proxyErrorReportValve = null;
+        for (Valve valve : host.getPipeline().getValves()) {
+            if (valve instanceof ProxyErrorReportValve) {
+                proxyErrorReportValve = (ProxyErrorReportValve) valve;
+                break;
+            }
+        }
+        Assert.assertNotNull(proxyErrorReportValve);
+        proxyErrorReportValve.setUseRedirect(true);
+        proxyErrorReportValve.setShowReport(false);
+        proxyErrorReportValve.setProperty("errorCode." + 
HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
+                "http://localhost:"; + getPort() + "/error-page");
+
+        ByteChunk res = new ByteChunk();
+        Map<String, List<String>> resHead = new HashMap<>();
+        int rc = methodUrl("http://localhost:"; + getPort(), res,
+                DEFAULT_CLIENT_TIMEOUT_MS, null, resHead, "GET", false);
+
+        Assert.assertEquals(HttpServletResponse.SC_FOUND, rc);
+
+        List<String> locationHeader = resHead.get("Location");
+        Assert.assertNotNull(locationHeader);
+        String location = locationHeader.get(0);
+
+        Assert.assertTrue(location.contains("statusCode="));
+        Assert.assertTrue(location.contains("statusReason="));
+        Assert.assertFalse(location.contains("message="));
+        Assert.assertFalse(location.contains("throwable="));
+        Assert.assertFalse(location.contains("statusDescription="));
+    }
+
+
+    @Test
+    public void testNoErrorPageShowReportFalse() throws Exception {
+        Tomcat tomcat = getTomcatInstance();
+        StandardHost host = (StandardHost) tomcat.getHost();
+        host.setErrorReportValveClass(PROXY_VALVE);
+
+        Context ctx = getProgrammaticRootContext();
+
+        Tomcat.addServlet(ctx, "sendError", new SendErrorServlet(
+                HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Server broke"));
+        ctx.addServletMappingDecoded("/", "sendError");
+
+        tomcat.start();
+
+        ProxyErrorReportValve proxyErrorReportValve = null;
+        for (Valve valve : host.getPipeline().getValves()) {
+            if (valve instanceof ProxyErrorReportValve) {
+                proxyErrorReportValve = (ProxyErrorReportValve) valve;
+                break;
+            }
+        }
+        Assert.assertNotNull(proxyErrorReportValve);
+        proxyErrorReportValve.setShowReport(false);
+
+        ByteChunk res = new ByteChunk();
+        int rc = getUrl("http://localhost:"; + getPort(), res, null);
+
+        Assert.assertEquals(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, rc);
+
+        String body = res.toString();
+        Assert.assertNotNull(body);
+        Assert.assertFalse(body.contains("Server broke"));
+    }
+
+
     private static final class SendErrorServlet extends HttpServlet {
 
         private static final long serialVersionUID = 1L;
diff --git a/webapps/docs/config/valve.xml b/webapps/docs/config/valve.xml
index f80e14c862..94962b12ee 100644
--- a/webapps/docs/config/valve.xml
+++ b/webapps/docs/config/valve.xml
@@ -2495,6 +2495,18 @@
         value is <code>false</code>.</p>
       </attribute>
 
+      <attribute name="showReport" required="false">
+        <p>Flag to determine if the error report details (description, custom
+           error message and/or stack trace) are included in the query
+           parameters of the redirect or proxy URL when an error occurs. If
+           set to <code>false</code>, then only the status code and reason
+           phrase are included. When falling back to the default error report
+           valve (no error page configured), this flag also controls whether
+           the HTML error report includes these details.
+           Default value: <code>true</code>
+        </p>
+      </attribute>
+
       <attribute name="useRedirect" required="false">
         <p>If <code>true</code>, the valve will redirect the client to the URL
         that displays the error and the redirect will include full details of


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to