3 ms·
The lesson from this would be: when creating a network protocol, always start the stream or packet with a magic number, in both directions. If the magic number
by cesarb 10y ago
The lesson from this would be: when creating a network protocol, always start the stream or packet with a magic number, in both directions. If the magic number doesn't match, drop the packet or close the connection.
In fact, one could say that these are HTTP's magic numbers: 'HTTP/' for the response, and a few ('GET ', 'HEAD ', 'POST ', 'PUT ', and so on) for the request. IIRC, one trick web servers use to speed up parsing a request is to treat the first four bytes as an integer, and switch on its value to determine the HTTP method.
- theoh 10y agoNot sure about this. "magic" in the sense of file type recognition has no cryptographic/security ambitions. On the other hand, when implementing a network protocol, I'd say one needs to be really careful and expect the unexpected at any point (not just in the "magic" phase). What does it buy you (in terms of robustness) to have a fakeable magic number at the start of the stream?