VAITP Dataset

← Back to the dataset

CVE-2024-45858

Arbitrary code execution via malicious XML file in Guardrails framework.

  • CVSS 7.8
  • CWE-95
  • Input Validation and Sanitization
  • Remote

An arbitrary code execution vulnerability exists in versions 0.2.9 up to 0.5.10 of the Guardrails AI Guardrails framework because of the way it validates XML files. If a victim user loads a maliciously crafted XML file containing Python code, the code will be passed to an eval function, causing it to execute on the user's machine.

CVSS base score
7.8
Published
2024-09-18
OWASP
A01 Broken Access Control
Orthogonal defect classification
Checking
Code defect classification
Incorrect Check
Category
Input Validation and Sanitization
Subcategory
Insecure Parsing or Deserialization
Accessibility scope
Remote
Impact
Arbitrary Code Execution
Affected component
Guardrails A
Fixed by upgrading
Yes

Solution

Upgrade to version 0.5.11 or later.

Vulnerable code sample

import xml.etree.ElementTree as ET

def load_xml_and_execute(xml_string):
    root = ET.fromstring(xml_string)
    
    code_to_execute = root.find('code').text
    eval(code_to_execute)

xml = """<root>
    <code>print('This is an arbitrary code execution!')</code>
</root>"""

load_xml_and_execute(xml)

Patched code sample

import xml.etree.ElementTree as ET

def execute_action(action):
    actions = {
        "greet": lambda: print("Hello, safe world!"),
        "farewell": lambda: print("Goodbye, safe world!")
    }
    
    if action in actions:
        actions[action]()
    else:
        print("Invalid action.")

def load_xml_and_execute(xml_string):
    root = ET.fromstring(xml_string)
    code_to_execute = root.find('action').text
    execute_action(code_to_execute)

xml = """<root>
    <code>print('This is an arbitrary code execution!')</code>
</root>"""

load_xml_and_execute(xml)

Payload

<root>
    <code>os.system('whoami')</code>
</root>

Cite this entry

@misc{vaitp:cve202445858,
  title        = {{Arbitrary code execution via malicious XML file in Guardrails framework.}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2024},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2024-45858},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2024-45858/}}
}
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 ::