VAITP Dataset

← Back to the dataset

CVE-2013-7040

Denial of Service in Python Hash Collision Handling

  • CVSS 4.3
  • CWE-310: Cryptographic Issues
  • Cryptographic
  • Local

Python 2.7 before 3.4 only uses the last eight bits of the prefix to randomize hash values, which causes it to compute hash values without restricting the ability to trigger hash collisions predictably and makes it easier for context-dependent attackers to cause a denial of service (CPU consumption) via crafted input to an application that maintains a hash table. NOTE: this vulnerability exists because of an incomplete fix for CVE-2012-1150.

CVSS base score
4.3
Published
2014-05-19
OWASP
A08 Software and Data Integrity Failures
Orthogonal defect classification
Algorithm
Code defect classification
Incorrect Algorithm
Category
Cryptographic
Subcategory
Inadequate random number generation
Accessibility scope
Local
Impact
Unauthorized Access
Fixed by upgrading
Yes

Solution

Upgrade to Python 3.4 or later.

Vulnerable code sample

import sys
table = {}
while True:
    s = input("Enter a string: ")
    if s == "quit":
        break
    h = hash(s)
    print(f"The hash of {s} is {h}")
    if h in table:
        print(f"Collision detected with {table[h]}")
        sys.exit(1)
    else:
        table[h] = s

Patched code sample

import sys
import hashlib
table = {}
while True:
    s = input("Enter a string: ")
    if s == "quit":
        break
    h = hashlib.sha256(s.encode()).hexdigest()
    print(f"The hash of {s} is {h}")
    if h in table:
        print(f"Collision detected with {table[h]}")
        sys.exit(1)
    else:
        table[h] = s

Cite this entry

@misc{vaitp:cve20137040,
  title        = {{Denial of Service in Python Hash Collision Handling}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2014},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2013-7040},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2013-7040/}}
}
Introducing the "VAITP dataset": a specialized repository of Python vulnerabilities and patches, meticulously compiled for the use of the security research community. As Python's prominence grows, understanding and addressing potential security vulnerabilities become crucial. Crafted by and for the cybersecurity community, this dataset offers a valuable resource for researchers, analysts, and developers to analyze and mitigate the security risks associated with Python. Through the comprehensive exploration of vulnerabilities and corresponding patches, the VAITP dataset fosters a safer and more resilient Python ecosystem, encouraging collaborative advancements in programming security.

The supreme art of war is to subdue the enemy without fighting.

Sun Tzu – “The Art of War”

:: Shaping the future through research and ingenuity ::