Skip to content

Commit 40fa74c

Browse files
committed
Fix BZ 64563 - additional payload length validation
https://bz.apache.org/bugzilla/show_bug.cgi?id=64563
1 parent e2ce6a9 commit 40fa74c

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

java/org/apache/tomcat/websocket/LocalStrings.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ wsFrame.noContinuation=A new message was started when a continuation frame was e
7171
wsFrame.notMasked=The client frame was not masked but all client frames must be masked
7272
wsFrame.oneByteCloseCode=The client sent a close frame with a single byte payload which is not valid
7373
wsFrame.partialHeaderComplete=WebSocket frame received. fin [{0}], rsv [{1}], OpCode [{2}], payload length [{3}]
74+
wsFrame.payloadMsbInvalid=An invalid WebSocket frame was received - the most significant bit of a 64-bit payload was illegally set
7475
wsFrame.sessionClosed=The client data cannot be processed because the session has already been closed
7576
wsFrame.suspendRequested=Suspend of the message receiving has already been requested.
7677
wsFrame.textMessageTooBig=The decoded text message was too big for the output buffer and the endpoint does not support partial messages

java/org/apache/tomcat/websocket/WsFrameBase.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,13 @@ private boolean processRemainingHeader() throws IOException {
261261
} else if (payloadLength == 127) {
262262
payloadLength = byteArrayToLong(inputBuffer.array(),
263263
inputBuffer.arrayOffset() + inputBuffer.position(), 8);
264+
// The most significant bit of those 8 bytes is required to be zero
265+
// (see RFC 6455, section 5.2). If the most significant bit is set,
266+
// the resulting payload length will be negative so test for that.
267+
if (payloadLength < 0) {
268+
throw new WsIOException(
269+
new CloseReason(CloseCodes.PROTOCOL_ERROR, sm.getString("wsFrame.payloadMsbInvalid")));
270+
}
264271
inputBuffer.position(inputBuffer.position() + 8);
265272
}
266273
if (Util.isControl(opCode)) {

webapps/docs/changelog.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,14 @@
127127
</fix>
128128
</changelog>
129129
</subsection>
130+
<subsection name="WebSocket">
131+
<changelog>
132+
<fix>
133+
<bug>64563</bug>: Add additional validation of payload length for
134+
WebSocket messages. (markt)
135+
</fix>
136+
</changelog>
137+
</subsection>
130138
<subsection name="Other">
131139
<changelog>
132140
<fix>

0 commit comments

Comments
 (0)