Skip to content

fix(core): enforce RFC 9207 issuer identification in MCP OAuth flow - #29117

Merged
DavidAPierce merged 7 commits into
google-gemini:mainfrom
jvargassanchez-dot:b_463963247
Sep 2, 2026
Merged

DavidAPierce merged 7 commits into
google-gemini:mainfrom
jvargassanchez-dot:b_463963247

Conversation

@jvargassanchez-dot

@jvargassanchez-dot jvargassanchez-dot commented Aug 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Implements RFC 9207 (OAuth 2.0 Authorization Server Issuer Identification) validation in Gemini CLI's MCP OAuth flow to ensure response origin consistency and prevent unintended token routing.

Details

  • Extended OAuthAuthorizationResponse to include the optional iss?: string parameter.
  • Implemented areIssuersEqual(issuerA, issuerB) helper in oauth-flow.ts to normalize trailing slashes and origin paths per RFC 8414/9207 while rejecting userinfo and preserving queries/fragments.
  • Updated startCallbackServer to accept expectedIssuer?: string and enforce fail-closed RFC 9207 validation (rejecting missing iss or mismatched issuers with HTTP 400).
  • Formatted error messages and redacted debug logs to avoid reflecting unvalidated callback parameters or exposing internal issuer URLs.
  • Connected config.issuer from MCP discovery to startCallbackServer in MCPOAuthProvider.authenticate.
  • Updated documentation in docs/tools/mcp-server.md with RFC 9207 authorization server requirements.

Compatibility Note for MCP Developers

  • Remote MCP servers using OAuth must ensure their Authorization Server supports RFC 9207 by returning the iss parameter in the callback redirect (/oauth/callback?code=...&state=...&iss=https://<issuer>).
  • If an expected issuer is configured or discovered for the MCP server, callback responses missing iss will be rejected.

Related Issues

How to Validate

  1. Run targeted OAuth flow unit tests:
    npm test -w @google/gemini-cli-core -- src/utils/oauth-flow.test.ts src/mcp/oauth-provider.test.ts src/mcp/oauth-utils.test.ts

Pre-Merge Checklist

  • [ x] Updated relevant documentation and README (if needed)
  • [ x] 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
    • [ x] Linux
      • [ x] npm run
      • npx
      • Docker

Implements RFC 9207 Authorization Server Issuer Identification validation in the OAuth callback handler to defend against Identity Provider (IdP) mix-up attacks and prevent unauthorized token leakage.
@jvargassanchez-dot
jvargassanchez-dot requested a review from a team as a code owner August 28, 2026 17:56
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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 enhances the security of the OAuth authentication flow by implementing RFC 9207 validation. By verifying the issuer (iss) parameter returned during the callback, the system can now defend against Identity Provider (IdP) mix-up attacks. The changes include robust URL normalization, updated callback server logic, and comprehensive test coverage to ensure both modern and legacy authorization servers are handled correctly.

Highlights

  • RFC 9207 Implementation: Implemented Authorization Server Issuer Identification validation in the OAuth callback handler to mitigate IdP mix-up attacks.
  • Issuer Validation Logic: Added areIssuersEqual helper to normalize issuer URLs (handling trailing slashes and path differences) for robust comparison.
  • Callback Server Updates: Updated startCallbackServer to accept an expectedIssuer parameter and perform validation against the incoming iss parameter, while maintaining legacy support.
  • Observability: Added detailed debug and warning logs to track issuer validation status and identify potential security mismatches.
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 the 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 counterproductive. 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.

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. ↩

@github-actions github-actions Bot added the size/m A medium sized PR label Aug 28, 2026
@github-actions

github-actions Bot commented Aug 28, 2026 •

Copy link
Copy Markdown

📊 PR Size: size/L

  • Lines changed: 505
  • Additions: +484
  • Deletions: -21
  • Files changed: 5

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

Copy link
Copy Markdown
Contributor

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 implements RFC 9207 Authorization Server Issuer Identification to defend against OAuth Mix-Up attacks. It introduces an areIssuersEqual utility to compare issuer URLs and updates startCallbackServer to validate the incoming iss parameter against the expected issuer, accompanied by comprehensive unit tests. However, a security vulnerability was identified in the areIssuersEqual normalization logic: discarding the userinfo component from the URL allows an attacker to bypass the issuer check using a crafted URL (e.g., containing an @ symbol). It is recommended to apply the provided suggestion to preserve the full URL structure while stripping only query parameters, fragments, and trailing slashes.

Comment thread packages/core/src/utils/oauth-flow.ts Resolved
@gemini-cli gemini-cli Bot added the status/need-issue Pull requests that need to have an associated issue. label Aug 28, 2026
…63963247)

- Reject issuer URLs containing userinfo (username/password) to prevent RFC 9207 mix-up bypasses

