Repository navigation
fix(editor): harden Windows subprocess argument quoting and prevent command injection on Windows - #29510
fix(editor): harden Windows subprocess argument quoting and prevent command injection on Windows#29510zainnadeem786 wants to merge 3 commits into
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 addresses a security vulnerability in Windows subprocess execution where file paths and arguments were passed unquoted to Highlights
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 the 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 counterproductive. 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. Footnotes
|
|
📊 PR Size: size/M
|
There was a problem hiding this comment.
Code Review
This pull request introduces a quoteCmdArg utility in packages/core/src/utils/editor.ts to escape and quote command-line arguments when launching diff tools via cmd.exe on Windows, along with corresponding unit tests. However, the feedback highlights critical security and correctness vulnerabilities in the implementation of quoteCmdArg, including potential command injection via newlines, incorrect handling of percent signs, and nested double quotes. The reviewer has provided suggestions to address these issues and update the test assertions accordingly.
…dArg to prevent command injection
|
@gemini-code-assist review |
There was a problem hiding this comment.
Code Review
This pull request introduces a new utility function quoteCmdArg to safely quote arguments when spawning editor processes on Windows, preventing command injection and argument splitting. The reviewer identified an issue where escaping percent signs (%) with carets (^%) inside double quotes is incorrect because cmd.exe treats carets literally inside double quotes, which would corrupt paths containing %. The reviewer suggested removing this escaping and updating the corresponding test cases.
…ent path corruption on Windows
|
Hi there! Thank you for your interest in contributing to Gemini CLI. To ensure we maintain high code quality and focus on our prioritized roadmap, we only guarantee review and consideration of pull requests for issues that are explicitly labeled as 'help wanted'. This PR will be closed in 7 days if it remains without that designation. We encourage you to find and contribute to existing 'help wanted' issues in our backlog! Thank you for your understanding. |
Summary
This PR hardens Windows subprocess execution in
packages/core/src/utils/editor.tsby introducing a robust argument quoting helper (quoteCmdArg) forshell: trueinvocations.Problem / Vulnerability Addressed
When spawning diff commands on Windows using
shell: true, file paths and arguments containing spaces, quotes, or shell metacharacters (&,|,^,%VAR%) were passed unquoted tocmd.exe. This created risks of:C:\Program Files\...) were split into multiple arguments.cmd.exe.%VAR%sequences inside paths could trigger unintended variable expansion.Solution & Key Changes
quoteCmdArgImplementation:" -> "") and carets (% -> ^%) to neutralizecmd.exevariable expansion.cmd.exe/CommandLineToArgvWdoes not misinterpret quotes.openDiffto mapquoteCmdArgacrossdiffCommand.argsexclusively whenprocess.platform === 'win32'.packages/core/src/utils/editor.test.tscovering safe paths, edge cases, special characters, and cross-platform consistency.Test Verification
editor.test.ts): 233 / 233 passed (100%)Relates to #29625