fix(patch): cherry-pick cfdc4cf to release/v0.24.0-pr-16759 to patch version v0.24.0 and create version 0.24.1#16865
Conversation
Co-authored-by: Tommaso Sciortino <sciortino@gmail.com>
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
Summary of ChangesHello @gemini-cli-robot, 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 introduces a critical fix by converting the 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 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
|
|
Size Change: +12 B (0%) Total Size: 22.2 MB ℹ️ View Unchanged
|
There was a problem hiding this comment.
Code Review
This pull request correctly updates the scheduleToolCalls function to be awaited, ensuring proper asynchronous flow and test reliability across the codebase. However, a critical prompt injection vulnerability has been identified. User input is not sanitized before being sent to the LLM, and the application blindly executes tool calls generated by the LLM. This could allow an attacker to execute arbitrary tools, potentially leading to remote code execution. While the PR improves asynchronous handling, it does not address this underlying security issue. Specific comments have been added with details and remediation steps.
| prompt_id, | ||
| }; | ||
| scheduleToolCalls([toolCallRequest], abortSignal); | ||
| await scheduleToolCalls([toolCallRequest], abortSignal); |
There was a problem hiding this comment.
A critical prompt injection vulnerability exists here. User input is passed to the Gemini model without sanitization, allowing an attacker to manipulate the LLM's behavior and execute arbitrary tool calls, potentially leading to remote code execution. This line executes a tool call originating from a slash command, which is derived from user input. Beyond the security concern, the scheduleToolCalls function is asynchronous and must be awaited to prevent race conditions and ensure proper application flow. Remediation for the vulnerability includes strict input validation and sanitization, implementing an allow-list for tools with schema validation, and requiring user confirmation for sensitive tool calls. The suggested code addresses the asynchronous call.
| await scheduleToolCalls([toolCallRequest], abortSignal); | |
| await scheduleToolCalls([toolCallRequest], abortSignal); |
| } | ||
| if (toolCallRequests.length > 0) { | ||
| scheduleToolCalls(toolCallRequests, signal); | ||
| await scheduleToolCalls(toolCallRequests, signal); |
There was a problem hiding this comment.
A critical prompt injection vulnerability exists here. User input is passed to the Gemini model without sanitization, allowing an attacker to manipulate the LLM's behavior and execute arbitrary tool calls, potentially leading to remote code execution. This line executes tool calls requested by the LLM in its response to a user's prompt. Beyond the security concern, scheduleToolCalls is an asynchronous operation and must be awaited to prevent incorrect state management (e.g., StreamProcessingStatus.Completed returning prematurely). Remediation for the vulnerability includes strict input validation and sanitization, implementing an allow-list for tools with schema validation, and requiring user confirmation for sensitive tool calls. The suggested code addresses the asynchronous call.
| await scheduleToolCalls(toolCallRequests, signal); | |
| await scheduleToolCalls(toolCallRequests, signal); |
| ) => { | ||
| setToolCallsForDisplay([]); | ||
| void scheduler.schedule(request, signal); | ||
| return scheduler.schedule(request, signal); |
There was a problem hiding this comment.
Previously, void scheduler.schedule explicitly ignored the returned Promise. Since scheduler.schedule is now asynchronous and returns a Promise, it's important to return this Promise. This allows the caller to await the scheduling operation, ensuring proper asynchronous flow and error handling.
| return scheduler.schedule(request, signal); | |
| return scheduler.schedule(request, signal); |
| await act(async () => { | ||
| await schedule(request, new AbortController().signal); |
There was a problem hiding this comment.
When testing asynchronous operations in React components, it's crucial to wrap act calls that involve Promises with await act(async () => { await ... }). This ensures that all state updates and side effects triggered by the asynchronous operation are fully processed before the test continues, preventing flaky tests or incorrect assertions.
| await act(async () => { | |
| await schedule(request, new AbortController().signal); | |
| await act(async () => { | |
| await schedule(request, new AbortController().signal); | |
| }); |
| req: ToolCallRequestInfo | ToolCallRequestInfo[], | ||
| signal: AbortSignal, | ||
| ) => void, | ||
| ) => Promise<void>, |
There was a problem hiding this comment.
The type definition for schedule in the test utility function scheduleAndWaitForExecution must correctly reflect its asynchronous nature, returning Promise<void>. This aligns with the updated ScheduleFn type and ensures type safety within the test.
| ) => Promise<void>, | |
| ) => Promise<void>, |
| let schedulePromise1: Promise<void>; | ||
| let schedulePromise2: Promise<void>; |
There was a problem hiding this comment.
| await act(async () => { | ||
| schedulePromise1 = schedule(request1, new AbortController().signal); | ||
| }); |
There was a problem hiding this comment.
| await act(async () => { | ||
| schedulePromise2 = schedule(request2, new AbortController().signal); | ||
| }); |
| // Wait for first to complete | ||
| await act(async () => { | ||
| await schedulePromise1; | ||
| }); |
There was a problem hiding this comment.
Explicitly awaiting schedulePromise1 ensures that the first scheduled operation has fully completed, including its execution and any subsequent callbacks, before the test asserts its outcome. This is critical for testing sequential asynchronous flows.
await act(async () => {
await schedulePromise1;
});| await act(async () => { | ||
| await schedulePromise2; | ||
| }); |
This PR automatically cherry-picks commit cfdc4cf to patch version v0.24.0 in the stable release to create version 0.24.1.