Skip to content

Commit

Permalink
Fix CVE-2023-24816 by removing legacy code.
Browse files Browse the repository at this point in the history
Remove legacy code that might trigger a CVE.

Currently set_term_title is only called with (semi-)trusted input that
contain the current working directory of the current IPython session. If
an attacker can control directory names, and manage to get a user cd
into this directory the attacker can execute arbitrary commands
contained in the folder names.

Example:

    - On a windows machine where python is built without _ctypes, create
      a folder called && echo "pwn" > pwn.txt. This can be done by for
      example cloning a git repository.
    - call toggled_set_term_title(True), (or have the preference to
      true)
    - Open IPython and cd into this directory.
    - the folder now contain a pwn.txt, with pwn as content, despite the
      user not asking for any code execution.

Workaround:

    Set the configuration option
    c.TerminalInteractiveShell.term_title_format='IPython' (or to any
    other fixed, safe string).
  • Loading branch information
weddige authored and Carreau committed Feb 7, 2023
1 parent 56e6925 commit 991849c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 25 deletions.
2 changes: 1 addition & 1 deletion IPython/__init__.py
Expand Up @@ -63,7 +63,7 @@
version_info = release.version_info
# list of CVEs that should have been patched in this release.
# this is informational and should not be relied upon.
__patched_cves__ = {"CVE-2022-21699"}
__patched_cves__ = {"CVE-2022-21699", "CVE-2023-24816"}


def embed_kernel(module=None, local_ns=None, **kwargs):
Expand Down
32 changes: 8 additions & 24 deletions IPython/utils/terminal.py
Expand Up @@ -91,30 +91,14 @@ def _restore_term_title_xterm():
_set_term_title = _set_term_title_xterm
_restore_term_title = _restore_term_title_xterm
elif sys.platform == 'win32':
try:
import ctypes

SetConsoleTitleW = ctypes.windll.kernel32.SetConsoleTitleW
SetConsoleTitleW.argtypes = [ctypes.c_wchar_p]

def _set_term_title(title):
"""Set terminal title using ctypes to access the Win32 APIs."""
SetConsoleTitleW(title)
except ImportError:
def _set_term_title(title):
"""Set terminal title using the 'title' command."""
global ignore_termtitle

try:
# Cannot be on network share when issuing system commands
curr = os.getcwd()
os.chdir("C:")
ret = os.system("title " + title)
finally:
os.chdir(curr)
if ret:
# non-zero return code signals error, don't try again
ignore_termtitle = True
import ctypes

SetConsoleTitleW = ctypes.windll.kernel32.SetConsoleTitleW
SetConsoleTitleW.argtypes = [ctypes.c_wchar_p]

def _set_term_title(title):
"""Set terminal title using ctypes to access the Win32 APIs."""
SetConsoleTitleW(title)


def set_term_title(title):
Expand Down
12 changes: 12 additions & 0 deletions docs/source/whatsnew/version8.rst
Expand Up @@ -2,6 +2,18 @@
8.x Series
============


IPython 8.9.1
-------------

Out of schedule release of IPython with minor fixes to patch a potential CVE-2023-24816.
This is a really low severity CVE that you most likely are not affected by unless:

- You are on windows.
- You have a custom build of Python without ``_ctypes``
- You cd or start IPython or Jupyter in untrusted directory which names may be valid shell commands.


.. _version 8.9.0:

IPython 8.9.0
Expand Down

0 comments on commit 991849c

Please sign in to comment.