Skip to content

Commit

Permalink
Fix BZ 64563 - additional payload length validation
Browse files Browse the repository at this point in the history
  • Loading branch information
markt-asf committed Jun 30, 2020
1 parent 3d23880 commit f9f75c1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions java/org/apache/tomcat/websocket/LocalStrings.properties
Expand Up @@ -64,6 +64,7 @@ wsFrame.noContinuation=A new message was started when a continuation frame was e
wsFrame.notMasked=The client frame was not masked but all client frames must be masked
wsFrame.oneByteCloseCode=The client sent a close frame with a single byte payload which is not valid
wsFrame.partialHeaderComplete=WebSocket frame received. fin [{0}], rsv [{1}], OpCode [{2}], payload length [{3}]
wsFrame.payloadMsbInvalid=An invalid WebSocket frame was received - the most significant bit of a 64-bit payload was illegally set
wsFrame.sessionClosed=The client data cannot be processed because the session has already been closed
wsFrame.textMessageTooBig=The decoded text message was too big for the output buffer and the endpoint does not support partial messages
wsFrame.wrongRsv=The client frame set the reserved bits to [{0}] for a message with opCode [{1}] which was not supported by this endpoint
Expand Down
7 changes: 7 additions & 0 deletions java/org/apache/tomcat/websocket/WsFrameBase.java
Expand Up @@ -256,6 +256,13 @@ private boolean processRemainingHeader() throws IOException {
readPos += 2;
} else if (payloadLength == 127) {
payloadLength = byteArrayToLong(inputBuffer, readPos, 8);
// The most significant bit of those 8 bytes is required to be zero
// (see RFC 6455, section 5.2). If the most significant bit is set,
// the resulting payload length will be negative so test for that.
if (payloadLength < 0) {
throw new WsIOException(
new CloseReason(CloseCodes.PROTOCOL_ERROR, sm.getString("wsFrame.payloadMsbInvalid")));
}
readPos += 8;
}
if (Util.isControl(opCode)) {
Expand Down
4 changes: 4 additions & 0 deletions webapps/docs/changelog.xml
Expand Up @@ -105,6 +105,10 @@
Include the target URL in the log message when a WebSocket connection
fails. (markt)
</add>
<fix>
<bug>64563</bug>: Add additional validation of payload length for
WebSocket messages. (markt)
</fix>
</changelog>
</subsection>
<subsection name="Other">
Expand Down

1 comment on commit f9f75c1

@Beyond-My
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, I have a question to ask you,why the additional validation of payload length for WebSocket messages is 64563 ?

Please sign in to comment.