@ai-sdk/mcp 1.0.91 → 1.0.92
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/index.js +9 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +9 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/tool/oauth.ts +14 -1
package/package.json
CHANGED
package/src/tool/oauth.ts
CHANGED
|
@@ -631,8 +631,12 @@ export function buildDiscoveryUrls(
|
|
|
631
631
|
expectedIssuer: pathIssuer,
|
|
632
632
|
});
|
|
633
633
|
|
|
634
|
+
// Assign the path rather than resolving it as a URL reference: a pathname
|
|
635
|
+
// beginning with // would otherwise replace the authorization server host.
|
|
636
|
+
const oidcDiscoveryUrl = new URL(url.origin);
|
|
637
|
+
oidcDiscoveryUrl.pathname = `${pathname}/.well-known/openid-configuration`;
|
|
634
638
|
urlsToTry.push({
|
|
635
|
-
url:
|
|
639
|
+
url: oidcDiscoveryUrl,
|
|
636
640
|
type: 'oidc',
|
|
637
641
|
expectedIssuer: pathIssuer,
|
|
638
642
|
});
|
|
@@ -670,8 +674,17 @@ export async function discoverAuthorizationServerMetadata(
|
|
|
670
674
|
): Promise<AuthorizationServerMetadata | undefined> {
|
|
671
675
|
const headers = { 'MCP-Protocol-Version': protocolVersion };
|
|
672
676
|
|
|
677
|
+
const authorizationServerOrigin = new URL(authorizationServerUrl).origin;
|
|
673
678
|
const urlsToTry = buildDiscoveryUrls(authorizationServerUrl);
|
|
674
679
|
|
|
680
|
+
// Check all candidates before any request so discovery cannot bypass an
|
|
681
|
+
// application's authorization server validation by changing the origin.
|
|
682
|
+
if (urlsToTry.some(({ url }) => url.origin !== authorizationServerOrigin)) {
|
|
683
|
+
throw new MCPClientOAuthError({
|
|
684
|
+
message: 'OAuth discovery URL changed authorization-server origin',
|
|
685
|
+
});
|
|
686
|
+
}
|
|
687
|
+
|
|
675
688
|
for (const { url: endpointUrl, type, expectedIssuer } of urlsToTry) {
|
|
676
689
|
const response = await fetchWithCorsRetry(
|
|
677
690
|
endpointUrl,
|