CVE-2024-22421 (published 2024-01-19T21:15Z)

JupyterLab is an extensible environment for interactive and reproducible computing, based on the Jupyter Notebook and Architecture. Users of JupyterLab who click on a malicious link may get their `Authorization` and `XSRFToken` tokens exposed to a third party when running an older `jupyter-server` version. JupyterLab versions 4.1.0b2, 4.0.11, and 3.6.7 are patched. No workaround has been identified, however users should ensure to upgrade `jupyter-server` to version 2.7.2 or newer which includes a redirect vulnerability fix.

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

Weakness information:
cwe_id: CWE-200
cwe_name: Exposure of Sensitive Information to an Unauthorized Actor
description: The product exposes sensitive information to an actor that is not explicitly authorized to have access to that information.
extended_description: 
	   There are many different kinds of mistakes that introduce information exposures. The severity of the error can range widely, depending on the context in which the product operates, the type of sensitive information that is revealed, and the benefits it may provide to an attacker.  Some kinds of sensitive information include:
       
         private, personal information, such as personal messages, financial data, health records, geographic location, or contact details
         system status and environment, such as the operating system and installed packages
		 business secrets and intellectual property
		 network status and configuration
		 the product's own code or internal state
         metadata, e.g. logging of connections or message headers
		 indirect information, such as a discrepancy between two internal operations that can be observed by an outsider
       
	    Information might be sensitive to different parties, each of which may have their own expectations for whether the information should be protected.  These parties include:
               
                  the product's own users
                  people or organizations whose information is created or used by the product, even if they are not direct product users
		  the product's administrators, including the admins of the system(s) and/or networks on which the product operates
                  the developer
               
	    Information exposures can occur in different ways:
               
                  the code explicitly inserts sensitive information into resources or messages that are intentionally made accessible to unauthorized actors, but should not contain the information - i.e., the information should have been "scrubbed" or "sanitized"
                  a different weakness or mistake indirectly inserts the sensitive information into resources, such as a web script error revealing the full system path of the program.
                  the code manages resources that intentionally contain sensitive information, but the resources are unintentionally made accessible to unauthorized actors. In this case, the information exposure is resultant - i.e., a different weakness enabled the access to the information in the first place.
               
	    It is common practice to describe any loss of confidentiality as an "information exposure," but this can lead to overuse of CWE-200 in CWE mapping. From the CWE perspective, loss of confidentiality is a technical impact that can arise from dozens of different weaknesses, such as insecure file permissions or out-of-bounds read.  CWE-200 and its lower-level descendants are intended to cover the mistakes that occur in behaviors that explicitly manage, store, transfer, or cleanse sensitive information.
         
         
cwe_id: CWE-23
cwe_name: Relative Path Traversal
description: The product uses external input to construct a pathname that should be within a restricted directory, but it does not properly neutralize sequences such as ".." that can resolve to a location that is outside of that directory.
extended_description: This allows attackers to traverse the file system to access files or directories that are outside of the restricted directory.
         

Fix information:
repo_url: https://github.com/jupyterlab/jupyterlab
commit_details: repo_url: https://github.com/jupyterlab/jupyterlab
author: Michał Krassowski
author_date: 2024-01-19 13:15:40+00:00
msg: Merge pull request from GHSA-44cc-43rp-5947

