-
Notifications
You must be signed in to change notification settings - Fork 18
Description
I've compared both the original and this implementation and while it's true that there's a standard way of getting a random number, the process id and the thread id, this does not provide the same amount of entropy.
Operating systems often use bit-hacks and smart encodings of identifiers for efficient lookup.
If you observe the pids/tids on your consumer Windows machine for example you will see that all pids are of the form 2*n where 150 < n < 20'000.
Servers have even less range for n as there's less Software running and they are less random and more "lab condition".
To make the seed more random this implementation calls rand twice.
When we now view this in the context of distributed systems* it becomes clear that pids and tids aren't really random and the only meaningful source of entropy comes from the two rand calls, which suddenly sounds a lot gloomier - as it should.
I think the amount of entropy here is insufficient compared to the original implementation and we should come up with a better way to seed this.
For reference, the original implementation hashes
> Object.keys(window).toString().length
< 4980characters and uses 32 rand calls to build the seed.
See also: CWE-331: Insufficient Entropy and CWE-339: Small Seed Space in PRNG.
* imagine an infrastructure like Netflix, where you have 1000 identically configured servers, running the exact same microservice and think what happens when they - at the same time, with the same seed - try to generate an ID and 5% of the servers happen to have the same pid/tid.