VAITP Dataset

← Back to the dataset

CVE-2023-26145

Command Injection in pydash < 6.0.0 allows arbitrary code execution via manipulated arguments

  • CVSS 8.1
  • CWE-77 Improper Neutralization of Special Elements used in a Command ('Command Injection')
  • Input Validation and Sanitization
  • Remote

This affects versions of the package pydash before 6.0.0. A number of pydash methods such as pydash.objects.invoke() and pydash.collections.invoke_map() accept dotted paths (Deep Path Strings) to target a nested Python object, relative to the original source object. These paths can be used to target internal class attributes and dict items, to retrieve, modify or invoke nested Python objects. The pydash.objects.invoke() method is vulnerable to Command Injection when the following prerequisites are satisfied: 1) The source object (argument 1) is not a built-in object such as list/dict (otherwise, the __init__.__globals__ path is not accessible). 2) The attacker has control over argument 2 (the path string) and argument 3 (the argument to pass to the invoked method). The pydash.collections.invoke_map() method is also vulnerable, but is harder to exploit as the attacker does not have direct control over the argument to be passed to the invoked function.

CVSS base score
8.1
Published
2023-09-28
OWASP
A03 Injection
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
pydash
Fixed by upgrading
Yes

Solution

Update pydash to version 6.0.0 or higher.

Vulnerable code sample

import pydash

class MyClass:
    def my_method(self, arg):
        return f"Method called with argument: {arg}"

obj = MyClass()
# User-controlled input that could be exploited
path = "__init__.__globals__['os'].system"  # Example of a dangerous path
command = "echo Vulnerable!"  # Command to execute

# This will invoke the command due to the vulnerability
result = pydash.objects.invoke(obj, path, command)
print(result)

Patched code sample

import pydash

def safe_invoke(source, path, *args, **kwargs):
    # Ensure the path does not contain any dangerous patterns
    if '..' in path or path.startswith('/') or path.startswith('..'):
        raise ValueError("Invalid path provided.")
    
    # Use pydash's invoke safely
    return pydash.objects.invoke(source, path, *args, **kwargs)

# Example usage
class MyClass:
    def my_method(self, arg):
        return f"Method called with argument: {arg}"

obj = MyClass()
path = "my_method"  # Safe path
result = safe_invoke(obj, path, "test argument")
print(result)

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.

Cite this entry

@misc{vaitp:cve202326145,
  title        = {{Command Injection in pydash < 6.0.0 allows arbitrary code execution via manipulated arguments}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2023},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2023-26145},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2023-26145/}}
}

Download this entry as JSON Download the whole dataset

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 ::

Before you use the VAITP AI models

Please read and accept the following disclaimer:

By choosing "I understand and accept", you acknowledge that you understand and agree to these terms.