Skip to content

Commit 1c1c77b

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

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
@@ -138,6 +138,14 @@
138138
</fix>
139139
</changelog>
140140
</subsection>
141+
<subsection name="WebSocket">
142+
<changelog>
143+
<fix>
144+
<bug>64563</bug>: Add additional validation of payload length for
145+
WebSocket messages. (markt)
146+
</fix>
147+
</changelog>
148+
</subsection>
141149
<subsection name="Web Applications">
142150
<changelog>
143151
<update>

0 commit comments

Comments
 (0)