From 26cb16457de193dc9eee745977bc71c29bb58286 Mon Sep 17 00:00:00 2001 From: Gustavo Avila Date: Fri, 15 Jul 2022 18:42:42 -0500 Subject: [PATCH] Add payload length validation to ping and pong --- .../gustavoavila/websocketclient/WebSocketClient.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/dev/gustavoavila/websocketclient/WebSocketClient.java b/src/main/java/dev/gustavoavila/websocketclient/WebSocketClient.java index 36227e4..26177ff 100644 --- a/src/main/java/dev/gustavoavila/websocketclient/WebSocketClient.java +++ b/src/main/java/dev/gustavoavila/websocketclient/WebSocketClient.java @@ -499,8 +499,11 @@ public void run() { * @param data Data to be sent, or null if there is no data. */ public void sendPing(byte[] data) { - final Payload payload = new Payload(OPCODE_PING, data); + if (data != null && data.length > 125) { + throw new IllegalArgumentException("Control frame payload cannot be greater than 125 bytes"); + } + final Payload payload = new Payload(OPCODE_PING, data); new Thread(new Runnable() { @Override public void run() { @@ -515,8 +518,11 @@ public void run() { * @param data Data to be sent, or null if there is no data. */ public void sendPong(byte[] data) { - final Payload payload = new Payload(OPCODE_PONG, data); + if (data != null && data.length > 125) { + throw new IllegalArgumentException("Control frame payload cannot be greater than 125 bytes"); + } + final Payload payload = new Payload(OPCODE_PONG, data); new Thread(new Runnable() { @Override public void run() {