I’ve noticed that, by default, Zig hash map doesn’t depend on random number generation, and instantiates a particular hash function with a fixed seed. It seems to me that this is potentially vulnurable to a DoS attack, when the attacker can craft hash map entries which force collisions.
In particular, it seems that recently added http server has this problem when dealing with headers:
Am I correct that the code as is is vulnerable to DoS? That is, that a malicious client can send a sequence of headers which would require O(N^2) CPU time to process?
What would be the correct and idiomatic way to fix that?
The way to defend against this class of attack is to use a cryptographic hash function (for example std.crypto.auth.siphash.SipHash128(1,2) with a secret key (not 0).
Cryptographic hash functions are secure when you use enough bits if your hashmap is not EiBs big you will only use very little bits, it is easy to find collisions on the few bits your hashmap will use, you will run out of memory way before a cryptographic hash function is secure.