use issuer instead of authorization_endpoint for oauth discovery#17332
Conversation
|
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 @garrettsparks, 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 refines the OAuth dynamic client registration process within the Gemini CLI by correcting the source used for authorization server metadata discovery. Previously, the system relied on 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
|
There was a problem hiding this comment.
Code Review
This pull request refactors the OAuth discovery mechanism to use the issuer URL instead of authorization_endpoint for dynamic client registration, which improves alignment with OAuth specifications. The changes are consistently applied and well-tested. However, a critical Server-Side Request Forgery (SSRF) vulnerability has been identified. This pre-existing issue arises because the issuer URL from external metadata is used to make network requests without validation, allowing potential exploitation by a malicious server. Although noted as out of scope by the author, this high-severity risk requires strict URL validation for all discovered endpoints.
| await this.discoverAuthServerMetadataForRegistration( | ||
| config.authorizationUrl, | ||
| ); | ||
| await this.discoverAuthServerMetadataForRegistration(config.issuer); |
There was a problem hiding this comment.
The application performs OAuth discovery and dynamic client registration using URLs provided by external MCP servers without proper validation. Specifically, the issuer URL (and subsequent URLs derived from it or provided in metadata) is used in fetch calls. A malicious MCP server can provide URLs pointing to internal services (e.g., http://localhost, http://169.254.169.254) or other sensitive endpoints, leading to Server-Side Request Forgery (SSRF). This can be used to probe internal networks or access cloud metadata services from the user's machine.
Remediation: Implement strict validation for all URLs obtained from external metadata before using them in fetch calls. This should include:
- Blocking internal IP ranges (e.g.,
127.0.0.0/8,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16). - Blocking cloud metadata service IPs (e.g.,
169.254.169.254). - Ensuring that the
issuerin the metadata matches the expected issuer URL. - Consider using an allow-list of trusted domains if possible.
There was a problem hiding this comment.
This behavior is already present in the codebase and is not modified as a result of this change: authorization_endpoint (currently in use) is unvalidated.
4b19acf to
f4134d9
Compare
f4134d9 to
069689a
Compare
|
Hi there! Thank you for your contribution to Gemini CLI. We really appreciate the time and effort you've put into this pull request. To keep our backlog manageable and ensure we're focusing on current priorities, we are closing pull requests that haven't seen maintainer activity for 30 days. Currently, the team is prioritizing work associated with 🔒 maintainer only or help wanted issues. If you believe this change is still critical, please feel free to comment with updated details. Otherwise, we encourage contributors to focus on open issues labeled as help wanted. Thank you for your understanding! |
Summary
When retrieving authorization server metadata for OAuth dynamic client registration, use
issuerfrom/.well-known/oauth-authorization-serverinstead ofauthorization_endpoint.Details
OAuth authorization servers may have a different
authorization_endpointURL than the authorization server itself. Gemini CLI currently attempts to useauthorization_endpointas the discovery endpoint for registration which results in failed OAuth registration because theauthorization_endpointis not necessarily expected to be able to provide authorization server metadata.For dynamic client registration, Gemini CLI should use the actual authorization server URL from
issuerto discovery authorization server metadata.📓 NOTE: This does not fix any existing SSRF vulnerability that may be present with gemini-cli's MCP integration (there was no validation of
authorization_endpointoccurring before either). I would consider that out of scope for this change; it should be addressed separately.Related Issues
Fixes #19458
How to Validate
Tested with cloudflare's audit log MCP server (
https://auditlogs.mcp.cloudflare.com/mcp)in
settings.jsonPre-Merge Checklist