Skip to content

Sanitize Code Ran in Pyodide in CSVAgent#5836

Merged
christopherholland-workday merged 2 commits intomainfrom
python-injection
Feb 24, 2026
Merged

Sanitize Code Ran in Pyodide in CSVAgent#5836
christopherholland-workday merged 2 commits intomainfrom
python-injection

Conversation

@christopherholland-workday
Copy link
Copy Markdown
Contributor

This is a follow up to #5701 (Adding the validation here was missed).

CSVAgent runs LLM generated code using Pyodide. We want to limit the code that is run to avoid potential issues. Changes include:

  1. (Done in previous PR) Create pythonCodeValidator that rejects code including imports, dangerous built-in functions, and dangerous modules
  2. Use pythonCodeValidator before running python code in Pyodide

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @christopherholland-workday, 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 strengthens the security posture of the CSVAgent by introducing a critical validation step for user-provided Python code. It ensures that any custom CSV reading functions are scrutinized for dangerous constructs before being executed in the Pyodide environment, thereby mitigating risks associated with arbitrary code execution. Additionally, a minor adjustment was made to the secureAxiosRequest function to handle HTTP status codes more broadly during redirect handling.

Highlights

  • Security Enhancement: Implemented validation for customReadCSVFunc within the CSVAgent to prevent the execution of potentially unsafe Python code in Pyodide.
Changelog
  • packages/components/nodes/agents/CSVAgent/CSVAgent.ts
    • Added a call to validatePythonCodeForDataFrame to check customReadCSVFunc for security vulnerabilities.
    • Introduced error handling to throw an exception if the custom CSV read code is deemed unsafe.
  • packages/components/src/httpSecurity.ts
    • Modified secureAxiosRequest to set validateStatus: () => true in currentConfig when disabling automatic redirects, ensuring all HTTP status codes are accepted.
Activity
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

The pull request introduces a security validation step for Python code executed in Pyodide within the CSVAgent. This is a crucial improvement to prevent potential remote code execution vulnerabilities by rejecting unsafe constructs in LLM-generated or custom Python code. Additionally, a minor change was made to httpSecurity.ts to accept all status codes for secureAxiosRequest when handling redirects, which is a reasonable adjustment for robust redirect handling.

Comment on lines +147 to +154
const csvReadValidation = validatePythonCodeForDataFrame(customReadCSVFunc)
if (!csvReadValidation.valid) {
throw new Error(
`Custom read_csv code was rejected for security reasons (${
csvReadValidation.reason ?? 'unsafe construct'
}). Please use only safe pandas read_csv operations.`
)
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

security-critical critical

This new validation step is a critical security enhancement. By validating customReadCSVFunc before execution, you effectively prevent malicious or unsafe Python code from being run in the Pyodide environment, mitigating potential remote code execution (RCE) risks. This directly addresses the objective of limiting code to avoid potential issues.

@christopherholland-workday christopherholland-workday merged commit 0c8236a into main Feb 24, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants