Skip to content

fix(core): align OAuth callback iss parameter validation with RFC 9207 metadata - #29616

Merged
DavidAPierce merged 3 commits into
google-gemini:mainfrom
luisfelipe-alt:bugfix/WT-engineer_568383679
Oct 6, 2026
Merged

DavidAPierce merged 3 commits into
google-gemini:mainfrom
luisfelipe-alt:bugfix/WT-engineer_568383679

Conversation

@luisfelipe-alt

Copy link
Copy Markdown
Contributor

Summary

This PR aligns OAuth callback iss (issuer) parameter validation in Gemini CLI
with RFC 9207 and the MCP
authorization specification. Specifically, it requires the iss query
parameter in authorization callback redirects only when the authorization
server metadata explicitly declares
authorization_response_iss_parameter_supported: true, while continuing to
validate iss against the expected issuer whenever iss is present in the
callback response.

This resolves OAuth authentication failures with MCP servers (for example,
Notion MCP at https://mcp.notion.com/mcp) that publish an issuer field in
/.well-known/oauth-authorization-server metadata without declaring
authorization_response_iss_parameter_supported: true and omit iss from the
authorization redirect URI.

Details

Per RFC 9207 Section 3, authorization_response_iss_parameter_supported is an
optional boolean metadata parameter that defaults to false when omitted.
Previously, OAuthAuthorizationServerMetadata and MCPOAuthConfig did not
track this property, and startCallbackServer() required iss in every
callback redirect whenever expectedIssuer was configured.

This change updates the OAuth discovery and callback pipeline across four core
modules:

  • packages/core/src/mcp/oauth-utils.ts: Adds
    authorization_response_iss_parameter_supported?: boolean to
    OAuthAuthorizationServerMetadata and maps it to
    authorizationResponseIssParameterSupported in
    OAuthUtils.metadataToOAuthConfig().
  • packages/core/src/mcp/oauth-provider.ts: Adds
    authorizationResponseIssParameterSupported?: boolean to MCPOAuthConfig,
    preserves the property across both WWW-Authenticate and standard discovery
    configuration merges in MCPOAuthProvider.authenticate(), and passes it to
    startCallbackServer().
  • packages/core/src/tools/mcp-client.ts: Propagates
    authorizationResponseIssParameterSupported when building oauthAuthConfig
    in handleAutomaticOAuth() and connectToMcpServer().
  • packages/core/src/utils/oauth-flow.ts: Adds an optional
    requireIssInResponse?: boolean parameter to startCallbackServer() so
    callbacks missing iss are rejected only when requireIssInResponse is
    true, while callbacks containing iss are always validated with
    areIssuersEqual(iss, expectedIssuer).
  • Tests and documentation: Updates unit tests (oauth-flow.test.ts,
    oauth-utils.test.ts, oauth-provider.test.ts), adds an integration test
    suite (oauth-callback-iss-handling.test.ts) covering all four combinations
    of authorization_response_iss_parameter_supported and callback iss
    presence, and updates docs/tools/mcp-server.md.

Related Issues

Fixes #29477

How to Validate

Follow these steps to validate the changes locally:

  1. Run the targeted Vitest unit and integration test suites in
    @google/gemini-cli-core:

    npm test -w @google/gemini-cli-core -- \
      src/mcp/oauth-callback-iss-handling.test.ts \
      src/utils/oauth-flow.test.ts \
      src/mcp/oauth-utils.test.ts \
      src/mcp/oauth-provider.test.ts \
      src/tools/mcp-client.test.ts
  2. Verify that all five test suites (252 tests) pass, including the five
    scenarios in oauth-callback-iss-handling.test.ts:

    • Callback without iss succeeds when
      authorization_response_iss_parameter_supported is omitted in metadata.
    • Callback with iss validates issuer matching when
      authorization_response_iss_parameter_supported is true.
    • Callback without iss fails with HTTP 400 when
      authorization_response_iss_parameter_supported is true.
    • Callback with iss validates issuer matching even when
      authorization_response_iss_parameter_supported is omitted or false.
    • Direct startCallbackServer() invocation with expectedIssuer and
      omitted requireIssInResponse resolves when iss is absent.
  3. Run the linter and TypeScript type checker across all workspaces:

    npm run lint
    npm run typecheck

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

@luisfelipe-alt
luisfelipe-alt requested review from a team as code owners October 2, 2026 19:11
@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 aligns the Gemini CLI's OAuth callback validation with RFC 9207 and the MCP authorization specification. By introducing support for the 'authorization_response_iss_parameter_supported' metadata flag, the system now correctly handles authorization servers that omit the 'iss' parameter in redirects when not explicitly required, resolving authentication failures with services like Notion MCP.

Highlights

  • RFC 9207 Compliance: Updated OAuth callback validation to support the 'authorization_response_iss_parameter_supported' metadata flag, ensuring compatibility with servers that do not explicitly require the 'iss' parameter.
  • OAuth Pipeline Updates: Propagated the 'authorizationResponseIssParameterSupported' property across discovery, configuration, and callback handling modules to ensure correct runtime behavior.
  • Test Coverage: Added a comprehensive integration test suite covering various scenarios of 'iss' presence and metadata configuration, alongside updates to existing unit tests.
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/l A large sized PR label Oct 2, 2026
@github-actions

github-actions Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

📊 PR Size: size/L

  • Lines changed: 893
  • Additions: +871
  • Deletions: -22
  • Files changed: 12

@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 updates the OAuth callback flow to conditionally validate the iss (issuer) parameter per RFC 9207 and the Model Context Protocol (MCP) specification. The presence of the iss parameter is now only strictly enforced if the authorization server metadata explicitly declares authorization_response_iss_parameter_supported: true. If this parameter is omitted or false, callbacks without iss are accepted, while mismatched issuers are still rejected. The changes span across the core OAuth provider, utilities, client logic, documentation, and comprehensive unit tests. There are no review comments to assess, and I have no additional feedback to provide.

@luisfelipe-alt

Copy link
Copy Markdown
Contributor Author

/gemini review

@gemini-cli gemini-cli Bot added priority/p1 Important and should be addressed in the near term. area/security Issues related to security labels Oct 2, 2026

@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 updates the OAuth flow to conditionally validate the iss parameter in authorization responses per RFC 9207 and the MCP specification, ensuring it is only strictly required when the server's metadata sets authorization_response_iss_parameter_supported to true. This prevents connection failures with providers that omit the parameter. The review feedback highlights a critical issue in packages/core/src/tools/mcp-client.ts (in both handleAutomaticOAuth and connectToMcpServer) where the user's explicit configuration for authorizationResponseIssParameterSupported is ignored and overridden by discovered metadata. It is recommended to use nullish coalescing to prioritize the user's settings over the discovered metadata.

Comment thread packages/core/src/tools/mcp-client.ts Resolved
Comment thread packages/core/src/tools/mcp-client.ts Resolved
@luisfelipe-alt

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 updates the OAuth callback flow to conditionally enforce the iss (issuer) parameter validation per RFC 9207 and the MCP specification. Specifically, the iss parameter is only required in the callback redirect if the authorization server metadata explicitly declares authorization_response_iss_parameter_supported: true. If this parameter is omitted or false, callbacks without iss are accepted, while any present iss is still validated against the expected issuer. The changes span documentation, core OAuth provider and client logic, callback server handling, and comprehensive unit tests. There are no review comments provided, so I have no feedback to evaluate.

@github-actions

github-actions Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

✅ 69 tests passed successfully on gemini-3-flash-preview.

🧠 Model Steering Guidance

This PR modifies files that affect the model's behavior (prompts, tools, or instructions).

  • ⚠️ Consider adding Evals: No behavioral evaluations (evals/*.eval.ts) were added or updated in this PR. Consider adding a test case to verify the new behavior and prevent regressions.

This is an automated guidance message triggered by steering logic signatures.

@luisfelipe-alt

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 introduces support for the authorization_response_iss_parameter_supported metadata parameter from RFC 9207 and the Model Context Protocol (MCP) specification. It allows Gemini CLI to conditionally validate the iss parameter in OAuth callback redirects based on discovered server metadata or explicit user configuration (authorizationResponseIssParameterSupported in settings.json). The changes span the OAuth provider, client, and callback server implementation, accompanied by updated documentation and comprehensive unit tests. I have no feedback to provide as there are no review comments and the implementation is well-tested and documented.

@TrueAlpha-spiral

TrueAlpha-spiral commented Oct 5, 2026 via email

Copy link
Copy Markdown

@DavidAPierce

Copy link
Copy Markdown
Contributor

🟡 Improvements

  1. Strict boolean check vs. truthy coercion in OAuthUtils.metadataToOAuthConfig

    • File: packages/core/src/mcp/oauth-utils.ts (lines 326–328)
      authorizationResponseIssParameterSupported: Boolean(
        metadata.authorization_response_iss_parameter_supported,
      ),
    • Observation: If an external authorization server returns a non-boolean JSON string such as "false" or "0" (which can occur with loosely typed OAuth implementations), Boolean("false") evaluates to true, causing Gemini CLI to erroneously require the iss parameter and reject valid callbacks.
    • Suggested Fix: Use an explicit equality check:
      authorizationResponseIssParameterSupported:
        metadata.authorization_response_iss_parameter_supported === true,
      This strictly guarantees that only an explicit boolean true enables required issuer verification in the redirect per RFC 9207 §3.
  2. Restore global.fetch in test cleanup

    • File: packages/core/src/mcp/oauth-callback-iss-handling.test.ts (lines 54–56, 115–120)
      const realFetch = global.fetch;
      const mockFetch = vi.fn();
      global.fetch = mockFetch;
    • Observation: In afterEach, vi.restoreAllMocks() is called, but global.fetch was directly assigned rather than spied on with vi.spyOn. If tests are run sequentially in a shared worker process or with --no-threads, global.fetch remains patched as mockFetch.
    • Suggested Fix: Add an afterAll hook to restore global.fetch:
      afterAll(() => {
        global.fetch = realFetch;
      });
  3. Expose authorizationResponseIssParameterSupported in schemas/settings.schema.json

    • File: schemas/settings.schema.json
    • Observation: While mcpServers.*.oauth permits additional properties via "additionalProperties": true, explicitly declaring authorizationResponseIssParameterSupported under the oauth properties definition in schemas/settings.schema.json with a description and boolean type will provide IDE autocomplete, hover documentation, and validation for users configuring custom OAuth servers in .gemini/settings.json.

🟢 Nitpicks

  1. Callback triggering in integration test helper
    • File: packages/core/src/mcp/oauth-callback-iss-handling.test.ts (lines 145–147)
      setTimeout(() => {
        realFetch(callbackUrl.toString()).catch(() => {});
      }, 10);
    • Observation: Because startCallbackServer() already awaits callbackServer.port before invoking openBrowserSecurely, the HTTP server is guaranteed to be listening. Using queueMicrotask(() => { void realFetch(...); }) or setImmediate avoids relying on arbitrary 10ms timer delays under heavy CI VM load.

…7 metadata

Propagate authorization_response_iss_parameter_supported from OAuth authorization server metadata through MCPOAuthConfig, mcp-client, and MCPOAuthProvider to startCallbackServer.
  Require the iss query parameter in authorization callbacks only when the server explicitly declares authorization_response_iss_parameter_supported: true, while continuing to validate iss
  against the expected issuer whenever iss is present in the callback response.

Fixes google-gemini#29477
@luisfelipe-alt

luisfelipe-alt commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor Author

🟡 Improvements

  1. Strict boolean check vs. truthy coercion in OAuthUtils.metadataToOAuthConfig

    • File: packages/core/src/mcp/oauth-utils.ts (lines 326–328)

      authorizationResponseIssParameterSupported: Boolean(
        metadata.authorization_response_iss_parameter_supported,
      ),
    • Observation: If an external authorization server returns a non-boolean JSON string such as "false" or "0" (which can occur with loosely typed OAuth implementations), Boolean("false") evaluates to true, causing Gemini CLI to erroneously require the iss parameter and reject valid callbacks.

    • Suggested Fix: Use an explicit equality check:

      authorizationResponseIssParameterSupported:
        metadata.authorization_response_iss_parameter_supported === true,

      This strictly guarantees that only an explicit boolean true enables required issuer verification in the redirect per RFC 9207 §3.

  2. Restore global.fetch in test cleanup

    • File: packages/core/src/mcp/oauth-callback-iss-handling.test.ts (lines 54–56, 115–120)
      const realFetch = global.fetch;
      const mockFetch = vi.fn();
      global.fetch = mockFetch;
    • Observation: In afterEach, vi.restoreAllMocks() is called, but global.fetch was directly assigned rather than spied on with vi.spyOn. If tests are run sequentially in a shared worker process or with --no-threads, global.fetch remains patched as mockFetch.
    • Suggested Fix: Add an afterAll hook to restore global.fetch:
      afterAll(() => {
        global.fetch = realFetch;
      });
  3. Expose authorizationResponseIssParameterSupported in schemas/settings.schema.json

    • File: schemas/settings.schema.json
    • Observation: While mcpServers.*.oauth permits additional properties via "additionalProperties": true, explicitly declaring authorizationResponseIssParameterSupported under the oauth properties definition in schemas/settings.schema.json with a description and boolean type will provide IDE autocomplete, hover documentation, and validation for users configuring custom OAuth servers in .gemini/settings.json.

🟢 Nitpicks

  1. Callback triggering in integration test helper

    • File: packages/core/src/mcp/oauth-callback-iss-handling.test.ts (lines 145–147)
      setTimeout(() => {
        realFetch(callbackUrl.toString()).catch(() => {});
      }, 10);
    • Observation: Because startCallbackServer() already awaits callbackServer.port before invoking openBrowserSecurely, the HTTP server is guaranteed to be listening. Using queueMicrotask(() => { void realFetch(...); }) or setImmediate avoids relying on arbitrary 10ms timer delays under heavy CI VM load.

@DavidAPierce

Strict boolean check:
Done. metadataToOAuthConfig now uses metadata.authorization_response_iss_parameter_supported === true, so only a literal boolean true makes the iss parameter required.
Added a parameterized test in oauth-utils.test.ts covering "false", "true", "0", "1", 1 and null, all mapping to false

Restore global.fetch:
Done. Added an afterAll hook in oauth-callback-iss-handling.test.ts that restores global.fetch = realFetch, since vi.restoreAllMocks() doesn't undo the direct assignment.

Schema exposure:
Done. Declared authorizationResponseIssParameterSupported as a documented boolean under oauth in settingsSchema.ts (both MCPServerConfig and RequiredMcpServerConfig) and regenerated schemas/settings.schema.json with npm run schema:settings. additionalProperties: true is kept for the other OAuth fields.

Test callback timing (nit):
Done. Replaced the 10 ms setTimeout with setImmediate, since the provider already awaits the callback server port before calling openBrowserSecurely.

Exact iss comparison:
Thanks for the suggestion. Issuer comparison is handled by areIssuersEqual, which already exists on main and isn't modified by this PR. Its trailing-slash and host normalization is intentional and already covered by existing tests. To keep this PR focused on authorization_response_iss_parameter_supported, I'd suggest tracking a switch to strict RFC 3986 simple string comparison in a separate issue.

@luisfelipe-alt

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 support for the authorizationResponseIssParameterSupported configuration option, aligning Gemini CLI's OAuth flow with RFC 9207 and the Model Context Protocol (MCP) specification. It updates the settings schema, configuration interfaces, metadata discovery logic, and the local callback server to dynamically require or accept missing iss parameters based on discovered server metadata or explicit user configuration. Additionally, comprehensive unit tests have been added to verify these behaviors, and the documentation has been updated accordingly. There are no review comments provided, so I have no additional feedback to offer.

Note: Security Review did not run due to the size of the PR.

@DavidAPierce
DavidAPierce enabled auto-merge October 6, 2026 21:05
@DavidAPierce
DavidAPierce added this pull request to the merge queue Oct 6, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 6, 2026
@DavidAPierce
DavidAPierce enabled auto-merge October 6, 2026 21:50
@DavidAPierce
DavidAPierce added this pull request to the merge queue Oct 6, 2026
Merged via the queue into google-gemini:main with commit 23c77ca Oct 6, 2026
34 of 35 checks passed
Blackmanx pushed a commit to Blackmanx/gemini-cli that referenced this pull request Oct 20, 2026

This branch was previously deployed

1 inactive deployment
eval-gate — f1450da9 Deployed Oct 6, 2026 by luisfelipe-alt via Evaluate Steering & Regressions #2145
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/security Issues related to security priority/p1 Important and should be addressed in the near term. size/l A large sized PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MCP OAuth: RFC 9207 check rejects iss-less callbacks from servers that do not advertise authorization_response_iss_parameter_supported

3 participants