How to change WebSocket payload?

77 views
Skip to first unread message

K

unread,
Feb 23, 2022, 11:40:10 AM2/23/22
to OWASP ZAP User Group
Hello,
I am trying to change the WebSocket payload but getting the error:

"java.lang.ClassCastException: Cannot cast java.lang.String to [Bjava.lang.ClassCastException: Cannot cast java.lang.String to [B"

My script:

function onMessageFrame(msg, helper){
mss = msg.getReadablePayload();        
n = mss.indexOf("Red\":500");
if(n > 0) {
newmss = mss.replace("Red\":500", "Red\":100");
msg.setPayload( newmss );
}
}

Checked the ZAP code and it seems that setPayload method expect Object, but after replacing the text I am getting String.

public void setPayload(Object payload) {
this.payload = payload;
}


What is the correct method how to change the WebSocket content?

thc...@gmail.com

unread,
Feb 24, 2022, 4:15:44 AM2/24/22
to zaprox...@googlegroups.com
Hi.

The scripts are passed in a WebSocketMessage not WebSocketMessageDTO.

You need to set a byte[] e.g.:

msg.setPayload( newmss.getBytes("UTF-8") );


Best regards.

K

unread,
Feb 24, 2022, 6:17:34 AM2/24/22
to OWASP ZAP User Group

Hello,
Thank you.
It solved my issue.
Reply all
Reply to author
Forward
0 new messages