fix(core): validate MCP OAuth resources from metadata URL - #27139
fix(core): validate MCP OAuth resources from metadata URL#27139pragnyanramtha wants to merge 6 commits into
Conversation
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 addresses an issue where path-based MCP server URLs failed validation during OAuth metadata discovery when falling back to root-based endpoints. By shifting the validation logic to rely on the metadata URL itself rather than the original server path, the system now correctly handles resource identification in both standard and fallback scenarios, ensuring better adherence to RFC 9728. 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
|
There was a problem hiding this comment.
Code Review
This pull request introduces the buildResourceParameterFromMetadataUrl utility to OAuthUtils to correctly extract resource identifiers from metadata URLs according to RFC 9728. The OAuth discovery logic has been updated to use this method for improved validation, supported by new test cases for various discovery scenarios. Feedback was provided regarding a high-severity security vulnerability in the new utility method, where improper handling of protocol-relative paths could allow for URL host injection and bypass origin-binding security requirements.
|
Hi there! Thank you for your interest in contributing to Gemini CLI. To ensure we maintain high code quality and focus on our prioritized roadmap, we only guarantee review and consideration of pull requests for issues that are explicitly labeled as 'help wanted'. This PR will be closed in 7 days if it remains without that designation. We encourage you to find and contribute to existing 'help wanted' issues in our backlog! Thank you for your understanding. |
|
This pull request is being closed as it has been open for 14 days without a 'help wanted' designation. We encourage you to find and contribute to existing 'help wanted' issues in our backlog! Thank you for your understanding. |
Fixes #20017.
Summary
.well-known/oauth-protected-resourcefallback metadata to validate against the root resource for path-based MCP server URLsWWW-AuthenticatediscoveryRoot cause
For path-based MCP URLs like
https://mcp.slack.com/mcp, discovery first tries the path-based metadata URL and then falls back to the root metadata URL when the path endpoint is unavailable. After that fallback succeeded, validation still compared the returned root resource against the original MCP server path, producing errors such asProtected resource https://mcp.slack.com does not match expected https://mcp.slack.com/mcp.Relation to prior OAuth fixes: #19038 fixed the earlier 401/resource-metadata routing path. This PR is a follow-up for the later #20017 root-metadata fallback/resource mismatch.
Validation
npm exec -- vitest run packages/core/src/mcp/oauth-utils.test.tsnpm run test:ci --workspace @google/gemini-cli-core -- src/mcp/oauth-utils.test.tsnpm exec -- prettier --check packages/core/src/mcp/oauth-utils.ts packages/core/src/mcp/oauth-utils.test.tsnpm exec -- eslint packages/core/src/mcp/oauth-utils.ts packages/core/src/mcp/oauth-utils.test.ts --max-warnings 0npm run typecheck --workspace @google/gemini-cli-corenpm run build --workspace @google/gemini-cli-coregit diff --check