-
Notifications
You must be signed in to change notification settings - Fork 14.5k
use issuer instead of authorization_endpoint for oauth discovery #17332
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,6 +27,7 @@ export interface MCPOAuthConfig { | |
| clientId?: string; | ||
| clientSecret?: string; | ||
| authorizationUrl?: string; | ||
| issuer?: string; | ||
| tokenUrl?: string; | ||
| scopes?: string[]; | ||
| audiences?: string[]; | ||
|
|
@@ -161,14 +162,14 @@ export class MCPOAuthProvider { | |
| } | ||
|
|
||
| private async discoverAuthServerMetadataForRegistration( | ||
| authorizationUrl: string, | ||
| issuer: string, | ||
| ): Promise<{ | ||
| issuerUrl: string; | ||
| metadata: NonNullable< | ||
| Awaited<ReturnType<typeof OAuthUtils.discoverAuthorizationServerMetadata>> | ||
| >; | ||
| }> { | ||
| const authUrl = new URL(authorizationUrl); | ||
| const authUrl = new URL(issuer); | ||
|
|
||
| // Preserve path components for issuers with path-based discovery (e.g., Keycloak) | ||
| // Extract issuer by removing the OIDC protocol-specific path suffix | ||
|
|
@@ -784,6 +785,7 @@ export class MCPOAuthProvider { | |
| config = { | ||
| ...config, | ||
| authorizationUrl: discoveredConfig.authorizationUrl, | ||
| issuer: discoveredConfig.issuer, | ||
| tokenUrl: discoveredConfig.tokenUrl, | ||
| scopes: config.scopes || discoveredConfig.scopes || [], | ||
| // Preserve existing client credentials | ||
|
|
@@ -814,6 +816,7 @@ export class MCPOAuthProvider { | |
| ...config, | ||
| authorizationUrl: discoveredConfig.authorizationUrl, | ||
| tokenUrl: discoveredConfig.tokenUrl, | ||
| issuer: discoveredConfig.issuer, | ||
| scopes: config.scopes || discoveredConfig.scopes || [], | ||
| registrationUrl: discoveredConfig.registrationUrl, | ||
| // Preserve existing client credentials | ||
|
|
@@ -852,18 +855,14 @@ export class MCPOAuthProvider { | |
|
|
||
| // If no registration URL was previously discovered, try to discover it | ||
| if (!registrationUrl) { | ||
| // Extract server URL from authorization URL | ||
| if (!config.authorizationUrl) { | ||
| throw new Error( | ||
| 'Cannot perform dynamic registration without authorization URL', | ||
| ); | ||
| // Use the issuer to discover registration endpoint | ||
| if (!config.issuer) { | ||
| throw new Error('Cannot perform dynamic registration without issuer'); | ||
| } | ||
|
|
||
| debugLogger.debug('→ Attempting dynamic client registration...'); | ||
| const { metadata: authServerMetadata } = | ||
| await this.discoverAuthServerMetadataForRegistration( | ||
| config.authorizationUrl, | ||
| ); | ||
| await this.discoverAuthServerMetadataForRegistration(config.issuer); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The application performs OAuth discovery and dynamic client registration using URLs provided by external MCP servers without proper validation. Specifically, the Remediation: Implement strict validation for all URLs obtained from external metadata before using them in
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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: |
||
| registrationUrl = authServerMetadata.registration_endpoint; | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.