-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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 injection by API api/v1/validate/code
which can lead to code execution
#696
Comments
Hi! What are your suggestions on this? Sandboxing is out of reach for an open-source project like this (for now at least). I think we can test some options such as literal_eval but I'm not sure it is going to have the same result. What do you think? |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Hi! Sorry for the late reply...
|
Fixes langflow-ai#696 Update `post_validate_code` to use `literal_eval` instead of `exec` for safer code evaluation. * **API Changes** - Add a warning comment about the risks of using the `/validate/code` endpoint in `src/backend/base/langflow/api/v1/validate.py`. - Update `post_validate_code` to use `literal_eval` instead of `exec`. * **Validation Changes** - Update `validate_code` in `src/backend/base/langflow/utils/validate.py` to filter out malicious code. - Add checks to prevent the use of `import` statements and dangerous functions like `eval` and `exec`. * **Testing** - Add tests in `src/backend/tests/unit/test_validate_code.py` to ensure `post_validate_code` handles and rejects malicious code inputs. - Add tests to verify the updated `validate_code` function. --- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/langflow-ai/langflow/issues/696?shareId=XXXX-XXXX-XXXX-XXXX).
Describe the bug
As defined in the source code, API
validate/code
validate the code and give the validation result. While the functionexec
is used when facing the condition thatisinstance(node, ast.FunctionDef)
, after going into this branch, exec will be called.But we can trigger the
exec
by using the default parameter of a function which can lead to code execution.While this API is the public API, so if a service is running on a public server, attacker can do RCE by calling the API, giving a part of code to execute the code remotely, even reverse a shell.
To Reproduce
Here is the PoC:
Shell Log
The text was updated successfully, but these errors were encountered: