CVE-2021-41150
Vulnerability pre-version 0.12.0 Rust library: File overwrite via improper role name sanitization in TUF repositories
- CVSS 6.5
- CWE-22 Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')
- Input Validation and Sanitization
- Remote
Tough provides a set of Rust libraries and tools for using and generating the update framework (TUF) repositories. The tough library, prior to 0.12.0, does not properly sanitize delegated role names when caching a repository, or when loading a repository from the filesystem. When the repository is cached or loaded, files ending with the .json extension could be overwritten with role metadata anywhere on the system. A fix is available in version 0.12.0. No workarounds to this issue are known.
- CVSS base score
- 6.5
- Published
- 2021-10-19
- OWASP
- A08 Software and Data Integrity Failures
- Orthogonal defect classification
- Function
- Code defect classification
- Incorrect Functionality
- Category
- Input Validation and Sanitization
- Subcategory
- Path Traversal
- Accessibility scope
- Remote
- Impact
- Arbitrary Code Execution
- Affected component
- tough
- Fixed by upgrading
- Yes
Solution
Update to tough library version 0.12.0 or higher.
Vulnerable code sample
import os
import json
def load_repository(repository_path):
# Load roles without proper sanitization
roles = {}
for filename in os.listdir(repository_path):
if filename.endswith('.json'):
role_name = os.path.splitext(filename)[0]
# Unsanitized role name allows for potential overwriting
with open(os.path.join(repository_path, filename), 'r') as f:
roles[role_name] = json.load(f)
# Potentially dangerous operation: could overwrite any .json file
with open(f"{role_name}.json", 'w') as f:
json.dump(roles[role_name], f)
return roles
# Example usage
repository = load_repository('/path/to/repository')Patched code sample
import os
import json
def safe_load_repository(repository_path):
# Ensure the repository path is valid and does not contain malicious role names
if not os.path.isdir(repository_path):
raise ValueError("Invalid repository path")
# Load roles safely
roles = {}
for filename in os.listdir(repository_path):
if filename.endswith('.json'):
role_name = os.path.splitext(filename)[0]
# Sanitize role name to prevent directory traversal or overwriting
if not is_safe_role_name(role_name):
raise ValueError(f"Unsafe role name detected: {role_name}")
with open(os.path.join(repository_path, filename), 'r') as f:
roles[role_name] = json.load(f)
return roles
def is_safe_role_name(role_name):
# Implement sanitization logic, e.g., disallow certain characters or patterns
return all(c.isalnum() or c in ('-', '_') for c in role_name)
# Example usage
try:
repository = safe_load_repository('/path/to/repository')
except ValueError as e:
print(f"Error loading repository: {e}")Cite this entry
@misc{vaitp:cve202141150,
title = {{Vulnerability pre-version 0.12.0 Rust library: File overwrite via improper role name sanitization in TUF repositories}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2021},
note = {VAITP Python Vulnerability Dataset, entry CVE-2021-41150},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2021-41150/}}
}
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 ::
