VAITP Dataset

← Back to the dataset

CVE-2021-45082

Cobbler before 3.3.1 allows Python module imports via "#from MODULE import" in templar.py, posing a security risk

  • CVSS 7.8
  • CWE-77 Improper Neutralization of Special Elements used in a Command ('Command Injection')
  • Input Validation and Sanitization
  • Remote

An issue was discovered in Cobbler before 3.3.1. In the templar.py file, the function check_for_invalid_imports can allow Cheetah code to import Python modules via the "#from MODULE import" substring. (Only lines beginning with #import are blocked.)

CVSS base score
7.8
Published
2022-02-19
OWASP
A06 Vulnerable and Outdated Components
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
Cobbler
Fixed by upgrading
Yes

Solution

Update Cobbler to version 3.3.1 or higher.

Vulnerable code sample

import re

def check_for_invalid_imports(template_code):
    # This regex matches lines that start with "#import" but allows "#from" imports
    if re.search(r'^\s*#import\s+', template_code, re.MULTILINE):
        raise ValueError("Import statements are not allowed in templates.")
    
    # This allows "#from MODULE import" which is a vulnerability
    # Additional logic to process the template code
    # ...

# Example usage
try:
    check_for_invalid_imports("""
    # This is a comment
    #from os import path  # This should not raise an error
    print("Hello, World!")
    """)
except ValueError as e:
    print(e)

Patched code sample

import re

def check_for_invalid_imports(template_code):
    # Block any import statements that are not preceded by a comment
    # This regex matches lines that start with "#from" or "#import"
    if re.search(r'^\s*#(from|import)\s+', template_code, re.MULTILINE):
        raise ValueError("Import statements are not allowed in templates.")
    
    # Additional logic to process the template code safely
    # ...

# Example usage
try:
    check_for_invalid_imports("""
    # This is a comment
    #from os import path  # This should raise an error
    print("Hello, World!")
    """)
except ValueError as e:
    print(e)

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:cve202145082,
  title        = {{Cobbler before 3.3.1 allows Python module imports via "#from MODULE import" in templar.py, posing a security risk}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2022},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2021-45082},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2021-45082/}}
}

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.