webscoket 中的 mask 细节

文章讲述了WebSocket协议中,客户端向服务器发送的所有帧,包括空的ping帧,都必须进行掩码加密。RFC6455规定了这一安全措施,以保护数据和混淆网络中间代理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

掩码用于给客户端到服务端的帧数据加密(异或的方式,非常简单),对此RFC6455中给了一些细节如下:

The masking key is contained completely within the frame, as defined in Section 5.2 as frame-masking-key. It is used to mask the "Payload data" defined in the same section as frame-payload-data, which includes "Extension data" and "Application data".

我们看到,这个写的很清楚,掩码是给 payload  进行加密用的,这个位置会产生一个误解,就是,如果我没有 payload 的时候,是不是可以不需要掩码?比如一个 ping 帧,不带任何数据是否不需要mask?

答案是否定的!

协议中有这么一段话:

In the WebSocket Protocol, data is transmitted using a sequence of frames. To avoid confusing network intermediaries (such as intercepting proxies) and for security reasons that are further discussed in Section 10.3, a client MUST mask all frames that it sends to the server (see Section 5.3 for further details). (Note that masking is done whether

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值