net: websocket: fix masked data when server sends close

When sending the close command as a server, the data is incorrectly
masked which violates RFC6455 section 5.1.

Use the is_client flag to avoid masking if the close is for a websocket
server.

Signed-off-by: Eric Holmberg <eric.holmberg@northriversystems.co.nz>
This commit is contained in:
Eric Holmberg 2025-04-03 00:13:37 +13:00 committed by Benjamin Cabé
commit 84d3cafbce

View file

@ -421,7 +421,7 @@ static int websocket_interal_disconnect(struct websocket_context *ctx)
NET_DBG("[%p] Disconnecting", ctx); NET_DBG("[%p] Disconnecting", ctx);
ret = websocket_send_msg(ctx->sock, NULL, 0, WEBSOCKET_OPCODE_CLOSE, ret = websocket_send_msg(ctx->sock, NULL, 0, WEBSOCKET_OPCODE_CLOSE,
true, true, SYS_FOREVER_MS); ctx->is_client, true, SYS_FOREVER_MS);
if (ret < 0) { if (ret < 0) {
NET_DBG("[%p] Failed to send close message (err %d).", ctx, ret); NET_DBG("[%p] Failed to send close message (err %d).", ctx, ret);
} }