Stop LLM Generated Code from Having Any Additional Imports#5879
Stop LLM Generated Code from Having Any Additional Imports#5879christopherholland-workday merged 2 commits intomainfrom
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly strengthens the security of LLM-generated Python code by hardening the validation logic. It addresses previous flaws that allowed unauthorized imports, ensuring that only pre-approved modules like pandas and numpy are available. The changes also expand the detection of dangerous built-ins and reflection attributes, making the execution environment more secure. Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request significantly enhances the security of the Python code execution environment by tightening restrictions on LLM-generated code. The changes include pre-importing numpy alongside pandas and then strictly forbidding any further import statements from the LLM. Additionally, several dangerous built-in functions and reflection-related attributes (vars(), dir(), __dict__, __module__) are now explicitly blocked to prevent potential sandbox escapes or unauthorized access. The introduction of a comprehensive suite of unit tests for the pythonCodeValidator is a crucial improvement, ensuring the effectiveness of these new security measures and guarding against future regressions. This is a well-executed security hardening.
Overview
Flowise-281 and Flowise-282
The previous python code sanitizer had flaws that would allow some imports to be part of LLM generated code. These updates harden the validations.
Testing
Manual tests
See Jira FLOWISE-281 for manual testing details.
Unit tests
Added new unit tests and ran them locally: