CVE-2024-27444: Insufficient Information (NVD-CWE-noinfo)
value: langchain_experimental (aka LangChain Experimental) in LangChain before 0.1.8 allows an attacker to bypass the CVE-2023-44467 fix and execute arbitrary code via the __import__, __subclasses__, __builtins__, __globals__, __getattribute__, __bases__, __mro__, or __base__ attribute in Python code. These are not prohibited by pal_chain/base.py.
CWE description: There is insufficient information about the issue to classify it; details are unkown or unspecified.
Published: 2024-02-26T16:28Z
Repository: https://github.com/langchain-ai/langchain
Language: Python
Files changed: libs/experimental/langchain_experimental/pal_chain/base.py
Commit date: 2024-02-14 11:44:07 -0800
Commit message: experimental[patch]: Enhance protection against arbitrary code execution in PALChain (#17091)

- **Description:** Block some ways to trigger arbitrary code execution
bug in PALChain.

---------

Co-authored-by: Eugene Yurtsev <eyurtsev@gmail.com>
Diff: diff --git a/libs/experimental/langchain_experimental/pal_chain/base.py b/libs/experimental/langchain_experimental/pal_chain/base.py
index d30655ed37..58593076f4 100644
--- a/libs/experimental/langchain_experimental/pal_chain/base.py
+++ b/libs/experimental/langchain_experimental/pal_chain/base.py
@@ -19,10 +19,20 @@ from langchain_core.language_models import BaseLanguageModel
 from langchain_experimental.pal_chain.colored_object_prompt import COLORED_OBJECT_PROMPT
 from langchain_experimental.pal_chain.math_prompt import MATH_PROMPT
 from langchain_experimental.pydantic_v1 import Extra, Field
 
 COMMAND_EXECUTION_FUNCTIONS = ["system", "exec", "execfile", "eval", "__import__"]
+COMMAND_EXECUTION_ATTRIBUTES = [
+    "__import__",
+    "__subclasses__",
+    "__builtins__",
+    "__globals__",
+    "__getattribute__",
+    "__bases__",
+    "__mro__",
+    "__base__",
+]
 
 
 class PALValidation:
     SOLUTION_EXPRESSION_TYPE_FUNCTION = ast.FunctionDef
     SOLUTION_EXPRESSION_TYPE_VARIABLE = ast.Name
@@ -230,10 +240,19 @@ class PALChain(Chain):
         if (
             not code_validations.allow_command_exec
             or not code_validations.allow_imports
         ):
             for node in ast.walk(code_tree):
+                if (
+                    not code_validations.allow_command_exec
+                    and isinstance(node, ast.Attribute)
+                    and node.attr in COMMAND_EXECUTION_ATTRIBUTES
+                ):
+                    raise ValueError(
+                        f"Found illegal command execution function "
+                        f"{node.attr} in code {code}"
+                    )
                 if (not code_validations.allow_command_exec) and isinstance(
                     node, ast.Call
                 ):
                     if (
                         hasattr(node.func, "id")

Fixed code: COMMAND_EXECUTION_ATTRIBUTES = [
    "__import__",
    "__subclasses__",
    "__builtins__",
    "__globals__",
    "__getattribute__",
    "__bases__",
    "__mro__",
    "__base__",
]
                if (
                    not code_validations.allow_command_exec
                    and isinstance(node, ast.Attribute)
                    and node.attr in COMMAND_EXECUTION_ATTRIBUTES
                ):
                    raise ValueError(
                        f"Found illegal command execution function "
                        f"{node.attr} in code {code}"
                    )