Skip to content

Fix: Block Shell tool regex denylist bypass leading to command injection (CVE-2026-2256)#880

Merged
alcholiclg merged 4 commits intomainfrom
code_sandbox
Mar 5, 2026
Merged

Fix: Block Shell tool regex denylist bypass leading to command injection (CVE-2026-2256)#880
alcholiclg merged 4 commits intomainfrom
code_sandbox

Conversation

@alcholiclg
Copy link
Collaborator

Change Summary

  • Fixes CVE-2026-2256: Shell tool command execution could be abused via regex denylist bypass when using subprocess.run(..., shell=True).

  • Mitigates by moving shell execution into an isolated Docker sandbox, preventing host-level command execution even if filtering is bypassed.

Related issue number

Checklist

  • The pull request title is a good summary of the changes - it will be used in the changelog
  • Unit tests for the changes exist
  • Run pre-commit install and pre-commit run --all-files before git commit, and passed lint check.
  • Documentation reflects the changes where applicable

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, 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 delivers a critical security update by fixing a command injection vulnerability in the shell execution tool. The core change involves migrating shell command execution to a Docker-isolated sandbox environment, which provides a stronger security boundary than previous regex-based filtering. Additionally, the handling of shell commands has been refined to automatically wrap complex commands for safer execution, and related project configurations and documentation have been updated to reflect these architectural changes.

Highlights

  • Security Fix (CVE-2026-2256): Addressed a critical vulnerability (CVE-2026-2256) in the Shell tool's regex denylist, which could be bypassed to achieve command injection when using subprocess.run(..., shell=True).
  • Docker Sandbox Isolation: Implemented a robust mitigation strategy by moving all shell command execution into an isolated Docker sandbox. This prevents host-level command execution even if filtering mechanisms are bypassed, significantly enhancing security.
  • Enhanced Shell Command Handling: Modified the shell_executor to execute commands directly without shell parsing by default. Commands containing shell metacharacters (e.g., &&, |, cd, export) are now automatically wrapped with sh -lc "..." for safer, explicit shell interpretation within the sandbox.
  • Refactored Shell Tool: The previous ms_agent/tools/shell/shell.py module, which contained the vulnerable execute_single tool and its regex-based safety checks, has been removed and replaced by the more secure shell_executor within the code_executor framework.
  • Updated Project Configuration and Documentation: Updated code_genesis project configurations (coding.yaml, install.yaml, refine.yaml) and README.md to reflect the new code_executor tool, its Docker sandbox setup, and the process for building the required sandbox image.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • ms_agent/tools/code/code_executor.py
    • Updated the description for shell_executor to clarify direct command execution and advise explicit sh -lc "..." for shell syntax.
    • Increased the default timeout for shell_executor from 30 seconds to 900 seconds.
    • Introduced logic to automatically wrap commands containing shell metacharacters with sh -lc "..." to ensure safer execution within the sandbox.
  • ms_agent/tools/shell/shell.py
    • Removed the deprecated Shell tool module, including its execute_single method and regex-based safety checks.
  • ms_agent/tools/tool_manager.py
    • Removed the import and instantiation of the Shell tool, reflecting its deprecation.
  • projects/code_genesis/README.md
    • Updated environment setup instructions to guide users on building the Docker sandbox image instead of separate Python and npm environments.
    • Added details about the contents and security benefits of the new Docker sandbox image.
  • projects/code_genesis/coding.yaml
    • Updated prompt examples to reference shell_executor instead of the old shell tool and execute_single.
    • Replaced the shell tool configuration with code_executor configuration, including detailed Docker sandbox settings (image, working directory, resource limits, enabled tools).
  • projects/code_genesis/install.yaml
    • Updated prompt instructions to refer to shell_executor for dependency installation.
    • Replaced the shell tool configuration with code_executor configuration, incorporating Docker sandbox settings and adjusting tool_call_timeout.
  • projects/code_genesis/refine.yaml
    • Updated prompt instructions to refer to shell_executor for pwd command usage.
    • Replaced the shell tool configuration with code_executor configuration, including Docker sandbox settings.
  • projects/code_genesis/tools/build_sandbox_image.sh
    • Added a new script to build a Docker image (code-genesis-sandbox:version1) that includes Python 3.12, Node.js 20, npm, git, and curl, configured with mirror registries for faster dependency downloads.
  • projects/code_genesis/workflow/refine.py
    • Modified the prompt message to inform agents that shell_executor operates within a Docker sandbox and project files are accessible at /data.
  • requirements/code.txt
    • Added docker and websocket-client as new dependencies.
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
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

This pull request refactors the shell execution mechanism by replacing a regex-based denylist with a Docker sandbox isolation model, effectively mitigating host-level command injection (CVE-2026-2256). However, the implementation introduces new security risks, specifically the lack of authentication for the Jupyter Kernel Gateway within the sandbox, which allows unauthenticated code execution, and excessively high tool call timeouts that could lead to Denial of Service. Additionally, there are general issues related to timeout consistency and hardcoded mirror configurations that could impact maintainability and portability.

Comment on lines +19 to +34
RUN sed -i 's|deb.debian.org|mirrors.aliyun.com|g' /etc/apt/sources.list.d/debian.sources \
&& apt-get update -o Acquire::Retries=5 \
&& apt-get install -y --no-install-recommends \
curl \
git \
build-essential \
&& curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \
&& apt-get install -y --no-install-recommends nodejs \
&& apt-get clean && rm -rf /var/lib/apt/lists/*

# Configure npm to use a Chinese mirror. Comment out this line if not needed.
RUN npm config set registry https://registry.npmmirror.com/

# Install Jupyter kernel gateway (required by sandbox)
RUN pip install --no-cache-dir -i https://mirrors.aliyun.com/pypi/simple --trusted-host mirrors.aliyun.com \
jupyter_kernel_gateway \
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The Dockerfile hardcodes the use of specific mirror registries (e.g., mirrors.aliyun.com for Debian, npm, and PyPI). While this might speed up builds in certain network environments, it reduces the portability of the Docker image and might not be suitable for all users or organizations with different network configurations or security policies. Consider making these mirror configurations configurable via build arguments or environment variables, or removing them to rely on official sources by default, as suggested in the comments.

@alcholiclg alcholiclg merged commit 5f7178b into main Mar 5, 2026
2 of 3 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.

3 participants