From cd4d4641f7b77e905db09cfd1761ab2997583db2 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Tue, 27 Feb 2024 15:41:20 -0600 Subject: [PATCH] Issue #11448 - improved stacktrace message for ambiguous URI --- .../jetty/ee10/servlet/ServletApiRequest.java | 9 ++++--- .../ee10/servlet/ServletContextRequest.java | 25 ++++++++++++++++--- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/jetty-ee10/jetty-ee10-servlet/src/main/java/org/eclipse/jetty/ee10/servlet/ServletApiRequest.java b/jetty-ee10/jetty-ee10-servlet/src/main/java/org/eclipse/jetty/ee10/servlet/ServletApiRequest.java index 28a6facd63e0..b0a711d0f9da 100644 --- a/jetty-ee10/jetty-ee10-servlet/src/main/java/org/eclipse/jetty/ee10/servlet/ServletApiRequest.java +++ b/jetty-ee10/jetty-ee10-servlet/src/main/java/org/eclipse/jetty/ee10/servlet/ServletApiRequest.java @@ -1307,21 +1307,24 @@ public Map getTrailerFields() static class AmbiguousURI extends ServletApiRequest { - protected AmbiguousURI(ServletContextRequest servletContextRequest) + private final String msg; + + protected AmbiguousURI(ServletContextRequest servletContextRequest, String msg) { super(servletContextRequest); + this.msg = msg; } @Override public String getPathInfo() { - throw new HttpException.IllegalArgumentException(HttpStatus.BAD_REQUEST_400, "Ambiguous URI encoding"); + throw new HttpException.IllegalArgumentException(HttpStatus.BAD_REQUEST_400, msg); } @Override public String getServletPath() { - throw new HttpException.IllegalArgumentException(HttpStatus.BAD_REQUEST_400, "Ambiguous URI encoding"); + throw new HttpException.IllegalArgumentException(HttpStatus.BAD_REQUEST_400, msg); } } diff --git a/jetty-ee10/jetty-ee10-servlet/src/main/java/org/eclipse/jetty/ee10/servlet/ServletContextRequest.java b/jetty-ee10/jetty-ee10-servlet/src/main/java/org/eclipse/jetty/ee10/servlet/ServletContextRequest.java index b9ab64d1b303..143e0fbd6801 100644 --- a/jetty-ee10/jetty-ee10-servlet/src/main/java/org/eclipse/jetty/ee10/servlet/ServletContextRequest.java +++ b/jetty-ee10/jetty-ee10-servlet/src/main/java/org/eclipse/jetty/ee10/servlet/ServletContextRequest.java @@ -197,11 +197,28 @@ protected ServletApiRequest newServletApiRequest() if (getHttpURI().hasViolations() && !getServletChannel().getServletContextHandler().getServletHandler().isDecodeAmbiguousURIs()) { // TODO we should check if current compliance mode allows all the violations? - - for (UriCompliance.Violation violation : getHttpURI().getViolations()) + if (getHttpURI().hasViolations()) { - if (UriCompliance.AMBIGUOUS_VIOLATIONS.contains(violation)) - return new ServletApiRequest.AmbiguousURI(this); + StringBuilder msg = null; + for (UriCompliance.Violation violation : getHttpURI().getViolations()) + { + if (UriCompliance.AMBIGUOUS_VIOLATIONS.contains(violation)) + { + if (msg == null) + { + msg = new StringBuilder(); + msg.append("Ambiguous URI encoding: "); + } + else + { + msg.append(", "); + } + + msg.append(violation.name()); + } + } + if (msg != null) + return new ServletApiRequest.AmbiguousURI(this, msg.toString()); } }