This is an automated email from the ASF dual-hosted git repository.
rmaucher pushed a commit to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/9.0.x by this push:
new 390fa65774 Consistency for extension header processing issues
390fa65774 is described below
commit 390fa65774b537c59acba293c78ca98c1eef4912
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 385d39e1d3..ff873b0375 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 07429ed19a..7847497986 100644
--- a/java/org/apache/tomcat/websocket/WsWebSocketContainer.java
+++ b/java/org/apache/tomcat/websocket/WsWebSocketContainer.java
@@ -441,7 +441,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 9c0b10ff27..edbfb9117e 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]