CVE-2020-29651
Denial of service in py.path.svnwc (python-py) 1.9.0 via malicious input in blame functionality
- CVSS 7.5
- CWE-400: Uncontrolled Resource Consumption
- Resource Management
- Remote
A denial of service via regular expression in the py.path.svnwc component of py (aka python-py) through 1.9.0 could be used by attackers to cause a compute-time denial of service attack by supplying malicious input to the blame functionality.
- CVSS base score
- 7.5
- Published
- 2020-12-09
- OWASP
- A06 Vulnerable and Outdated Components
- Orthogonal defect classification
- Function
- Code defect classification
- Incorrect Functionality
- Category
- Resource Management
- Subcategory
- Resource Exhaustion
- Accessibility scope
- Remote
- Impact
- Denial of Service (DoS)
- Affected component
- py
- Fixed by upgrading
- Yes
Solution
Update py (python-py) to version 1.9.1 or higher.
Vulnerable code sample
import re
def vulnerable_blame(input_string):
# Vulnerable regex that can lead to catastrophic backtracking
pattern = re.compile(r'^(a+)+$') # This pattern can cause excessive backtracking
if not pattern.match(input_string):
raise ValueError("Input does not match expected format")
# Proceed with the blame functionality using the input
# (Actual blame logic would go here)
return "Blame processed for input: " + input_string
# Example usage
try:
result = vulnerable_blame("a" * 10000 + "b") # Malicious input to trigger DoS
print(result)
except ValueError as e:
print(e)Patched code sample
import re
def safe_blame(input_string):
# Using a more controlled regex to avoid catastrophic backtracking
# This regex is simplified to avoid complex patterns that could lead to DoS
pattern = re.compile(r'^[\w\s\-]+$') # Allow only word characters, spaces, and hyphens
if not pattern.match(input_string):
raise ValueError("Input contains invalid characters")
# Proceed with the blame functionality using the safe input
# (Actual blame logic would go here)
return "Blame processed for input: " + input_string
# Example usage
try:
result = safe_blame("valid-input")
print(result)
except ValueError as e:
print(e)Published fix
Public sources link this CVE to the changes below. The code samples above were generated to illustrate the defect; these links lead to the code the project actually changed.
- svnwc: fix regular expression vulnerable to DoS in blame functionality (pytest-dev/py)
py/_path/svnwc.py
Cite this entry
@misc{vaitp:cve202029651,
title = {{Denial of service in py.path.svnwc (python-py) 1.9.0 via malicious input in blame functionality}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2020},
note = {VAITP Python Vulnerability Dataset, entry CVE-2020-29651},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2020-29651/}}
}
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 ::
