-
Notifications
You must be signed in to change notification settings - Fork 4.6k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Code Execution vulnerability with tool PythonCodeTool #2908
Comments
To address the security issue with the
Here is an example of how you can implement this: Step 1: Implement the
|
I share the same opinion. Using exec is very risky, and I was concerned about it while developing. I am currently working on a new design. Preview
|
There are options in LangChain's StructuredTool, such as the option to extract signatures. I am considering a format that reuses such options and does not use the Code field. If you have any suggestions for improvement, I will consider them |
To avoid the risk for
|
Hi @ogabrielluiz, What's the security policy of langflow? I wonder if maintainers will patch the vulnerability and request for a CVE. Thank you. |
I don't think any update on this component is worth it in terms of security. Even implementing a sandbox is not enough to actually prevent malicious users to access the system, there are too many ways to escape it. Langflow admin must be aware of it and do not let any client to execute code. Langflow flows must be considered as application code, therefore it's not up to langflow runtime code to provide those mitigation. This can be achieved by Authorization implementation in the backend, which is lacking today but can "easily" replaced by any other http proxy with custom rules. |
Do you need any assistance with this case? If not, please let us know if this issue can be closed. |
I find a simliar issue #1973. It was caused by exec function as well. I consider langflow as an LLM service which can be deployed on a cloud server. Take the service provided by official in https://astra.datastax.com as a example, users can log in to the server and create flows. In this scene, an attacker can execute malicous code with the PythonCodeTool on the server. So I wonder if components in langflow can be executed in a safer way. |
Upon further reflection, I think it is reasonable to manage the operations within a component at the API call level, given that everything running within the system can be utilized. While imposing restrictions within the component can offer some assistance, it is not a fundamental solution. Having access to the editor screen essentially grants full control. As I mentioned in the previous post, LangFlow has now introduced user-specific API keys, providing a slight security enhancement compared to before. Although in the case of a demo space with autologin set to true, all information can be stolen as mentioned in that post, it is only a demo. When we manage it at the product level, it should naturally be managed by an account-based administrator.We occasionally see bots or hackers attempting to # on the addresses we use for development. Exposing the LangFlow endpoint on the internet is essentially equivalent to fully opening up the computer. It would be great to have stable component and flow management through source reviews by the maintainers at LangFlow Store. However, it is challenging to invest time and resources into that. |
You can deploy Langflow in BE mode with no UI and then it is up to the Administrator/Operator to put API restrictions based on their deployment environment |
Bug Description
When compose an LLM app with langflow,
PythonCodeTool
is available to developers to implement a tool withStructuredTool
in langchain. However, there is a lack of validation for the python code and codes will be executed directly.Once the LLM app is deployed on a server, arbitrary code can be executed on the server.
Reproduction
1.Create a new project.
2.Import the json file to the collection.
PythonCodeTool.json
In the PythonCodeTool,
Tool Code
is set to read/etc/passwd
with os.popen.And in order to use the
search
tool, the input is set toSearch for the result
.Also input a valid OPENAI API KEY and OPENAI BASE.
3.Run Flow in the Playground. Code in PythonCodeTool is executed and we can get the content of
/etc/passwd
of the server.Expected behavior
Since all the inputs can be controled by users, validation should be taken into consideration when executing users code. Enable the necessary action and forbid the malicious behavior before using
exec
.Who can help?
@ogabrielluiz
Operating System
Ubuntu Linux 22.04
Langflow Version
v1.0.12
Python Version
The text was updated successfully, but these errors were encountered: