CVE-2023-41039
Format string allows information disclosure in RestrictedPython
- CVSS 7.7
- CWE-74 Improper Neutralization of Special Elements in Output Used by a Downstream Component ('Injection')
- Information Leakage
- Remote
RestrictedPython is a restricted execution environment for Python to run untrusted code. Python's "format" functionality allows someone controlling the format string to "read" all objects accessible through recursive attribute lookup and subscription from objects he can access. This can lead to critical information disclosure. With `RestrictedPython`, the format functionality is available via the `format` and `format_map` methods of `str` (and `unicode`) (accessed either via the class or its instances) and via `string.Formatter`. All known versions of `RestrictedPython` are vulnerable. This issue has been addressed in commit `4134aedcff1` which has been included in the 5.4 and 6.2 releases. Users are advised to upgrade. There are no known workarounds for this vulnerability.
- CVSS base score
- 7.7
- Published
- 2023-08-30
- OWASP
- A05 Security Misconfiguration
- Orthogonal defect classification
- Function
- Code defect classification
- Incorrect Functionality
- Category
- Information Leakage
- Subcategory
- Information Disclosure
- Accessibility scope
- Remote
- Impact
- Information Disclosure
- Fixed by upgrading
- Yes
Solution
Update to RestrictedPython version 5.4 or 6.2 or higher.
Vulnerable code sample
def format_string(format_string, user):
return format_string.format(user=user)
user_data = {'name': 'Alice', 'secret': 'This is a secret!'}
format_string = "Hello, {user.name}. Your secret is: {user.secret}"
result = format_string(format_string, user_data)
print(result)Patched code sample
def format_string(format_string, user):
allowed_fields = {
'name': user.get('name')
}
return format_string.format(user=allowed_fields)
user_data = {'name': 'Alice', 'secret': 'This is a secret!'}
format_string_input = "Hello, {user[name]}."
result = format_string(format_string_input, user_data)
print(result)Cite this entry
@misc{vaitp:cve202341039,
title = {{Format string allows information disclosure in RestrictedPython}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2023},
note = {VAITP Python Vulnerability Dataset, entry CVE-2023-41039},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2023-41039/}}
}
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 ::
