Skip to content

Fix Socket Mode builtin WebSocket masked payload unmasking (RFC 6455)#1858

Open
beejak wants to merge 1 commit intoslackapi:mainfrom
beejak:fix/socket-mode-masked-payload-unmasking
Open

Fix Socket Mode builtin WebSocket masked payload unmasking (RFC 6455)#1858
beejak wants to merge 1 commit intoslackapi:mainfrom
beejak:fix/socket-mode-masked-payload-unmasking

Conversation

@beejak
Copy link
Copy Markdown

@beejak beejak commented Apr 21, 2026

Summary

This change fixes the masked WebSocket frame handling path in the builtin Socket Mode client (slack_sdk/socket_mode/builtin/internals.py).

The previous code used range(data_to_append) where data_to_append is bytes (invalid in Python 3) and attempted in-place XOR on an immutable bytes object. Per RFC 6455, masking XORs octets; unmasking is now implemented with a bytearray and range(len(...)).

A short comment was also added in _validate_sec_websocket_accept: SHA-1 for Sec-WebSocket-Accept is required by RFC 6455 section 1.3, not a discretionary hash upgrade to SHA-256.

Verification

pytest tests/slack_sdk/socket_mode/test_builtin_message_parser.py -q

(2 passed locally.)

Context

Servers normally send unmasked frames to clients; the masked branch is uncommon but should be correct for compliance and tests that exercise masked server frames.

The masked-payload branch incorrectly used range(data_to_append) on bytes and
attempted in-place XOR on an immutable bytes object. Unmasking now uses a
bytearray per RFC 6455. Added a short comment that SHA-1 in
Sec-WebSocket-Accept is required by RFC 6455 section 1.3.

Made-with: Cursor
@beejak beejak requested a review from a team as a code owner April 21, 2026 14:53
@salesforce-cla
Copy link
Copy Markdown

Thanks for the contribution! Before we can merge this, we need @beejak to sign the Salesforce Inc. Contributor License Agreement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant