Blogs / Why Python Randomizes Its Hash Salt at Startup

Why Python Randomizes Its Hash Salt at Startup

What attack the Language Summit 2026 write-up says the random hash salt defends against, how Python adopted it and when the salt is randomized.

  • Learning
  • 1 min read

For: Learners curious about language security.

The attack

The issue was one that was familiar to Python and many other languages: denial-of-service through hash algorithm collisions.[1]

The defense

Python fixed this issue in Python 3.3, as did many other programming languages, by adding a random “salt” to hash() calculations.[1]

Attacker-controlledinputsRandom salt in hash()randomized at programstartupNo controlled hashvaluesprevents unbalanced datastructuresprevents
What does the random salt prevent?

When the salt is chosen

The salt is randomized at program startup to prevent remote attackers from controlling the hash values of inputs, and thus causing a CPU denial-of-service by creating extremely unbalanced data structures that rely on object hash values being evenly distributed, like dict and set.[1]

Sources

  1. Memory Snapshots for CPython (Python Language Summit 2026) (blog.python.org · checked )

More articles