CVE-2019-6446
Remote code execution via pickle in NumPy 1.16.0 and earlier
- CVSS 9.8
- CWE-502 Deserialization of Untrusted Data
- Input Validation and Sanitization
- Remote
** DISPUTED ** An issue was discovered in NumPy 1.16.0 and earlier. It uses the pickle Python module unsafely, which allows remote attackers to execute arbitrary code via a crafted serialized object, as demonstrated by a numpy.load call. NOTE: third parties dispute this issue because it is a behavior that might have legitimate applications in (for example) loading serialized Python object arrays from trusted and authenticated sources.
- CVSS base score
- 9.8
- Published
- 2019-01-16
- 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
- Arbitrary Code Execution
- Affected component
- NumPy
- Fixed by upgrading
- Yes
Solution
Update NumPy to version 1.16.1 or higher.
Vulnerable code sample
import numpy as np
# Loading a .npy file using numpy's load function with allow_pickle set to True
# This demonstrates the vulnerability as it allows arbitrary code execution
def vulnerable_load(file_path):
return np.load(file_path, allow_pickle=True)
# Example usage
# array = vulnerable_load('data.npy')Patched code sample
import numpy as np
import os
# Securely loading a .npy file without using pickle
def secure_load(file_path):
if not os.path.isfile(file_path):
raise FileNotFoundError("The specified file does not exist.")
# Load the array from a .npy file using numpy's built-in load function
# with allow_pickle set to False to prevent arbitrary code execution
return np.load(file_path, allow_pickle=False)
# Example usage
# array = secure_load('data.npy')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.
- BUG: load fails when using pickle without allow_pickle=True (numpy/numpy)
numpy/lib/format.py · read_array,numpy/lib/npyio.py,numpy/lib/npyio.py · load,numpy/lib/npyio.py · NpzFile.__init__
Cite this entry
@misc{vaitp:cve20196446,
title = {{Remote code execution via pickle in NumPy 1.16.0 and earlier}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2019},
note = {VAITP Python Vulnerability Dataset, entry CVE-2019-6446},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2019-6446/}}
}
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 ::
