VAITP Dataset

← Back to the dataset

CVE-2021-32811

Zope < 4.6.3 & 5.3, Python 3, Products.PythonScripts package, RCE, Zope Manager role

  • CVSS 7.2
  • CWE-1321
  • Design Defects
  • Remote

Zope is an open-source web application server. Zope versions prior to versions 4.6.3 and 5.3 have a remote code execution security issue. In order to be affected, one must use Python 3 for one's Zope deployment, run Zope 4 below version 4.6.3 or Zope 5 below version 5.3, and have the optional `Products.PythonScripts` add-on package installed. By default, one must have the admin-level Zope "Manager" role to add or edit Script (Python) objects through the web. Only sites that allow untrusted users to add/edit these scripts through the web are at risk. Zope releases 4.6.3 and 5.3 are not vulnerable. As a workaround, a site administrator can restrict adding/editing Script (Python) objects through the web using the standard Zope user/role permission mechanisms. Untrusted users should not be assigned the Zope Manager role and adding/editing these scripts through the web should be restricted to trusted users only. This is the default configuration in Zope.

CVSS base score
7.2
Published
2021-08-02
OWASP
A05 Security Misconfiguration
Orthogonal defect classification
Checking
Code defect classification
Incorrect Check
Category
Design Defects
Subcategory
Security Misconfigurations
Accessibility scope
Remote
Impact
Arbitrary Code Execution
Affected component
Zope
Fixed by upgrading
Yes

Solution

Update Zope to version 4.6.3 or 5.3, restrict Script (Python) object access to trusted users.

Vulnerable code sample

# Vulnerable Python script in Zope that demonstrates the RCE vulnerability
def execute_user_code():
    # Simulating a scenario where untrusted user input is executed
    user_code = request.form.get('user_code')  # User-supplied code
    exec(user_code)  # Dangerous: executes arbitrary code from user input

# Example of a Zope script that could be added by an untrusted user
def malicious_script():
    # This function could be added by an untrusted user
    import os
    os.system('rm -rf /')  # Example of a harmful command

Patched code sample

# Example of a vulnerable Python script in Zope
# This code simulates a remote code execution vulnerability
def vulnerable_script():
    # This is an example of executing arbitrary code from user input
    user_input = request.form.get('code')  # Unsanitized user input
    exec(user_input)  # Vulnerable to RCE

# Fix for the vulnerability
def safe_script():
    # Instead of executing arbitrary code, restrict operations
    allowed_commands = {
        'allowed_function': allowed_function,
        # Add other allowed functions here
    }
    
    user_command = request.form.get('command')
    if user_command in allowed_commands:
        allowed_commands[user_command]()  # Only execute allowed commands
    else:
        raise PermissionError("Unauthorized command.")

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:cve202132811,
  title        = {{Zope < 4.6.3 & 5.3, Python 3, Products.PythonScripts package, RCE, Zope Manager role}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2021},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2021-32811},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2021-32811/}}
}

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.