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

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


The following commit(s) were added to refs/heads/11.0.x by this push:
     new 293c892c71 Consistency for extension header processing issues
293c892c71 is described below

commit 293c892c71cdd4789757fd656b7ddb5173e88939
Author: remm <[email protected]>
AuthorDate: Wed Sep 2 10:02:30 2026 +0200

    Consistency for extension header processing issues
    
    Found by code review.
---
 java/org/apache/tomcat/websocket/LocalStrings.properties   | 1 +
 java/org/apache/tomcat/websocket/WsWebSocketContainer.java | 7 ++++++-
 java/org/apache/tomcat/websocket/server/UpgradeUtil.java   | 7 ++++++-
 3 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/java/org/apache/tomcat/websocket/LocalStrings.properties 
b/java/org/apache/tomcat/websocket/LocalStrings.properties
index 7805a0e7f3..6b9e347fbf 100644
--- a/java/org/apache/tomcat/websocket/LocalStrings.properties
+++ b/java/org/apache/tomcat/websocket/LocalStrings.properties
@@ -140,6 +140,7 @@ wsWebSocketContainer.connect.write=Writing the HTTP upgrade 
request from buffer
 wsWebSocketContainer.defaultConfiguratorFail=Failed to create the default 
configurator
 wsWebSocketContainer.failedAuthentication=Failed to handle HTTP response code 
[{0}]. [{1}] header was not accepted by server.
 wsWebSocketContainer.httpRequestFailed=The HTTP request to initiate the 
WebSocket connection to [{0}] failed
+wsWebSocketContainer.invalidExtensionsHeader=The server sent an invalid 
extension header
 wsWebSocketContainer.invalidExtensionParameters=The server responded with 
extension parameters the client is unable to support
 wsWebSocketContainer.invalidHeader=Unable to parse HTTP header as no colon is 
present to delimit header name and header value in [{0}]. The header has been 
skipped.
 wsWebSocketContainer.invalidStatus=The HTTP response from the server [{0}] did 
not permit the HTTP upgrade to WebSocket
diff --git a/java/org/apache/tomcat/websocket/WsWebSocketContainer.java 
b/java/org/apache/tomcat/websocket/WsWebSocketContainer.java
index c16d775a05..688dd3c1ba 100644
--- a/java/org/apache/tomcat/websocket/WsWebSocketContainer.java
+++ b/java/org/apache/tomcat/websocket/WsWebSocketContainer.java
@@ -436,7 +436,12 @@ public class WsWebSocketContainer implements 
WebSocketContainer, BackgroundProce
             List<String> extHeaders = 
handshakeResponse.getHeaders().get(Constants.WS_EXTENSIONS_HEADER_NAME);
             if (extHeaders != null) {
                 for (String extHeader : extHeaders) {
-                    Util.parseExtensionHeader(extensionsAgreed, extHeader);
+                    try {
+                        Util.parseExtensionHeader(extensionsAgreed, extHeader);
+                    } catch (IllegalArgumentException iae) {
+                        throw new DeploymentException(
+                                
sm.getString("wsWebSocketContainer.invalidExtensionsHeader"), iae);
+                    }
                 }
             }
 
diff --git a/java/org/apache/tomcat/websocket/server/UpgradeUtil.java 
b/java/org/apache/tomcat/websocket/server/UpgradeUtil.java
index 750b727022..e6e7d98d1b 100644
--- a/java/org/apache/tomcat/websocket/server/UpgradeUtil.java
+++ b/java/org/apache/tomcat/websocket/server/UpgradeUtil.java
@@ -136,7 +136,12 @@ public class UpgradeUtil {
         List<Extension> extensionsRequested = new ArrayList<>();
         Enumeration<String> extHeaders = 
req.getHeaders(Constants.WS_EXTENSIONS_HEADER_NAME);
         while (extHeaders.hasMoreElements()) {
-            Util.parseExtensionHeader(extensionsRequested, 
extHeaders.nextElement());
+            try {
+                Util.parseExtensionHeader(extensionsRequested, 
extHeaders.nextElement());
+            } catch (IllegalArgumentException iae) {
+                resp.sendError(HttpServletResponse.SC_BAD_REQUEST);
+                return;
+            }
         }
         // Negotiation phase 1. By default, this simply filters out the
         // extensions that the server does not support but applications could


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

Reply via email to