CVE-2024-21513
Arbitrary Code Execution in langchain-experimental due to unsafe eval usage.
- CVSS 8.5
- CWE-94
- Input Validation and Sanitization
- Remote
Versions of the package langchain-experimental from 0.0.15 and before 0.0.21 are vulnerable to Arbitrary Code Execution when retrieving values from the database, the code will attempt to call 'eval' on all values. An attacker can exploit this vulnerability and execute arbitrary python code if they can control the input prompt and the server is configured with VectorSQLDatabaseChain. **Notes:** Impact on the Confidentiality, Integrity and Availability of the vulnerable component: Confidentiality: Code execution happens within the impacted component, in this case langchain-experimental, so all resources are necessarily accessible. Integrity: There is nothing protected by the impacted component inherently. Although anything returned from the component counts as 'information' for which the trustworthiness can be compromised. Availability: The loss of availability isn't caused by the attack itself, but it happens as a result during the attacker's post-exploitation steps. Impact on the Confidentiality, Integrity and Availability of the subsequent system: As a legitimate low-privileged user of the package (PR:L) the attacker does not have more access to data owned by the package as a result of this vulnerability than they did with normal usage (e.g. can query the DB). The unintended action that one can perform by breaking out of the app environment and exfiltrating files, making remote connections etc. happens during the post exploitation phase in the subsequent system – in this case, the OS. AT:P: An attacker needs to be able to influence the input prompt, whilst the server is configured with the VectorSQLDatabaseChain plugin.
- CWE
- CWE-94
- CVSS base score
- 8.5
- Published
- 2024-07-15
- OWASP
- A01 Broken Access Control
- 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
- langchain-ex
- Fixed by upgrading
- Yes
Solution
Upgrade to version 0.0.21 or later of the langchain-experimental package.
Vulnerable code sample
def retrieve_value_from_database(db_value):
"""Vulnerable function that demonstrates the security issue."""
return eval(db_value)
user_input = "__import__('os').system('ls')"
result = retrieve_value_from_database(user_input)
print(result)Patched code sample
import ast
def retrieve_value_from_database(db_value):
"""Secure function that fixes the vulnerability."""
# SECURE: This version prevents command injection
return ast.literal_eval(db_value)
user_input = "__import__('os').system('ls')"
result = retrieve_value_from_database(user_input)
print(result)Payload
"__import__('os').system('whoami')"
Cite this entry
@misc{vaitp:cve202421513,
title = {{Arbitrary Code Execution in langchain-experimental due to unsafe eval usage.}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2024},
note = {VAITP Python Vulnerability Dataset, entry CVE-2024-21513},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2024-21513/}}
}
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 ::
