(tomcat) branch 10.1.x updated: Similar fix for restrictedUserAgents
[email protected] Fri, 31 Jul 2026 11:39:22 +0000
| Newsgroups | gmane.comp.jakarta.tomcat.devel |
|---|---|
| Message-ID | <178549796210.4049062.15941449119684042392@gitbox3-he-fi.apache.org> |
This is an automated email from the ASF dual-hosted git repository.
rmaucher 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 ade9e6c848 Similar fix for restrictedUserAgents
ade9e6c848 is described below
commit ade9e6c84839f80527f018af4c4132d97ed332b2
Author: remm <[email protected]>
AuthorDate: Fri Jul 31 13:36:01 2026 +0200
Similar fix for restrictedUserAgents
Coauthored with OpenCode.
---
java/org/apache/coyote/http11/Http11Processor.java | 2 +-
.../apache/coyote/http11/TestHttp11Processor.java | 35 ++++++++++++++++++++++
webapps/docs/changelog.xml | 6 ++++
3 files changed, 42 insertions(+), 1 deletion(-)
diff --git a/java/org/apache/coyote/http11/Http11Processor.java b/java/org/apache/coyote/http11/Http11Processor.java
index 555ff5880d..23437591ac 100644
--- a/java/org/apache/coyote/http11/Http11Processor.java
+++ b/java/org/apache/coyote/http11/Http11Processor.java
@@ -675,7 +675,7 @@ public class Http11Processor extends AbstractProcessor {
// and keepAlive flags accordingly
if (userAgentValueMB != null && !userAgentValueMB.isNull()) {
String userAgentValue = userAgentValueMB.toString();
- if (restrictedUserAgents.matcher(userAgentValue).matches()) {
+ if (restrictedUserAgents.matcher(userAgentValue).find()) {
http11 = false;
keepAlive = false;
}
diff --git a/test/org/apache/coyote/http11/TestHttp11Processor.java b/test/org/apache/coyote/http11/TestHttp11Processor.java
index 31a3b3f69f..4672115e83 100644
--- a/test/org/apache/coyote/http11/TestHttp11Processor.java
+++ b/test/org/apache/coyote/http11/TestHttp11Processor.java
@@ -2201,4 +2201,39 @@ public class TestHttp11Processor extends TomcatBaseTest {
Assert.assertTrue(newEncodings.contains("br"));
Assert.assertFalse(newEncodings.contains("gzip"));
}
+
+ @Test
+ public void testRestrictedUserAgents() throws Exception {
+ Tomcat tomcat = getTomcatInstance();
+
+ // No file system docBase required
+ Context ctx = getProgrammaticRootContext();
+
+ Tomcat.addServlet(ctx, "TesterServlet", new TesterServlet());
+ ctx.addServletMappingDecoded("/*", "TesterServlet");
+
+ // Set restricted user agents to match "MSIE"
+ Assert.assertTrue(tomcat.getConnector().setProperty("restrictedUserAgents", "gorilla|desesplorer|MSIE|tigrus"));
+
+ tomcat.start();
+
+ // User-agent matching the pattern should be downgraded to HTTP/1.0
+ // @formatter:off
+ String request =
+ "GET /test HTTP/1.1" + CRLF +
+ "Host: any" + CRLF +
+ "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)" + CRLF +
+ CRLF;
+ // @formatter:on
+
+ Client client = new Client(tomcat.getConnector().getLocalPort());
+ client.setRequest(new String[] { request });
+
+ client.connect();
+ client.processRequest();
+
+ // Should be downgraded to HTTP/1.0, although the server will still advertise HTTP/1.1
+ Assert.assertTrue(client.isResponse200());
+ Assert.assertTrue(client.getResponseHeaders().contains("Connection: close"));
+ }
}
\ No newline at end of file
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 3a2391869c..00626e9fd4 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -196,6 +196,12 @@
of the example <code>gorilla|desesplorer|tigrus</code> pattern
documented in the javadoc. (remm)
</fix>
+ <fix>
+ Fix matching the HTTP/1.1 connector
+ <code>restrictedUserAgents</code> with patterns of the style
+ of the example <code>gorilla|desesplorer|tigrus</code> pattern
+ documented in the javadoc. (remm)
+ </fix>
</changelog>
</subsection>
<subsection name="Jasper">