feat(security): implement robust IP validation and safeFetch foundation#21401
feat(security): implement robust IP validation and safeFetch foundation#21401alisa-alisa merged 1 commit intomainfrom
Conversation
|
Hi @alisa-alisa, thank you so much for your contribution to Gemini CLI! We really appreciate the time and effort you've put into this. We're making some updates to our contribution process to improve how we track and review changes. Please take a moment to review our recent discussion post: Improving Our Contribution Process & Introducing New Guidelines. Key Update: Starting January 26, 2026, the Gemini CLI project will require all pull requests to be associated with an existing issue. Any pull requests not linked to an issue by that date will be automatically closed. Thank you for your understanding and for being a part of our community! |
|
It is part of a split PR: #21348 |
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 establishes a critical security foundation for safe remote agent communication within the CLI. It introduces robust IP address validation and a connection-level SSRF protection layer, which are essential prerequisites for enabling future features like gRPC and remote agent discovery. The changes ensure the CLI cannot be exploited to probe internal networks or access sensitive metadata services, providing a secure communication pipe for all subsequent agent-to-agent functionalities. Highlights
Changelog
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: +89.2 kB (+0.34%) Total Size: 26.1 MB
ℹ️ View Unchanged
|
There was a problem hiding this comment.
Code Review
This pull request introduces robust Server-Side Request Forgery (SSRF) protection to the application's fetch operations by integrating the ipaddr.js library for accurate identification of private and reserved IP ranges, replacing a previous regex-based approach. A custom DNS lookup function (safeLookup) is implemented for undici agents, which filters out private IP addresses during DNS resolution and prevents connections to them, while explicitly allowing localhost requests. A new safeFetch function is provided that automatically uses this SSRF-protected dispatcher, and fetchWithTimeout is updated to leverage this protection, including re-mapping connection errors to a specific ERR_PRIVATE_NETWORK code. An asynchronous function isPrivateIpAsync was also added for more comprehensive private IP checks via DNS resolution. Comprehensive unit tests for these new utilities have been added. Additionally, the documentation for shell commands (docs/cli/tutorials/shell-commands.md) was updated to clarify that the AI model does not automatically 'see' the output of these commands unless explicitly provided. Finally, several dependencies, including @a2a-js/sdk, @grpc/grpc-js, and @bufbuild/protobuf, were updated or added in package-lock.json and packages/core/package.json.
8d10a1d to
f0ae3af
Compare
gundermanc
left a comment
There was a problem hiding this comment.
Looks fine to me but I don't have much context on this item. Gal might be a good point of contact.
f0ae3af to
d841e1f
Compare
d841e1f to
7652006
Compare
Summary
This PR establishes the security foundation for safe remote agent communication by implementing robust IP address validation and a connection-level SSRF protection layer. It is a prerequisite for enabling gRPC and remote agent discovery.
Details
ipaddr.jslibrary. This ensures reliable SSRF protection by correctly handling various IP notations (IPv4, IPv6, and IPv4-mapped IPv6) and matching them against standardized CIDR ranges.safeFetchutility that mirrors the nativefetchAPI but enforces connection-level IP filtering and DNS rebinding protection using a custom DNS lookup implementation (safeLookup).PrivateIpErrorclass and a centralizedhandleFetchErrorhelper. This ensures that security-related connection blocks are consistently mapped to a descriptiveFetchErrorwith a dedicatedERR_PRIVATE_NETWORKcode across the entire codebase.no-restricted-syntax) that restricts the use of the globalfetch()function. This guides contributors toward usingsafeFetch()for all new network logic, ensuring the security layer cannot be easily bypassed. Existing calls have been annotated for future migration.Why this is needed
To safely support remote agents, the CLI must ensure that it cannot be used as a proxy to probe internal networks or access sensitive metadata services (like AWS/GCP metadata endpoints). This PR provides the "secure pipe" that all subsequent A2A features will use.
Related Issues
Related to issue #18642.