CVE-2024-5565
Prompt injection in Vanna library allows remote code execution.
- CVSS 8.1
- CWE-94
- Input Validation and Sanitization
- Remote
The Vanna library uses a prompt function to present the user with visualized results, it is possible to alter the prompt using prompt injection and run arbitrary Python code instead of the intended visualization code. Specifically – allowing external input to the library’s “ask” method with "visualize" set to True (default behavior) leads to remote code execution.
- CWE
- CWE-94
- CVSS base score
- 8.1
- Published
- 2024-05-31
- 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
- Fixed by upgrading
- Yes
Solution
Upgrade the Vanna library to version 2.1.0 or later, which includes input validation and sanitization for the prompt function.
Vulnerable code sample
class Vanna:
def ask(self, prompt, visualize=True):
"""Vulnerable function that demonstrates the security issue."""
if visualize:
exec(prompt)
else:
print(f"Input received: {prompt}")
vanna = Vanna()
vanna.ask("import os; os.system('echo Vulnerable!')")Patched code sample
class Vanna:
def __init__(self):
"""Secure function that fixes the vulnerability."""
self.blacklist = [
'import os', 'os.system', 'subprocess', '__import__',
'eval', 'exec', 'open(', 'compile', 'input(', 'globals', 'locals'
]
def check(self, prompt):
"""Secure function that fixes the vulnerability."""
lowered = prompt.lower()
return not any(black_item in lowered for black_item in self.blacklist):
def ask(self, prompt, visualize=True):
"""Secure function that fixes the vulnerability."""
if visualize:
if self.check(prompt):
exec(prompt)
else:
print("Execution blocked.")
else:
print(f"Input received: {prompt}")
vanna = Vanna()
vanna.ask("import os; os.system('echo Vulnerable!')")Payload
"__import__('os').system('echo Vulnerable!')"
Cite this entry
@misc{vaitp:cve20245565,
title = {{Prompt injection in Vanna library allows remote code execution.}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2024},
note = {VAITP Python Vulnerability Dataset, entry CVE-2024-5565},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2024-5565/}}
}
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 ::
