Chapter 0
What a WebSocket is
One handshake. Then frames, for as long as the socket stays open.
Every later chapter rests on this model. If you know what the handshake checks, you know where the bugs are.
The protocol in three steps
Section titled “The protocol in three steps”- The client sends one HTTP request with an Upgrade header.
- The server answers 101 Switching Protocols, and the connection then carries frames.
- Either side can send a frame at any time, with no method, path, or headers.
That is the whole protocol. Memorize the handshake below. It is the only HTTP request in the life of the socket. The Origin header on it decides the cross-site chapter.
GET /chat HTTP/1.1Host: target.comUpgrade: websocketConnection: UpgradeSec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==Sec-WebSocket-Version: 13Origin: https://target.comHTTP/1.1 101 Switching ProtocolsUpgrade: websocketSec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=RFC 6455 also sends Connection: Upgrade on that response.
The sample above is the pair to recognize in a proxy log.
The key and the accept value are the worked example from RFC 6455.
Sec-WebSocket-Accept is a protocol checksum, not an authentication token. The server appends the fixed RFC GUID 258EAFA5-E914-47DA-95CA-C5AB0DC85B11 to your key, hashes it with SHA-1, and Base64-encodes the result. Anyone can compute s3pPLMBiTxaQ9kYGzzhZRbK+xOo= from the sample key, so it proves only that the server speaks WebSocket.
After status 101, the bytes are frames.
{"action": "subscribe", "channel": "orders"}{"event": "order_update", "orderId": 5551, "status": "shipped"}The first object is the client. The second object is the server. Neither object is an HTTP request.
What a frame contains
Section titled “What a frame contains”A frame has a FIN bit, an opcode, a mask bit, a length, and a payload. Opcode 1 is text. Opcode 2 is binary. Opcode 8 closes the socket. Opcode 9 is ping. Opcode 10 is pong. The client must mask every frame it sends. The server must not mask frames it sends. Burp, wscat, and websocat apply the mask for you. A raw script that skips the mask is dropped by a correct server.
Ping frames are how an idle socket stays open. A quiet socket can still be closed by a proxy idle timer. That timer is not a session check.
What cannot see the frames
Section titled “What cannot see the frames”Everything that guards a REST API is blind inside the frames.
| Control | REST API | WebSocket |
|---|---|---|
| Authorization on each route | Runs on each request | Runs on the handshake, if it runs at all |
| WAF inspection | Runs on each request | Usually cannot read frames |
| Rate limit | Counts each request | Usually does not count frames |
| Session expiry | Checked on each request | The open socket can outlive the session |
| What scanners list | The HTTP routes | Frames stay out of HTTP history until you open the WebSocket tab |
The 101 request does land in Burp HTTP history. The frames do not, until you open a WebSocket session from that request. That is why a default crawl looks empty.
The claim that causes the bugs
Section titled “The claim that causes the bugs”The handshake is the login. Later frames are trusted because that handshake happened.
That pair of claims is the bug class. Every bug in the later chapters is a check that ran once, or a check that never ran.
Two headers the page does not get to choose
Section titled “Two headers the page does not get to choose”From a page, the browser sends Origin.
The browser also attaches cookies for that host, when the cookie rules allow it.
Those rules are in the CSWSH chapter. Test them. Do not assume them.
Page script can set Sec-WebSocket-Protocol.
Page script cannot set Cookie or Origin on this API.
SameSite is a cookie rule.
It decides whether the browser attaches a cookie to a cross-site request.
CORS means Cross-Origin Resource Sharing.
CORS decides whether a page may read an HTTP response.
The browser does not apply CORS to a WebSocket.
Access-Control-Allow-Origin does not decide whether the script may use the socket.
If the server returns 101, the script may use it.
The server has to reject a bad Origin itself.
The weakness id for a missing Origin check is CWE-1385.
The CSWSH chapter tests both rules.
Next, Chapter 1 shows how to find the socket.
Hands-on lab drill
Section titled “Hands-on lab drill”You intercept this upgrade request in Burp, change the Origin header to https://evil.test, and replay it. The server still returns 101 Switching Protocols and streams private messages. What bug did you just confirm?
GET /ws/support HTTP/1.1 Host: app.target.com Upgrade: websocket Connection: Upgrade Origin: https://evil.test Cookie: session=eyJhbGciOiJIUzI1NiJ9...
Origin and required no anti-CSRF token, any malicious site can open the socket as the victim and read or send frames. Read the full CSWSH chapter next.Origin header against a strict allowlist on the server and require a short-lived, unpredictable token during the handshake or initial auth frame.Related across the field guides
Section titled “Related across the field guides”- Spot socket endpoints during recon in JavaScript analysis and live host probing.
- Test frame-level object swaps using the same mindset as IDOR fundamentals and session security.
Open local graph around this page
WebSocketFor authorized testing only.