Repository navigation
fix(core): enforce RFC 9207 issuer identification in MCP OAuth flow - #29117
Conversation
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.
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 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
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 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 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
|
|
📊 PR Size: size/L
|
There was a problem hiding this comment.
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.
…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
|
/gemini review |
There was a problem hiding this comment.
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.
…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
|
/gemini review |
There was a problem hiding this comment.
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 Please resolve the outdated comments to reduce noise in the PR |
…ation - Include iss parameter in simulated OAuth callback requests matching expected issuer - Align test cases with fail-closed RFC 9207 response validation
|
/gemini review |
There was a problem hiding this comment.
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.
| // Simulate OAuth callback | ||
| setTimeout(() => { | ||
| const mockReq = { | ||
| url: '/oauth/callback?code=auth_code_123&state=bW9ja19zdGF0ZV8xNl9ieXRlcw', |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
|
This looks to have broken authenticating to datadog mcp. |
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
OAuthAuthorizationResponseto include the optionaliss?: stringparameter.areIssuersEqual(issuerA, issuerB)helper inoauth-flow.tsto normalize trailing slashes and origin paths per RFC 8414/9207 while rejectinguserinfoand preserving queries/fragments.startCallbackServerto acceptexpectedIssuer?: stringand enforce fail-closed RFC 9207 validation (rejecting missingissor mismatched issuers with HTTP 400).config.issuerfrom MCP discovery tostartCallbackServerinMCPOAuthProvider.authenticate.docs/tools/mcp-server.mdwith RFC 9207 authorization server requirements.Compatibility Note for MCP Developers
issparameter in the callback redirect (/oauth/callback?code=...&state=...&iss=https://<issuer>).isswill be rejected.Related Issues
How to Validate
npm test -w @google/gemini-cli-core -- src/utils/oauth-flow.test.ts src/mcp/oauth-provider.test.ts src/mcp/oauth-utils.test.tsPre-Merge Checklist