CVE-2024-4078 (published 2024-05-16T09:15Z)

A vulnerability in the parisneo/lollms, specifically in the `/unInstall_binding` endpoint, allows for arbitrary code execution due to insufficient sanitization of user input. The issue arises from the lack of path sanitization when handling the `name` parameter in the `unInstall_binding` function, allowing an attacker to traverse directories and execute arbitrary code by loading a malicious `__init__.py` file. This vulnerability affects the latest version of the software. The exploitation of this vulnerability could lead to remote code execution on the system where parisneo/lollms is deployed.


Weakness information:
cwe_id: CWE-77
cwe_name: Improper Neutralization of Special Elements used in a Command ('Command Injection')
description: The product constructs all or part of a command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended command when it is sent to a downstream component.
extended_description: 
            Many protocols and products have their own custom command language. While OS or shell command strings are frequently discovered and targeted, developers may not realize that these other command languages might also be vulnerable to attacks.
         
         

Fix information:
repo_url: https://github.com/parisneo/lollms
commit_details: repo_url: https://github.com/parisneo/lollms
author: Saifeddine ALOUI
author_date: 2024-03-09 23:57:16+01:00
msg: Fixed some vulenerabilities
repository: repo_url: https://github.com/parisneo/lollms
repo_name: ParisNeo/lollms
description: Lord of LLMS
repo_language: Python
owner: parisneo
file_changes: filename: lollms_binding_infos.py
change_type: ModificationType.MODIFY
diff: @@ -14,7 +14,7 @@ from lollms.server.elf_server import LOLLMSElfServer
 from lollms.binding import BindingBuilder, InstallOption
 from ascii_colors import ASCIIColors
 from lollms.utilities import load_config, trace_exception, gc
-from lollms.security import sanitize_path_from_endpoint
+from lollms.security import sanitize_path_from_endpoint, sanitize_path
 from pathlib import Path
 from typing import List, Any
 import json
@@ -91,7 +91,7 @@ async def reload_binding(request: BindingReloadRequest):
 
     try:
         print(f"Reloading binding selected : {request.name}")
-        safe_name = os.path.basename(request.name) # sanitize the file path to prevent path traversal
+        safe_name = sanitize_path(os.path.basename(request.name)) # sanitize the file path to prevent path traversal
         lollmsElfServer.config["binding_name"]=safe_name
         if lollmsElfServer.binding:
             lollmsElfServer.binding.destroy_model()
@@ -133,7 +133,7 @@ def install_binding(data:BindingInstallParams):
         lollmsElfServer.info("Unmounting binding and model")
         lollmsElfServer.info("Reinstalling binding")
         old_bn = lollmsElfServer.config.binding_name
-        lollmsElfServer.config.binding_name = data.name
+        lollmsElfServer.config.binding_name = sanitize_path(data.name)
         lollmsElfServer.binding =  BindingBuilder().build_binding(lollmsElfServer.config, lollmsElfServer.lollms_paths, InstallOption.FORCE_INSTALL, lollmsCom=lollmsElfServer)
         lollmsElfServer.success("Binding installed successfully")
         del lollmsElfServer.binding
@@ -171,7 +171,7 @@ def reinstall_binding(data:BindingInstallParams):
         gc.collect()
         ASCIIColors.info("Reinstalling binding")
         old_bn = lollmsElfServer.config.binding_name
-        lollmsElfServer.config.binding_name = data.name
+        lollmsElfServer.config.binding_name = sanitize_path(data.name)
         lollmsElfServer.binding =  BindingBuilder().build_binding(lollmsElfServer.config, lollmsElfServer.lollms_paths, InstallOption.FORCE_INSTALL, lollmsCom=lollmsElfServer)
         lollmsElfServer.success("Binding reinstalled successfully")
         lollmsElfServer.config.binding_name = old_bn
@@ -207,7 +207,7 @@ def unInstall_binding(data:BindingInstallParams):
             gc.collect()
         ASCIIColors.info("Uninstalling binding")
         old_bn = lollmsElfServer.config.binding_name
-        lollmsElfServer.config.binding_name = data.name
+        lollmsElfServer.config.binding_name = sanitize_path(data.name)
         lollmsElfServer.binding =  BindingBuilder().build_binding(lollmsElfServer.config, lollmsElfServer.lollms_paths, InstallOption.NEVER_INSTALL, lollmsCom=lollmsElfServer)
         lollmsElfServer.binding.uninstall()
         ASCIIColors.green("Uninstalled successful")

programming_language: Python
filename: lollms_extensions_infos.py
change_type: ModificationType.MODIFY
diff: @@ -150,7 +150,7 @@ def install_extension(data: ExtensionInstallInfos):
 def reinstall_extension(data: ExtensionInstallInfos):
     if not data.name:
         try:
-            data.name=lollmsElfServer.config.extensions[-1]
+            data.name=sanitize_path(lollmsElfServer.config.extensions[-1])
         except Exception as ex:
             lollmsElfServer.error(ex)
             return

programming_language: Python