Co-authored-by: Frédéric Collonval <fcollonval@users.noreply.github.com>
repository: repo_url: https://github.com/jupyterlab/jupyterlab
repo_name: jupyterlab/jupyterlab
description: JupyterLab computational environment.
repo_language: TypeScript
owner: jupyterlab
file_changes: filename: workspacesplugin.ts
change_type: ModificationType.MODIFY
diff: @@ -210,7 +210,11 @@ namespace Private {
         await this._state.save(LAST_SAVE_ID, path);
 
         // Navigate to new workspace.
-        const url = URLExt.join(this._application, 'workspaces', id);
+        const workspacesBase = URLExt.join(this._application, 'workspaces');
+        const url = URLExt.join(workspacesBase, id);
+        if (!workspacesBase.startsWith(url)) {
+          throw new Error('Can only be used for workspaces');
+        }
         if (this._router) {
           this._router.navigate(url, { hard: true });
         } else {

programming_language: TypeScript
filename: index.ts
change_type: ModificationType.MODIFY
diff: @@ -57,9 +57,16 @@ function activateHubExtension(
   });
 
   // If hubServerName is set, use JupyterHub 1.0 URL.
-  const restartUrl = hubServerName
-    ? hubHost + URLExt.join(hubPrefix, 'spawn', hubUser, hubServerName)
-    : hubHost + URLExt.join(hubPrefix, 'spawn');
+  const spawnBase = URLExt.join(hubPrefix, 'spawn');
+  let restartUrl: string;
+  if (hubServerName) {
+    const suffix = URLExt.join(spawnBase, hubUser, hubServerName);
+    if (!suffix.startsWith(spawnBase)) {
+      throw new Error('Can only be used for spawn requests');
+    }
+    restartUrl = hubHost + suffix;
+  }
+  restartUrl = hubHost + spawnBase;
 
   const { commands } = app;
 

programming_language: TypeScript
filename: restapi.ts
change_type: ModificationType.MODIFY
diff: @@ -42,7 +42,12 @@ export async function listRunning(
  * Get a session url.
  */
 export function getSessionUrl(baseUrl: string, id: string): string {
-  return URLExt.join(baseUrl, SESSION_SERVICE_URL, id);
+  const servicesBase = URLExt.join(baseUrl, SESSION_SERVICE_URL);
+  const result = URLExt.join(servicesBase, id);
+  if (!result.startsWith(servicesBase)) {
+    throw new Error('Can only be used for services requests');
+  }
+  return result;
 }
 
 /**

programming_language: TypeScript
filename: index.ts
change_type: ModificationType.MODIFY
diff: @@ -161,6 +161,11 @@ namespace Private {
     const idsOnlyParam = idsOnly
       ? URLExt.objectToQueryString({ ids_only: true })
       : '';
-    return `${URLExt.join(base, SERVICE_SETTINGS_URL, id)}${idsOnlyParam}`;
+    const settingsBase = URLExt.join(base, SERVICE_SETTINGS_URL);
+    const result = URLExt.join(settingsBase, id);
+    if (!result.startsWith(settingsBase)) {
+      throw new Error('Can only be used for workspaces requests');
+    }
+    return `${result}${idsOnlyParam}`;
   }
 }

programming_language: TypeScript
filename: restapi.ts
change_type: ModificationType.MODIFY
diff: @@ -101,7 +101,11 @@ export async function shutdownTerminal(
   settings: ServerConnection.ISettings = ServerConnection.makeSettings()
 ): Promise<void> {
   Private.errorIfNotAvailable();
-  const url = URLExt.join(settings.baseUrl, TERMINAL_SERVICE_URL, name);
+  const workspacesBase = URLExt.join(settings.baseUrl, TERMINAL_SERVICE_URL);
+  const url = URLExt.join(workspacesBase, name);
+  if (!url.startsWith(workspacesBase)) {
+    throw new Error('Can only be used for terminal requests');
+  }
   const init = { method: 'DELETE' };
   const response = await ServerConnection.makeRequest(url, init, settings);
   if (response.status === 404) {

programming_language: TypeScript
filename: index.ts
change_type: ModificationType.MODIFY
diff: @@ -178,6 +178,11 @@ namespace Private {
    * Get the url for a workspace.
    */
   export function url(base: string, id: string): string {
-    return URLExt.join(base, SERVICE_WORKSPACES_URL, id);
+    const workspacesBase = URLExt.join(base, SERVICE_WORKSPACES_URL);
+    const result = URLExt.join(workspacesBase, id);
+    if (!result.startsWith(workspacesBase)) {
+      throw new Error('Can only be used for workspaces requests');
+    }
+    return result;
   }
 }

programming_language: TypeScript
filename: session.spec.ts
change_type: ModificationType.MODIFY
diff: @@ -144,5 +144,9 @@ describe('session', () => {
         SessionAPI.shutdownSession(UUID.uuid4())
       ).resolves.not.toThrow();
     });
+
+    it('should reject invalid on invalid id', async () => {
+      await expect(SessionAPI.shutdownSession('../')).rejects.toThrow();
+    });
   });
 });

programming_language: TypeScript
filename: manager.spec.ts
change_type: ModificationType.MODIFY
diff: @@ -53,6 +53,15 @@ describe('setting', () => {
 
         expect((await manager.fetch(id)).id).toBe(id);
       });
+
+      it('should reject on invalid id', async () => {
+        const id = '../';
+
+        const callback = async () => {
+          await manager.fetch(id);
+        };
+        await expect(callback).rejects.toThrow();
+      });
     });
 
     describe('#save()', () => {
@@ -64,6 +73,17 @@ describe('setting', () => {
         await manager.save(id, raw);
         expect(JSON.parse((await manager.fetch(id)).raw).theme).toBe(theme);
       });
+
+      it('should reject on invalid id', async () => {
+        const id = '../';
+        const theme = 'Foo Theme';
+        const raw = `{"theme": "${theme}"}`;
+
+        const callback = async () => {
+          await manager.save(id, raw);
+        };
+        await expect(callback).rejects.toThrow();
+      });
     });
   });
 });

programming_language: TypeScript
filename: manager.spec.ts
change_type: ModificationType.MODIFY
diff: @@ -55,6 +55,15 @@ describe('workspace', () => {
         expect((await manager.fetch(id)).metadata.id).toBe(id);
         await manager.remove(id);
       });
+
+      it('should reject on invalid id', async () => {
+        const id = '../';
+
+        const callback = async () => {
+          await manager.fetch(id);
+        };
+        await expect(callback).rejects.toThrow();
+      });
     });
 
     describe('#list()', () => {
@@ -87,6 +96,15 @@ describe('workspace', () => {
         expect((await manager.fetch(id)).metadata.id).toBe(id);
         await manager.remove(id);
       });
+
+      it('should reject on invalid id', async () => {
+        const id = '../';
+
+        const callback = async () => {
+          await manager.save(id, { data: {}, metadata: { id } });
+        };
+        await expect(callback).rejects.toThrow();
+      });
     });
   });
 });

programming_language: TypeScript
filename: server.ts
change_type: ModificationType.MODIFY
diff: @@ -27,7 +27,11 @@ export async function requestTranslationsAPI<T>(
   const settings = serverSettings ?? ServerConnection.makeSettings();
   translationsUrl =
     translationsUrl || `${settings.appUrl}/${TRANSLATIONS_SETTINGS_URL}`;
-  const requestUrl = URLExt.join(settings.baseUrl, translationsUrl, locale);
+  const translationsBase = URLExt.join(settings.baseUrl, translationsUrl);
+  const requestUrl = URLExt.join(translationsBase, locale);
+  if (!requestUrl.startsWith(translationsBase)) {
+    throw new Error('Can only be used for translations requests');
+  }
   let response: Response;
   try {
     response = await ServerConnection.makeRequest(requestUrl, init, settings);

programming_language: TypeScript