VAITP Dataset

← Back to the dataset

CVE-2025-30358

Mesop Python UI framework < 0.14.1 vulnerable to class pollution, DoS, and potential RCE.

  • CVSS 8.1
  • CWE-915
  • Design Defects
  • Remote

Mesop is a Python-based UI framework that allows users to build web applications. A class pollution vulnerability in Mesop prior to version 0.14.1 allows attackers to overwrite global variables and class attributes in certain Mesop modules during runtime. This vulnerability could directly lead to a denial of service (DoS) attack against the server. Additionally, it could also result in other severe consequences given the application's implementation, such as identity confusion, where an attacker could impersonate an assistant or system role within conversations. This impersonation could potentially enable jailbreak attacks when interacting with large language models (LLMs). Just like the Javascript's prototype pollution, this vulnerability could leave a way for attackers to manipulate the intended data-flow or control-flow of the application at runtime and lead to severe consequences like remote code execution when gadgets are available. Users should upgrade to version 0.14.1 to obtain a fix for the issue.

CVSS base score
8.1
Published
2025-03-27
OWASP
A08 Software and Data Integrity Failures
Orthogonal defect classification
Interface
Code defect classification
Incorrect Functionality
Category
Design Defects
Subcategory
Insecure Parsing or Deserialization
Accessibility scope
Remote
Impact
Denial of Service (DoS)
Affected component
Mesop
Fixed by upgrading
Yes

Solution

Upgrade to version 0.14.1.

Vulnerable code sample

# WARNING: This code is for demonstration purposes only and should not be used in a production environment.
# It demonstrates a potential vulnerability similar to CVE-2025-30358 and should be treated as unsafe.

import mesop
from mesop import component

# Simulate a vulnerable component that processes user-provided data
@component
def VulnerableComponent(data: dict):
  """
  This component takes a dictionary as input and naively updates the component's
  attributes based on the provided data. This could lead to class pollution if
  the data contains keys that correspond to attributes Mesop internally uses or
  are inherited from a parent class.
  """
  for key, value in data.items():
    setattr(VulnerableComponent, key, value) # Direct attribute assignment based on user input
  return mesop.text(f"Data processed: {data}")


@mesop.page(path="/")
def index():
  # Simulate user-provided data that could potentially overwrite critical attributes
  # A real exploit would likely source this data from user input (e.g., a query parameter,
  # a form submission, or an API endpoint).
  malicious_data = {
      "__class__": "<script>alert('XSS')</script>", #Example of class pollution
      "__name__": "EvilComponent"
  }

  VulnerableComponent(data=malicious_data)

Patched code sample

def sanitize_input(data):
    """
    Sanitizes the input data to prevent class pollution.

    Args:
        data: The input data (e.g., a dictionary) to be sanitized.

    Returns:
        A sanitized version of the input data, or the original data if no
        malicious patterns are detected.  Returns an empty dictionary if
        the input is malicious.
    """
    if not isinstance(data, dict):
        return data

    # Check for potentially malicious keys.  This example focuses on keys
    # that could target built-in Python classes or sensitive Mesop modules.
    # The actual list of prohibited keys would depend on the specific
    # internal structure of Mesop and the modules it uses.
    prohibited_keys = ["__class__", "__mro__", "__base__", "object", "type"]

    for key in data:
        if key in prohibited_keys:
            print(f"Detected prohibited key: {key}.  Input rejected.")
            return {}  # Or raise an exception: raise ValueError("Invalid input")

        # Recursively sanitize nested dictionaries
        if isinstance(data[key], dict):
            data[key] = sanitize_input(data[key])

    return data


def process_user_input(user_input):
    """
    Processes user input after sanitization.

    Args:
        user_input: The user input dictionary.

    Returns:
        The processed user input, or None if the input was invalid.
    """
    sanitized_input = sanitize_input(user_input)

    if not sanitized_input:
        print("Invalid user input. Processing stopped.")
        return None

    # Now you can safely use the sanitized_input.
    # Example usage:
    # For example, create a class where attributes are set based on the user input.

    class UserData:
        def __init__(self, data):
            for key, value in data.items():
                setattr(self, key, value)

    try:
        user_data = UserData(sanitized_input)
        # ... further processing with user_data ...
        return user_data

    except Exception as e:  # Catch errors that might still occur during object creation
        print(f"Error processing user input: {e}")
        return None


# Example usage (Demonstrates mitigation)
if __name__ == "__main__":
    # Malicious input example attempting to pollute the class
    malicious_input = {"__class__": {"__mro__": [object, {"new_attribute": "malicious_value"}]}}

    # Correct usage Example
    user_input = {"username": "test_user", "email": "test@example.com"}


    result_malicious = process_user_input(malicious_input)
    result_correct = process_user_input(user_input)

    if result_malicious is None:
        print("Malicious input was correctly blocked.")
    else:
        print("Malicious input was not blocked!")


    if result_correct is not None:
        print("Correct input was processed.")
        print(f"Username: {result_correct.username}, Email: {result_correct.email}")
    else:
        print("Correct input was not processed")

Payload

{
    "__class__": {
        "__module__": "mesop.components.text.text",
        "Text": {
            "__new__": {
                "__defaults__": {
                    "__class__": {
                        "__module__": "builtins",
                        "str": {
                            "__new__": {
                                "__defaults__": ["evil_string"]
                            }
                        }
                    }
                }
            }
        }
    }
}

Cite this entry

@misc{vaitp:cve202530358,
  title        = {{Mesop Python UI framework < 0.14.1 vulnerable to class pollution, DoS, and potential RCE.
}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2025},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2025-30358},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2025-30358/}}
}
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 ::