VAITP Dataset

← Back to the dataset

CVE-2022-45132

Linaro LAVA (before 2022.11.1) RCE via user Jinja2 template in device config validation

  • CVSS 9.8
  • CWE-94 Improper Control of Generation of Code ('Code Injection')
  • Input Validation and Sanitization
  • Remote

In Linaro Automated Validation Architecture (LAVA) before 2022.11.1, remote code execution can be achieved through user-submitted Jinja2 template. The REST API endpoint for validating device configuration files in lava-server loads input as a Jinja2 template in a way that can be used to trigger remote code execution in the LAVA server.

CVSS base score
9.8
Published
2022-11-18
OWASP
A03 Injection
Orthogonal defect classification
Function
Code defect classification
Incorrect Functionality
Category
Input Validation and Sanitization
Subcategory
Insecure Parsing or Deserialization
Accessibility scope
Remote
Impact
Arbitrary Code Execution
Affected component
Jinja2
Fixed by upgrading
Yes

Solution

Update LAVA to version 2022.11.1 or higher.

Vulnerable code sample

from jinja2 import Environment, FileSystemLoader

# Create a Jinja2 environment without autoescaping
env = Environment(
    loader=FileSystemLoader('templates')
)

def render_template(template_name, context):
    # Render the template with the provided context
    template = env.get_template(template_name)
    return template.render(context)

# Example usage
if __name__ == "__main__":
    user_input = input("Enter template name: ")
    user_context = {
        'user_input': user_input  # Directly using user input in context
    }
    output = render_template(user_input, user_context)
    print(output)

Patched code sample

from jinja2 import Environment, FileSystemLoader, select_autoescape

# Create a Jinja2 environment with autoescaping enabled
env = Environment(
    loader=FileSystemLoader('templates'),
    autoescape=select_autoescape(['html', 'xml'])  # Only allow specific file types
)

def render_template(template_name, context):
    # Render the template with the provided context safely
    template = env.get_template(template_name)
    return template.render(context)

# Example usage
if __name__ == "__main__":
    safe_context = {
        'key': 'value'  # Only include safe variables
    }
    output = render_template('safe_template.html', safe_context)
    print(output)

Cite this entry

@misc{vaitp:cve202245132,
  title        = {{Linaro LAVA (before 2022.11.1) RCE via user Jinja2 template in device config validation}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2022},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2022-45132},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2022-45132/}}
}

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.