fix(security): rate limit web_fetch tool to mitigate DDoS via prompt injection#19567
fix(security): rate limit web_fetch tool to mitigate DDoS via prompt injection#19567mattKorwel merged 5 commits intomainfrom
Conversation
…injection Implements a rolling time-window rate limit for the `web_fetch` tool. This addresses a potential vulnerability where a malicious prompt could instruct the model to execute numerous concurrent requests to a single target, especially in YOLO mode, effectively using the CLI as a botnet. The rate limiter tracks requests per hostname and temporarily blocks subsequent requests if a threshold (10 requests per minute) is exceeded, returning a `WEB_FETCH_PROCESSING_ERROR`. Also includes additional telemetry for tool call start and end times to better monitor execution rates. Fixes google-gemini/maintainers-gemini-cli#1205
Summary of ChangesHello @mattKorwel, 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 critical security vulnerability by introducing a robust rate-limiting mechanism to the Highlights
Changelog
Activity
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: +2.09 kB (+0.01%) Total Size: 25.1 MB
ℹ️ View Unchanged
|
There was a problem hiding this comment.
Code Review
This pull request introduces a rate-limiting mechanism for the web_fetch tool to prevent potential DDoS attacks via prompt injection and extends telemetry to track tool execution times. However, it introduces a critical memory leak due to the unbounded growth of the global hostRequestHistory map. This vulnerability could be exploited by an attacker providing many unique hostnames, leading to a Denial of Service (DoS) through memory exhaustion. To address this, using an LRU cache to bound memory usage is recommended, aligning with existing repository conventions.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
- Import LRUCache from mnemonist and fix constructor call - Remove unused peek() method from SchedulerStateManager - Update TestRig to capture error details in tool logs - Add integration test for web_fetch rate limiting
|
validated after the first 10 parallel request, we receive a rate limiting error |
| rig = new TestRig(); | ||
| }); | ||
|
|
||
| afterEach(async () => { |
There was a problem hiding this comment.
nit: could this be?
afterEach(async () => await rig?.cleanup());
…injection (#19567) Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Summary
This PR implements a rate limit for the
web_fetchtool to mitigate a potential DDoS vulnerability via prompt injection, as reported in issue 1205.Details
The fix introduces a rolling time-window rate limiter directly within the
WebFetchToolInvocationclass. It tracks the timestamps of requests made to each unique hostname. If the number of requests to a specific host exceeds the configured threshold (currently 10 requests per minute) within the time window, subsequent requests are temporarily blocked, and the tool returns aWEB_FETCH_PROCESSING_ERROR.Additionally, the
ToolCallEventtelemetry andCompletedToolCallscheduler types have been updated to includestart_timeandend_timeproperties, providing better visibility into tool execution rates and aiding in future monitoring. Some minor type cleanup in the scheduler logic was also performed during the investigation.Related Issues
Fixes google-gemini/maintainers-gemini-cli#1205
How to Validate
npm run test:e2e -- integration-tests/concurrency-limit.test.tsweb_fetchtool:npm test -w @google/gemini-cli-core -- src/tools/web-fetch.test.tsPre-Merge Checklist