CVE-2023-24816
IPython < 8.1.0 has a command injection flaw via set_term_title with untrusted input, enabling potential shell command injection
- CVSS 7.0
- CWE-78
- Input Validation and Sanitization
- Local
IPython (Interactive Python) is a command shell for interactive computing in multiple programming languages, originally developed for the Python programming language. Versions prior to 8.1.0 are subject to a command injection vulnerability with very specific prerequisites. This vulnerability requires that the function `IPython.utils.terminal.set_term_title` be called on Windows in a Python environment where ctypes is not available. The dependency on `ctypes` in `IPython.utils._process_win32` prevents the vulnerable code from ever being reached in the ipython binary. However, as a library that could be used by another tool `set_term_title` could be called and hence introduce a vulnerability. Should an attacker get untrusted input to an instance of this function they would be able to inject shell commands as current process and limited to the scope of the current process. Users of ipython as a library are advised to upgrade. Users unable to upgrade should ensure that any calls to the `IPython.utils.terminal.set_term_title` function are done with trusted or filtered input.
- CWE
- CWE-78
- CVSS base score
- 7.0
- Published
- 2023-02-10
- OWASP
- A03 Injection
- Orthogonal defect classification
- Function
- Code defect classification
- Incorrect Functionality
- Category
- Input Validation and Sanitization
- Subcategory
- Command Injection
- Accessibility scope
- Local
- Impact
- Arbitrary Code Execution
- Affected component
- IPython
- Fixed by upgrading
- Yes
Solution
Upgrade IPython to version 8.1.0 or higher.
Vulnerable code sample
import IPython.utils.terminal
# Vulnerable code that allows command injection if untrusted input is passed
def vulnerable_set_term_title(title):
# Directly using the input without validation
IPython.utils.terminal.set_term_title(title)
# Example of potentially unsafe usage
user_input = input("Enter terminal title: ")
vulnerable_set_term_title(user_input)Patched code sample
import IPython.utils.terminal
def safe_set_term_title(title):
# Ensure the title is safe and does not contain any shell metacharacters
if any(char in title for char in [';', '&', '|', '>', '<', '$', '`']):
raise ValueError("Unsafe title provided")
IPython.utils.terminal.set_term_title(title)
# Example usage
try:
safe_set_term_title("My Safe Title")
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.
- Fix CVE-2023-24816 by removing legacy code. (ipython/ipython)
IPython/utils/terminal.py,IPython/__init__.py
Cite this entry
@misc{vaitp:cve202324816,
title = {{IPython < 8.1.0 has a command injection flaw via set_term_title with untrusted input, enabling potential shell command injection}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2023},
note = {VAITP Python Vulnerability Dataset, entry CVE-2023-24816},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2023-24816/}}
}
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 ::
