VAITP Dataset

← Back to the dataset

CVE-2021-23422

Arbitrary OS command execution via untrusted Bikeshed Inline Tag Command metadata (pre-3.0.0)

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

This affects the package bikeshed before 3.0.0. This can occur when an untrusted source file containing Inline Tag Command metadata is processed. When an arbitrary OS command is executed, the command output would be included in the HTML output.

CVSS base score
7.8
Published
2021-08-16
OWASP
A03 Injection
Orthogonal defect classification
Function
Code defect classification
Incorrect Functionality
Category
Input Validation and Sanitization
Subcategory
Command Injection
Accessibility scope
Remote
Impact
Arbitrary Code Execution
Affected component
bikeshed
Fixed by upgrading
Yes

Solution

Update bikeshed to version 3.0.0 or higher.

Vulnerable code sample

import subprocess

def process_command(command):
    # Directly executing the command without validation
    result = subprocess.run(command, capture_output=True, text=True, shell=True)
    return result.stdout  # Output is returned directly

# Example usage
user_input = "ls; rm -rf /"  # Simulated user input with a malicious command
output = process_command(user_input)
print(f"<pre>{output}</pre>")

Patched code sample

import subprocess
import html

def safe_process_command(command):
    # Validate the command to prevent arbitrary command execution
    allowed_commands = {'ls', 'echo'}  # Define a whitelist of allowed commands
    command_parts = command.split()
    
    if command_parts[0] in allowed_commands:
        # Use subprocess.run with shell=False to prevent shell injection
        result = subprocess.run(command_parts, capture_output=True, text=True)
        return html.escape(result.stdout)  # Escape output for safe HTML rendering
    else:
        raise ValueError("Command not allowed")

# Example usage
try:
    user_input = "ls"  # Simulated user input
    output = safe_process_command(user_input)
    print(f"<pre>{output}</pre>")
except ValueError as e:
    print(f"Error: {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.

  • Prevent escaping the source doc's folder, or running arbitrary code, without explicit opt-in at the command-line. (tabatkins/bikeshed)
    bikeshed/cli.py · main, bikeshed/config/main.py, bikeshed/config/main.py · scriptPath, bikeshed/config/retrieve.py · retrieveBoilerplateFile, bikeshed/constants.py, bikeshed/extensions.py, bikeshed/extensions.py · load, bikeshed/inlineTags/__init__.py, bikeshed/inlineTags/__init__.py · processTags, bikeshed/InputSource.py, bikeshed/InputSource.py · FileInputSource.relative, bikeshed/InputSource.py · FileInputSource.__init__ and 2 more

Cite this entry

@misc{vaitp:cve202123422,
  title        = {{Arbitrary OS command execution via untrusted Bikeshed Inline Tag Command metadata (pre-3.0.0)}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2021},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2021-23422},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2021-23422/}}
}

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.