CVE-2022-21797
Joblib < 1.2.0, pre_dispatch flag, Arbitrary Code Execution via eval
- CVSS 9.8
- CWE-94
- Input Validation and Sanitization
- Remote
The package joblib from 0 and before 1.2.0 are vulnerable to Arbitrary Code Execution via the pre_dispatch flag in Parallel() class due to the eval() statement.
- CWE
- CWE-94
- CVSS base score
- 9.8
- Published
- 2022-09-26
- OWASP
- A06 Vulnerable and Outdated Components
- Orthogonal defect classification
- Function
- Code defect classification
- Incorrect Functionality
- Category
- Input Validation and Sanitization
- Subcategory
- Command Injection
- Accessibility scope
- Remote
- Impact
- Arbitrary Code Execution
- Affected component
- joblib
- Fixed by upgrading
- Yes
Solution
Update joblib to version 1.2.0 or higher.
Vulnerable code sample
from joblib import Parallel, delayed
# Vulnerable usage of Parallel with eval() in pre_dispatch
def vulnerable_function(x):
return x * x
# Using pre_dispatch in a way that could lead to arbitrary code execution
results = Parallel(n_jobs=2, pre_dispatch='2*n_jobs')(delayed(vulnerable_function)(i) for i in range(10))
print(results)Patched code sample
from joblib import Parallel, delayed
# Safe usage of Parallel without eval()
def safe_function(x):
return x * x
# Using the pre_dispatch flag without eval()
results = Parallel(n_jobs=2, pre_dispatch='2*n_jobs')(delayed(safe_function)(i) for i in range(10))
print(results)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.
- FIX actually fix the eval security issue (joblib/joblib)
joblib/parallel.py,joblib/parallel.py · Parallel.__call__ - FIX make sure pre_dispatch cannot do arbitrary code execution (#1321) (joblib/joblib)
joblib/parallel.py,joblib/parallel.py · Parallel.__call__
Cite this entry
@misc{vaitp:cve202221797,
title = {{Joblib < 1.2.0, pre_dispatch flag, Arbitrary Code Execution via eval}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2022},
note = {VAITP Python Vulnerability Dataset, entry CVE-2022-21797},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2022-21797/}}
}
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 ::
