PYTHONHASHSEED
The environment variable that controls the seed Python uses to randomise str, bytes and datetime hashes.
A fixed or disabled seed in production brings back the hash-flooding weakness.
In more detail
If it is unset or set to "random", each process picks a random seed. Setting it to an integer fixes the seed so hash values and set iteration order repeat between runs, and 0 turns randomisation off entirely. Fixed seeds are for reproducible tests and debugging only.
Example
PYTHONHASHSEED=0 python3 -c "print(hash('apple'))"Related terms
- hash randomisation — Mixing a secret random value, chosen when a process starts, into string hashing so that hash values cannot be predicted from outside.
- environment variable — A named setting such as PORT=8000 that a program reads from its surroundings when it starts.
- hash flooding — An attack that sends a server many keys crafted to collide in its hash tables, turning each O(1) operation into O(n) and exhausting its CPU.
Taught in
- What A Hash Function Promises — Algorithms & Data Structures for Working Engineers
- Collisions In Practice And Hash Flooding — Algorithms & Data Structures for Working Engineers