Validate that Sec-WebSocket-Key is a base64-encoded 16-byte nonce per RFC 6455. `base64Decode` (via `Poco::Base64Decoder`) throws `DataFormatException` on malformed input, so swallow exceptions here and treat any decode failure as an invalid key. Otherwise a crafted header would escape as a `500` instead of the deterministic `400` handshake rejection the caller expects.
| 54 | /// as an invalid key. Otherwise a crafted header would escape as a `500` |
| 55 | /// instead of the deterministic `400` handshake rejection the caller expects. |
| 56 | bool isValidWebSocketKey(const String & key) |
| 57 | { |
| 58 | if (key.empty() || key.size() > 128) |
| 59 | return false; |
| 60 | try |
| 61 | { |
| 62 | return base64Decode(key).size() == 16; |
| 63 | } |
| 64 | catch (...) /// Ok: malformed base64 is just an invalid key; the caller maps it to a 400 handshake rejection. |
| 65 | { |
| 66 | return false; |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | /// Send all bytes to the socket, handling partial writes. |
| 71 | void sendAllBytes(Poco::Net::StreamSocket & socket, const char * data, size_t len) |
no test coverage detected