CVE-2022-42965
Python-libnmap <=0.7.2: Remote command execution due to argument validation flaw
- CVSS 7.5
- CWE-1333 Inefficient Regular Expression Complexity
- Input Validation and Sanitization
- Remote
An exponential ReDoS (Regular Expression Denial of Service) can be triggered in the snowflake-connector-python PyPI package, when an attacker is able to supply arbitrary input to the undocumented get_file_transfer_type method
- CVSS base score
- 7.5
- Published
- 2022-11-09
- 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
- snowflake-connector-python
- Fixed by upgrading
- Yes
Solution
Update snowflake-connector-python to version 2.6.0 or higher.
Vulnerable code sample
import re
def vulnerable_get_file_transfer_type(input_string):
# Vulnerable regex pattern that can lead to exponential backtracking
pattern = r'^(.*?)+$' # Example of a vulnerable pattern
if re.match(pattern, input_string):
return "Valid input"
else:
return "Invalid input"
# Example usage
result = vulnerable_get_file_transfer_type("a" * 1000) # This can trigger the vulnerability
print(result)Patched code sample
import re
def safe_get_file_transfer_type(input_string):
# Limit the length of the input to prevent excessive backtracking
if len(input_string) > 100: # Example limit
raise ValueError("Input too long")
# Use a non-exponential regex pattern
pattern = r'^[a-zA-Z0-9_]+$' # Example pattern to match valid characters
if re.match(pattern, input_string):
return "Valid input"
else:
raise ValueError("Invalid input format")
# Example usage
try:
result = safe_get_file_transfer_type("valid_input_123")
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.
- SNOW-693548 fixing redos attack (#1327) (snowflakedb/snowflake-connector-python)
src/snowflake/connector/cursor.py,src/snowflake/connector/cursor.py · SnowflakeCursor.get_file_transfer_type,src/snowflake/connector/cursor.py · SnowflakeCursor._execute_helper,src/snowflake/connector/gcs_storage_client.py,src/snowflake/connector/gcs_storage_client.py · SnowflakeGCSRestClient._get_local_file_path_from_put_command
Cite this entry
@misc{vaitp:cve202242965,
title = {{Python-libnmap <=0.7.2: Remote command execution due to argument validation flaw}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2022},
note = {VAITP Python Vulnerability Dataset, entry CVE-2022-42965},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2022-42965/}}
}
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 ::
