CVE-2022-1930
eth-account PyPI package: Exponential ReDoS in "encode_structured_data" method
- CVSS 7.5
- CWE-1333
- Input Validation and Sanitization
- Remote
An exponential ReDoS (Regular Expression Denial of Service) can be triggered in the eth-account PyPI package, when an attacker is able to supply arbitrary input to the encode_structured_data method
- CWE
- CWE-1333
- CVSS base score
- 7.5
- Published
- 2022-08-22
- OWASP
- A06 Vulnerable and Outdated Components
- Orthogonal defect classification
- Function
- Code defect classification
- Incorrect Functionality
- Category
- Input Validation and Sanitization
- Subcategory
- Insecure Parsing or Deserialization
- Accessibility scope
- Remote
- Impact
- Denial of Service (DoS)
- Affected component
- eth-account
- Fixed by upgrading
- Yes
Solution
Update eth-account to the latest version.
Vulnerable code sample
import re
def vulnerable_encode_structured_data(data):
# Vulnerable regular expression that can lead to exponential backtracking
pattern = r'^(a|aa|aaa|aaaa|aaaaa|aaaaaa|aaaaaaa|aaaaaaaa|aaaaaaaaa|aaaaaaaaaa)+$'
if not re.match(pattern, data):
raise ValueError("Invalid input data")
# Proceed with the encoding logic
# ...
return encoded_dataPatched code sample
import re
def safe_encode_structured_data(data):
# Use a more efficient regular expression to avoid exponential backtracking
# This is a simplified example; the actual regex may vary based on requirements
pattern = r'^[a-zA-Z0-9_]+$' # Example pattern that matches only alphanumeric and underscores
if not re.match(pattern, data):
raise ValueError("Invalid input data")
# Proceed with the encoding logic
# ...
return encoded_dataPublished 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.
- fix redos-able regex and add poc code to tests (#182) (ethereum/eth-account)
eth_account/_utils/structured_data/validation.py
Cite this entry
@misc{vaitp:cve20221930,
title = {{eth-account PyPI package: Exponential ReDoS in "encode_structured_data" method}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2022},
note = {VAITP Python Vulnerability Dataset, entry CVE-2022-1930},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2022-1930/}}
}
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 ::
