Sources indicate that if you write your own WebSocket server, put one behind a custom proxy, or run one on a microcontroller, the first bug you are likely to hit is the handshake. The browser sends a Sec-WebSocket-Key. Your server answers with a Sec-WebSocket-Accept. If that answer is off by even one character, the connection never opens. Chromium's handshake code reports it as Incorrect 'Sec-WebSocket-Accept' header value.
Recent findings suggest that the rule takes one line, but there are a few ways to get it subtly wrong. Below we compute it by hand, reproduce four common mistakes with real output, and look at a known erratum in the RFC's own example.
It has been revealed that all values below come from the RFC's published example or from synthetic keys we generated. All outputs were produced by running the code shown in Node.js 24, and cross-checked in Python 3. (Related: Implementing MCP Servers in Python: An AI Shopping Assi...)
That is exactly the value printed in RFC 6455, section 1.3.
Sources indicate that the key dGhlIHNhbXBsZSBub25jZQ== is 24 characters long. Decoded, it is 16 bytes:.
Sources indicate that the RFC requires the key to be a base64-encoded random 16-byte nonce (section 4.1). The server does not need to decode it, though. It only needs to hash the text:.
SHA-1 of that string, in hex (40 characters = 20 bytes):.
The same 20 bytes in Base64 (28 characters, one =):.
Same RFC key, four broken implementations:.
Recent findings suggest that the first one is the easiest to spot: a correct accept value is always 28 characters and ends in a single =. A 56-character value starting with YjM3 means you encoded the text "b37a..." rather than the bytes. In Node that usually comes from digest('hex') followed by Buffer.from(hex).toString('base64'). Without the second argument, Buffer.from treats the hex as UTF-8 text. Either call digest('base64') directly or use Buffer.from(hex, 'hex').
The other three give a 28-character value that looks fine, which is why they take longer to find.
We ran a tiny http server that answers the upgrade event with one of three accept values, and connected to it with Node 24's built-in WebSocket client:.
Result: the correct value fired open. The hex-then-Base64 value and the decode-first value both fired error, and the connection never opened. The client generated a fresh 16-byte key each time, as the RFC requires. (Related: Welcome Gemma - Google’s fresh open LLM...)
RFC 6455 section 4.1 also gives an example key: the bytes 0x01 to 0x10 should be sent as AQIDBAUGBwgJCgsMDQ4PEC==.
That is not what a correct encoder produces. Encode those 16 bytes yourself and you get AQIDBAUGBwgJCgsMDQ4PEA==, ending in A, not C. The RFC Editor lists this as verified Errata ID 3150: the example was made by an encoder that did not set the unused padding bits to zero.
Why does this matter for a server?
Both strings decode to the same 16 bytes in lenient decoders (browser atob, Node Buffer, Python base64.b64decode). But they are different strings, so they hash to different accept values. A server that "normalises" the key by decoding and re-encoding it would send C/0n… to a client that sent …PEC== and expects OfS0…. The fix is the rule itself: hash the exact header text you received, trimmed of surrounding whitespace, and nothing else.
According to recent reports, one more sanity check that follows from the errata note. A 16-byte key always ends in two =, and the character before them can only be A, Q, g or w. We generated 20,000 random keys with crypto.randomBytes(16) and saw exactly those four endings. If you log a key that ends in some other letter, the client's encoder is non-standard. That is fine as long as you hash the string as received.
If you have a hex digest from a log or a sha1sum and want to check the Base64 form without writing code, the Hex ↔ Base64 page does it in the browser:.
Sources indicate that one tip from testing: paste only the hex digits. The converter drops every non-hex character. A prefix like 0x triggers an odd-length error, and a prefix like sha1= quietly leaves its a and 1 in the input, which changes the output.
Tool: https://base64decodetool.com/hex/.
Disclosure: this tool is from Mind vs Drive, the team behind this account.
