CVE-2022-39286 (published 2022-10-26T20:15Z)

Jupyter Core is a package for the core common functionality of Jupyter projects. Jupyter Core prior to version 4.11.2 contains an arbitrary code execution vulnerability in `jupyter_core` that stems from `jupyter_core` executing untrusted files in CWD. This vulnerability allows one user to run code as another. Version 4.11.2 contains a patch for this issue. There are no known workarounds.

CVSS v3 base score: 8.8, HIGH (CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H)

Weakness information:
cwe_id: CWE-427
cwe_name: Uncontrolled Search Path Element
description: The product uses a fixed or controlled search path to find resources, but one or more locations in that path can be under the control of unintended actors.
extended_description: 
            Although this weakness can occur with any type of resource, it is frequently introduced when a product uses a directory search path to find executables or code libraries, but the path contains a directory that can be modified by an attacker, such as "/tmp" or the current working directory.
            In Windows-based systems, when the LoadLibrary or LoadLibraryEx function is called with a DLL name that does not contain a fully qualified path, the function follows a search order that includes two path elements that might be uncontrolled:
               
                  the directory from which the program has been loaded
                  the current working directory
               
            In some cases, the attack can be conducted remotely, such as when SMB or WebDAV network shares are used.
	    One or more locations in that path could include the Windows drive root or its subdirectories. This often exists in Linux-based code assuming the controlled nature of the root directory (/) or its subdirectories (/etc, etc), or a code that recursively accesses the parent directory.  In Windows, the drive root and some of its subdirectories have weak permissions by default, which makes them uncontrolled.
            In some Unix-based systems, a PATH might be created that contains an empty element, e.g. by splicing an empty variable into the PATH. This empty element can be interpreted as equivalent to the current working directory, which might be an untrusted search element.
            In software package management frameworks (e.g., npm, RubyGems, or PyPi), the framework may identify dependencies on third-party libraries or other packages, then consult a repository that contains the desired package. The framework may search a public repository before a private repository. This could be exploited by attackers by placing a malicious package in the public repository that has the same name as a package from the private repository. The search path might not be directly under control of the developer relying on the framework, but this search order effectively contains an untrusted element.
         
         

Fix information:
repo_url: https://github.com/jupyter/jupyter_core
commit_details: repo_url: https://github.com/jupyter/jupyter_core
author: Steven Silvester
author_date: 2022-10-19 09:05:21-05:00
msg: Merge pull request from GHSA-m678-f26j-3hrp
repository: repo_url: https://github.com/jupyter/jupyter_core
repo_name: jupyter/jupyter_core
description: Core Jupyter functionality
repo_language: Python
owner: jupyter
file_changes: filename: application.py
change_type: ModificationType.MODIFY
diff: @@ -88,8 +88,8 @@ class JupyterApp(Application):
     def config_file_paths(self):
         path = jupyter_config_path()
         if self.config_dir not in path:
+            # Insert config dir as first item.
             path.insert(0, self.config_dir)
-        path.insert(0, os.getcwd())
         return path
 
     data_dir = Unicode()

programming_language: Python
filename: test_application.py
change_type: ModificationType.MODIFY
diff: @@ -69,25 +69,33 @@ def test_generate_config():
 
 def test_load_config():
     config_dir = mkdtemp()
-    wd = mkdtemp()
+    os.environ["JUPYTER_CONFIG_PATH"] = str(config_dir)
     with open(pjoin(config_dir, "dummy_app_config.py"), "w", encoding="utf-8") as f:
         f.write("c.DummyApp.m = 1\n")
         f.write("c.DummyApp.n = 1")
-    with patch.object(os, "getcwd", lambda: wd):
-        app = DummyApp(config_dir=config_dir)
-        app.initialize([])
+
+    app = DummyApp(config_dir=config_dir)
+    app.initialize([])
 
     assert app.n == 1, "Loaded config from config dir"
+    assert app.m == 1, "Loaded config from config dir"
+
+    shutil.rmtree(config_dir)
+    del os.environ["JUPYTER_CONFIG_PATH"]
 
-    with open(pjoin(wd, "dummy_app_config.py"), "w", encoding="utf-8") as f:
-        f.write("c.DummyApp.n = 2")
 
+def test_load_config_no_cwd():
+    config_dir = mkdtemp()
+    wd = mkdtemp()
+    with open(pjoin(wd, "dummy_app_config.py"), "w", encoding="utf-8") as f:
+        f.write("c.DummyApp.m = 1\n")
+        f.write("c.DummyApp.n = 1")
     with patch.object(os, "getcwd", lambda: wd):
         app = DummyApp(config_dir=config_dir)
         app.initialize([])
 
-    assert app.m == 1, "Loaded config from config dir"
-    assert app.n == 2, "Loaded config from CWD"
+    assert app.n == 0
+    assert app.m == 0
 
     shutil.rmtree(config_dir)
     shutil.rmtree(wd)
@@ -95,17 +103,17 @@ def test_load_config():
 
 def test_load_bad_config():
     config_dir = mkdtemp()
-    wd = mkdtemp()
+    os.environ["JUPYTER_CONFIG_PATH"] = str(config_dir)
     with open(pjoin(config_dir, "dummy_app_config.py"), "w", encoding="utf-8") as f:
         f.write('c.DummyApp.m = "a\n')  # Syntax error
-    with patch.object(os, "getcwd", lambda: wd):
-        with pytest.raises(SyntaxError):
-            app = DummyApp(config_dir=config_dir)
-            app.raise_config_file_errors = True
-            app.initialize([])
+
+    with pytest.raises(SyntaxError):
+        app = DummyApp(config_dir=config_dir)
+        app.raise_config_file_errors = True
+        app.initialize([])
 
     shutil.rmtree(config_dir)
-    shutil.rmtree(wd)
+    del os.environ["JUPYTER_CONFIG_PATH"]
 
 
 def test_runtime_dir_changed():

programming_language: Python