[Remote Agents] Add gRPC transport support#21348
Conversation
|
/gemini review |
|
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! |
|
Size Change: +242 kB (+0.93%) Total Size: 26.2 MB
ℹ️ View Unchanged
|
There was a problem hiding this comment.
Code Review
This pull request enhances remote agent support by integrating native gRPC communication via @a2a-js/sdk, improving agent card normalization, registry indexing, and URL resolution, with expanded test coverage. However, the resolveAgentCard method fetches remote agent cards from user-supplied URLs without sufficient validation, introducing a high-severity Server-Side Request Forgery (SSRF) vulnerability. Additionally, the current URL parsing logic is fragile and could lead to incorrect agent card resolution in edge cases. It is recommended to implement robust URL validation for agent card discovery.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces support for gRPC transport in the A2A client manager and enhances agent configuration and security. Key changes include updating @a2a-js/sdk, @bufbuild/protobuf, and @grpc/grpc-js dependencies, and extending the Settings interface to include experimental.enableAgents and agents overrides. The A2AClientManager now configures ClientFactory with gRPC, REST, and JSON-RPC transports, and includes new logic to normalize agent card URLs, handle .well-known paths, and implement Server-Side Request Forgery (SSRF) protection by rejecting private IP ranges for remote agents (except localhost). The a2aUtils module was updated with normalizeAgentCard to ensure consistent agent card structures and getGrpcCredentials for dynamic gRPC credential handling. The review comment highlights a critical security vulnerability: the current SSRF protection only validates the initial agent card URL, but not URLs specified within the agent card manifest itself (e.g., url or additionalInterfaces fields), which could allow an attacker to redirect connections to internal services. The reviewer recommends extending isPrivateIp validation to all URLs extracted from the agent card before client initialization.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces significant enhancements for remote agent communication by adding native gRPC support and upgrading the A2A SDK. It also includes comprehensive agent card normalization, a fix for registry indexing using canonical names, and thorough test coverage, improving functionality and robustness. However, a high-severity vulnerability has been identified: the implemented 'Deep SSRF Protection' is incomplete. It relies solely on string-based hostname checks and lacks DNS resolution, making it susceptible to bypasses via attacker-controlled domains that resolve to private IPs. This undermines the explicit goal of preventing access to sensitive private IP ranges like AWS/GCP metadata services.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces significant enhancements for remote agent communication, including native gRPC support and robust, multi-layered SSRF protection. While the changes are well-structured and include comprehensive tests, the implemented SSRF protection has weaknesses, including bypasses via 0.0.0.0/:: and vulnerability to DNS rebinding, which need to be addressed for robust security. Furthermore, a high-severity issue was identified in the URL parsing logic that could lead to incorrect agent card resolution when a URL contains a specially crafted fragment.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request adds valuable support for gRPC transport in remote agents and introduces significant security enhancements against SSRF attacks. However, a high-severity bypass was identified in the IP address validation logic due to incomplete coverage of IPv6 representations, specifically IPv4-mapped IPv6 addresses, which could allow an attacker to bypass the SSRF filters and access internal resources. Furthermore, the DNS rebinding protection, implemented via a custom undici lookup function, does not extend to gRPC connections, leaving the gRPC transport susceptible to SSRF attacks.
dd72294 to
4128c8f
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces significant enhancements by adding native gRPC transport support for remote agents and implementing multi-layered SSRF protection. The changes are extensive and well-structured, including robust URL normalization, DNS rebinding protection, and improved test coverage. I've identified a critical security issue in the regular expression used for validating IPv4-mapped IPv6 addresses, which could potentially allow for an SSRF bypass. The detailed comment for the fix has been retained as it does not contradict any provided rules.
Note: Security Review did not run due to the size of the PR.
4128c8f to
8a9c5aa
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces robust support for gRPC transport for remote agents, along with significant security enhancements, including native gRPC integration, deep SSRF protection, DNS rebinding mitigation, and more robust agent card normalization. However, critical security vulnerabilities have been identified in the SSRF implementation, specifically incomplete private IP range lists, fail-open behavior on DNS resolution failures, and a DNS rebinding vulnerability in the new safeFetch utility. These issues could allow an attacker to bypass SSRF protections and access internal network services. Additionally, there is critical feedback regarding the DNS pinning logic for gRPC that needs to be addressed to ensure its correctness and security.
8a9c5aa to
3e87f85
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces significant enhancements, most notably adding gRPC transport support for remote agents and implementing robust, multi-layered SSRF and DNS rebinding protection. However, a high-severity vulnerability was identified in the agent acknowledgement logic, where the use of a URL-based hash for remote agents allows for Indirect Prompt Injection if the remote agent card content is modified after initial approval. Implementing content-based hashing for acknowledgement is recommended to address this. Additionally, the IP address validation logic could be made more robust to further strengthen the new security measures.
…d URL splitting fix
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces significant enhancements for remote agents, including gRPC support and robust security measures against SSRF and DNS rebinding. However, a critical Server-Side Request Forgery (SSRF) vulnerability was identified in the AgentRegistry. The new content-based hashing logic fetches remote agent cards without using the protected fetch implementation, specifically lacking DNS rebinding protection. This could allow an attacker to probe internal networks or access sensitive metadata services if a malicious agent configuration is loaded. Please ensure that security measures are consistently applied to prevent such attacks.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces significant enhancements, most notably adding gRPC transport support for remote agents and implementing robust, multi-layered SSRF protection. The use of ipaddr.js for reliable IP validation and a custom safeLookup function for DNS rebinding protection are excellent security improvements. The change to content-based hashing for agent acknowledgement is a critical fix to prevent potential prompt injection attacks. I've found one critical security issue where the new safeFetch implementation was not used in one of the new code paths, which I've detailed in a specific comment. Otherwise, the code is well-structured, the new tests are comprehensive, and the changes align well with the project's goals of being a powerful and secure tool.
Note: Security Review did not run due to the size of the PR.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces significant and well-executed improvements for remote agent communication, notably adding gRPC support and robust security enhancements. The implementation of multi-layered SSRF protection, including connection-level DNS filtering with safeLookup and content-based hashing for agent acknowledgement, is excellent. The move to ipaddr.js for IP validation and the fixes for URL normalization and registry indexing greatly improve the system's reliability. I have one critical comment regarding the handling of Request objects in a new fetch wrapper, which could lead to incorrect request methods being used.
…registry and client manager
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces significant and well-implemented enhancements, particularly in adding gRPC support and robust SSRF protection for remote agents. The use of ipaddr.js, connection-level IP filtering, and content-based hashing for agent acknowledgement are excellent security improvements. However, the critical issue identified in the agent registration logic, which breaks name overrides, remains. Please see the detailed comment for more information.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces significant enhancements by adding gRPC transport support for remote agents and implementing a robust, multi-layered defense against Server-Side Request Forgery (SSRF) vulnerabilities. The changes are comprehensive, including native gRPC integration, consistent SSRF protection through a new safeFetch utility, improved IP validation using ipaddr.js, and DNS rebinding protection. The agent acknowledgement mechanism has been hardened with content-based hashing, and agent card normalization and URL handling have been made more reliable. The codebase is cleaner and more secure as a result. The changes are well-tested, with new unit and integration tests covering the new functionality and security features. After a thorough review, I found no issues of high or critical severity. The implementation is solid and demonstrates excellent attention to security and correctness.
Summary
This PR introduces robust support for the A2A V0 protocol and enables native gRPC communication for remote agents using the latest
@a2a-js/sdk. It focuses on standardizing agent card normalization, improving discovery reliability across different transport layers, and ensuring correct agent indexing within the registry.Details
🛠 Core Improvements
GrpcTransportFactoryand configuring secure/insecure credentials based on the agent's target URL.safeFetchutility that mirrors the nativefetchAPI. This protected implementation is used consistently across the codebase, including inAgentRegistryfor card resolution/hashing and inA2AClientManagerfor agent communication. It enforces connection-level IP filtering and DNS rebinding protection (usingsafeLookup) to prevent internal network probing.ipaddr.jslibrary. This ensures more reliable and maintainable SSRF protection by correctly handling various IP notations (IPv4, IPv6, and IPv4-mapped IPv6) and matching them against standardized CIDR ranges.AgentCardto detect modifications after initial approval, preventing Indirect Prompt Injection attacks that could result from modified remote agent configurations.URLAPI and direct object manipulation to ensure reliable agent discovery even in the presence of fragments or query parameters.a2aUtils.tsto handle varied agent card formats, ensuringtransportandurlfields are consistently populated and discovery works reliably.packages/a2a-serverto respectenableAgentsandagentssettings, ensuring remote agents can be configured and used within the experimental A2A server environment.AgentRegistryusing their (potentially overridden) name. This ensures that when an agent's name is modified via settings, the LLM can still correctly look up the agent's definition during tool execution. Added explicit validation to prevent name collisions during this process..well-knownto URLs that already contained the standard path.@a2a-js/sdk@0.3.10to leverage improved client factory patterns and better type safety.🧪 Enhanced Test Coverage
a2aUtils.test.ts: Validates "History Fallback" and conservative normalization.a2a-client-manager.test.ts: Tests protocol routing, robust URL resolution, and multi-layer SSRF protection including DNS rebinding scenarios.registry.test.ts: Added validation for canonical name indexing during registration.config.test.ts(a2a-server): Verified that agent settings are correctly propagated to the core configuration.Related Issues
Closes ticket #18642.
How to Validate
1. Automated Tests
Run the comprehensive test suite:
npm test -w @google/gemini-cli-core -- src/agents/a2aUtils.test.ts src/agents/a2a-client-manager.test.ts src/agents/registry.test.ts2. Live gRPC V0 Validation
Verify communication against the official A2A-Go reference implementation:
A. Prepare the Go Server (
a2a-gorepo)examples/helloworld/server/grpc/main.go, update the import:"github.com/a2aproject/a2a-go/a2agrpc/v1""github.com/a2aproject/a2a-go/a2agrpc/v0"a2a/core.go, ensure theVersionconstant is set to"0.1":const Version ProtocolVersion = "0.1"go run examples/helloworld/server/grpc/main.goB. Prepare the Gemini CLI (this repo)
.gemini/agents/grpc-test-agent.mdwith:.gemini/settings.json, ensure agents are enabled:{ "experimental": { "enableAgents": true } }C. Verify Communication
curl: