Skip to content

Comments

use issuer instead of authorization_endpoint for oauth discovery#17332

Merged
scidomino merged 2 commits intogoogle-gemini:mainfrom
garrettsparks:garrett.sparks/fix-mcp-oauth-authorization-servers
Feb 18, 2026
Merged

use issuer instead of authorization_endpoint for oauth discovery#17332
scidomino merged 2 commits intogoogle-gemini:mainfrom
garrettsparks:garrett.sparks/fix-mcp-oauth-authorization-servers

Conversation

@garrettsparks
Copy link
Contributor

@garrettsparks garrettsparks commented Jan 22, 2026

Summary

When retrieving authorization server metadata for OAuth dynamic client registration, use issuer from /.well-known/oauth-authorization-server instead of authorization_endpoint.

Details

OAuth authorization servers may have a different authorization_endpoint URL than the authorization server itself. Gemini CLI currently attempts to use authorization_endpoint as the discovery endpoint for registration which results in failed OAuth registration because the authorization_endpoint is 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 issuer to 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_endpoint occurring 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.json

  "mcpServers": {
    "cfauditlogs": {
      "httpUrl": "https://auditlogs.mcp.cloudflare.com/mcp"
    }
  }

Pre-Merge Checklist

  • Updated relevant documentation and README (if needed)
  • Added/updated tests (if needed)
  • Noted breaking changes (if any)
  • Validated on required platforms/methods:
    • MacOS
      • npm run
      • npx
      • Docker
      • Podman
      • Seatbelt
    • Windows
      • npm run
      • npx
      • Docker
    • Linux
      • npm run
      • npx
      • Docker

@garrettsparks garrettsparks requested a review from a team as a code owner January 22, 2026 19:31
@google-cla
Copy link

google-cla bot commented Jan 22, 2026

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.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @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 authorization_endpoint, which could lead to registration failures. The change now correctly utilizes the issuer URL, ensuring robust and successful client registration by pointing to the authoritative source of metadata.

Highlights

  • OAuth Dynamic Client Registration: The mechanism for discovering OAuth authorization server metadata during dynamic client registration has been updated to use the issuer URL instead of the authorization_endpoint. This change addresses issues where the authorization_endpoint might not correctly provide the necessary metadata.
  • Configuration and Validation: The MCPOAuthConfig interface now includes an optional issuer property. A new validation step has been introduced to ensure that the issuer is present when dynamic client registration is attempted, throwing an error if it's missing.
  • Test Coverage: New test cases have been added to oauth-provider.test.ts and oauth-utils.test.ts to validate the correct usage and handling of the issuer property, including scenarios where it's missing during dynamic registration.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

security-high high

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:

  1. 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).
  2. Blocking cloud metadata service IPs (e.g., 169.254.169.254).
  3. Ensuring that the issuer in the metadata matches the expected issuer URL.
  4. Consider using an allow-list of trusted domains if possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@gemini-cli gemini-cli bot added the priority/p1 Important and should be addressed in the near term. label Jan 22, 2026
@garrettsparks garrettsparks force-pushed the garrett.sparks/fix-mcp-oauth-authorization-servers branch from 4b19acf to f4134d9 Compare January 22, 2026 20:28
@garrettsparks garrettsparks changed the title use issuer instead of a value from authorization_servers list for oauth discovery use issuer instead of authorization_endpoint for oauth discovery Jan 22, 2026
@garrettsparks garrettsparks force-pushed the garrett.sparks/fix-mcp-oauth-authorization-servers branch from f4134d9 to 069689a Compare January 22, 2026 20:33
@gemini-cli
Copy link
Contributor

gemini-cli bot commented Jan 24, 2026

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!

@gemini-cli gemini-cli bot closed this Jan 24, 2026
@scidomino scidomino reopened this Feb 18, 2026
@scidomino scidomino self-requested a review February 18, 2026 19:47
@gemini-cli gemini-cli bot added the help wanted We will accept PRs from all issues marked as "help wanted". Thanks for your support! label Feb 18, 2026
@scidomino scidomino added this pull request to the merge queue Feb 18, 2026
Merged via the queue into google-gemini:main with commit 037061e Feb 18, 2026
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

help wanted We will accept PRs from all issues marked as "help wanted". Thanks for your support! priority/p1 Important and should be addressed in the near term.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Gemini assumes authorization_endpoint base path is the authorize server

2 participants