Repository navigation
fix(grep): prevent command-line option injection by passing search patterns with explicit -e delimiter - #29536
zainnadeem786 wants to merge 4 commits into
Conversation
|
📊 PR Size: size/M
|
🛑 Action Required: Evaluation ApprovalSteering changes have been detected in this PR. To prevent regressions, a maintainer must approve the evaluation run before this PR can be merged. Maintainers:
Once approved, the evaluation results will be posted here automatically. |
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 the grep execution module where user-provided search patterns could be misinterpreted as command-line flags. By enforcing the use of the '-e' pattern terminator, the system now ensures that all search inputs are treated as positional arguments, significantly improving the robustness and security of the subprocess execution logic. 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
|
There was a problem hiding this comment.
Code Review
This pull request modifies the grep tool to safely handle patterns with leading hyphens by prepending them with the -e flag in both system grep and git grep executions, and adds corresponding unit tests. The review feedback recommends validating and trimming the search pattern to prevent performance issues from whitespace-only inputs, clearing the execStreaming mock in tests to avoid state leakage, and using synchronous filesystem methods for test setup to enhance readability.
|
@gemini-code-assist review |
There was a problem hiding this comment.
Code Review
This pull request improves the grep tool by validating that the search pattern is not empty or whitespace-only, and by passing the -e flag before the pattern in both git grep and system grep commands to safely handle leading hyphens. It also adds corresponding unit tests. The review feedback recommends avoiding monkey-patching node:fs/promises in the test file, suggesting instead to import and use mkdirSync directly from node:fs to prevent potential runtime errors in strict ES module environments.
|
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. |
|
Hi team, just following up on this security hardening PR (#29536). It has already received an approving review from @svessebror-maker. Could a maintainer please help add the appropriate label or merge this in before the 7-day automated closure window? Thank you! |
Summary
This PR hardens the local grep execution module in
packages/core/src/tools/grep.tsagainst Command-Line Option / Argument Injection (CWE-88) by enforcing strict argument separation using the explicit pattern terminator (-e) for bothgit grepand systemgreppipelines.Problem / Vulnerability Addressed
When constructing search queries, both
git grepand systemgreppreviously appended user-supplied or workspace-derived search patterns directly as raw positional arguments:gitArgs = ['grep', '--untracked', '-n', '-E', '--ignore-case', pattern]grepArgs.push(pattern)Because POSIX and GNU command-line parsers process arguments sequentially from left to right, any token beginning with a hyphen (
-or--) is interpreted as a command-line flag or option rather than a literal search string.Impact:
-v,--max-count) could force the underlying tool to misinterpret inputs as flags, altering search output or triggering inverted matches.--max-countwithout a trailing integer value) caused the underlying subprocess to crash with fatal errors (fatal: option '--max-count' requires a value), disrupting the active CLI session.Solution & Key Changes
-eDelimiter Enforcement:git grepcommand building to push-eimmediately before the searchpattern:grepcommand building to prepend-ebefore thepattern:packages/core/src/tools/grep.test.tsvalidating that leading-hyphen search patterns (e.g.,-vand--flag) are safely preceded by the-eflag in spawned arguments.Test Verification
grep.test.ts): 35 / 35 tests passed (100%)Relates to #29627