- Preserve query parameters and fragments during normalization to avoid multi-tenant issuer collisions

- Normalize trailing slashes on pathname rather than href

- Add unit and callback server tests for userinfo spoofing and query parameter differentiation
@github-actions github-actions Bot added the size/l A large sized PR label Aug 28, 2026
@jvargassanchez-dot

Copy link
Copy Markdown
Contributor Author

/gemini review

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

Copy link
Copy Markdown
Contributor

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 implements RFC 9207 Authorization Server Issuer Identification to defend against OAuth mix-up attacks. It introduces an areIssuersEqual utility to normalize and compare issuer URLs, updates startCallbackServer to validate the incoming iss parameter against an expected issuer, and adds corresponding unit tests. The review feedback highlights a security downgrade vulnerability where the iss parameter is allowed to be omitted even when an expected issuer is configured; per RFC 9207, the server should strictly reject the response in this scenario to maintain a fail-closed security posture.

Comment thread packages/core/src/utils/oauth-flow.ts Resolved
…e error output (b/463963247)

- Reject callbacks when expectedIssuer is configured but iss is missing to prevent downgrade attacks

- Sanitize error messages and debug logs by removing raw issuer URLs and sensitive configuration details

- Add tests covering fail-closed missing iss behavior and information disclosure prevention
@jvargassanchez-dot

Copy link
Copy Markdown
Contributor Author

/gemini review

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

Copy link
Copy Markdown
Contributor

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 implements RFC 9207 Authorization Server Issuer Identification and Mix-Up defense in the OAuth flow. It introduces the areIssuersEqual utility function to safely compare issuer URLs by normalizing trailing slashes and origins, rejecting userinfo, and preserving query parameters and fragments. The startCallbackServer function is updated to accept an optional expectedIssuer parameter and enforce issuer validation when configured, rejecting authorization responses that lack a matching iss parameter. Comprehensive unit tests have been added to verify these security checks and normalization behaviors. There are no review comments, and I have no additional feedback to provide.

…th servers (b/463963247)

- Add authorization server requirements and callback redirect examples for RFC 9207

- Add configuration example with explicit issuer in settings.json

- Document issuer property under OAuth configuration properties
@jvargassanchez-dot
jvargassanchez-dot requested a review from a team as a code owner August 28, 2026 21:37
@jvargassanchez-dot jvargassanchez-dot changed the title fix(core): prevent OAuth IdP mix-up in MCP authentication (b/463963247) fix(core): prevent OAuth IdP mix-up in MCP authentication (463963247) Aug 28, 2026
@jvargassanchez-dot jvargassanchez-dot changed the title fix(core): prevent OAuth IdP mix-up in MCP authentication (463963247) fix(core): enforce RFC 9207 issuer identification in MCP OAuth flow Sep 1, 2026
@amelidev

amelidev commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

@jvargassanchez-dot Please resolve the outdated comments to reduce noise in the PR
Besides that it LGTM

DavidAPierce and others added 2 commits September 1, 2026 15:59
…ation

- Include iss parameter in simulated OAuth callback requests matching expected issuer

- Align test cases with fail-closed RFC 9207 response validation
@jvargassanchez-dot

Copy link
Copy Markdown
Contributor Author

/gemini review

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

Copy link
Copy Markdown
Contributor

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 implements OAuth Identity Provider (IdP) mix-up defense per RFC 9207 by validating the iss (issuer) parameter during the OAuth callback flow. It introduces an areIssuersEqual utility to normalize and compare issuer URLs (while rejecting userinfo to prevent spoofing) and updates startCallbackServer to enforce issuer validation when an expected issuer is configured. Additionally, comprehensive unit tests and documentation updates have been added. I have no feedback to provide.

@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Sep 2, 2026
@DavidAPierce
DavidAPierce added this pull request to the merge queue Sep 2, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Sep 2, 2026
@DavidAPierce
DavidAPierce added this pull request to the merge queue Sep 2, 2026
Merged via the queue into google-gemini:main with commit 55b495d Sep 2, 2026
32 of 33 checks passed
// Simulate OAuth callback
setTimeout(() => {
const mockReq = {
url: '/oauth/callback?code=auth_code_123&state=bW9ja19zdGF0ZV8xNl9ieXRlcw',

This comment was marked as spam.

@bhalsodnikunjhiteshbhai

This comment was marked as spam.

@rbond-vetsource

Copy link
Copy Markdown

This looks to have broken authenticating to datadog mcp.
After updating to v0.60.0 I am getting this when authenticating:

Failed to authenticate with MCP server 'datadog': Missing "iss" parameter in authorization response per RFC 9207

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/l A large sized PR size/m A medium sized PR status/need-issue Pull requests that need to have an associated issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants