Can anyone explain me which attacks the Sec-WebSocket-Key in the WebSocket handshake addresses?
I don't understand it in the RFC, neither on google.
The Wikipedia description (https://en.m.wikipedia.org/wiki/WebSocket) of the protocol seems to sum it up best.
To quote:
In addition to Upgrade headers, the client sends a Sec-WebSocket-Key header containing base64-encoded random bytes, and the server replies with a hash of the key in the Sec-WebSocket-Accept header. This is intended to prevent a caching proxy from re-sending a previous WebSocket conversation,[25] and does not provide any authentication, privacy or integrity. The hashing function appends the fixed string 258EAFA5-E914-47DA-95CA-C5AB0DC85B11 (a GUID) to the value from Sec-WebSocket-Key header (which is not decoded from base64), applies the SHA-1 hashing function, and encodes the result using base64.
Edit: removed statement regarding replay protections thanks to Steffen
From the WebSockets FAQ at the IETF:
By having a client send out an encoded random number and having a server give a response that can only be generated by aWebSocket server, the client can verify that they are indeed talking to a WebSocket server and not to some other kind of server. ...
Thus the main idea is that WebSockets cannot be used to talk to real sockets, like mail servers etc. This is important because from the browser often internal trusted servers could be reached and attacked or misused (sending spam) this way.
Apart from that it also makes sure that there is no misbehaving proxy which returns old cached content instead of passing the WebSockets connection directly to the server.
Apart from that it also makes sure that there is no misbehaving proxy which returns old cached content instead of passing the WebSockets connection directly to the server.
Though the misbehaving proxy can always reply with the correct Sec-WebSocket-Accept
header, pretending that it's a WebSocket server, doesn't it?
Commented
Sep 10, 2019 at 16:36