@google/gemini-cli-a2a-server 0.58.0-preview.0 → 0.59.0-nightly.20260827.g3c311beac
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/dist/a2a-server.mjs +198 -56
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
package/dist/a2a-server.mjs
CHANGED
|
@@ -891,15 +891,15 @@ var require_colorize = __commonJS({
|
|
|
891
891
|
* function colorize (lookup, level, message)
|
|
892
892
|
* Performs multi-step colorization using @colors/colors/safe
|
|
893
893
|
*/
|
|
894
|
-
colorize(
|
|
894
|
+
colorize(lookup2, level, message) {
|
|
895
895
|
if (typeof message === "undefined") {
|
|
896
896
|
message = level;
|
|
897
897
|
}
|
|
898
|
-
if (!Array.isArray(_Colorizer.allColors[
|
|
899
|
-
return colors[_Colorizer.allColors[
|
|
898
|
+
if (!Array.isArray(_Colorizer.allColors[lookup2])) {
|
|
899
|
+
return colors[_Colorizer.allColors[lookup2]](message);
|
|
900
900
|
}
|
|
901
|
-
for (let i3 = 0, len = _Colorizer.allColors[
|
|
902
|
-
message = colors[_Colorizer.allColors[
|
|
901
|
+
for (let i3 = 0, len = _Colorizer.allColors[lookup2].length; i3 < len; i3++) {
|
|
902
|
+
message = colors[_Colorizer.allColors[lookup2][i3]](message);
|
|
903
903
|
}
|
|
904
904
|
return message;
|
|
905
905
|
}
|
|
@@ -27762,7 +27762,7 @@ var require_mime_types = __commonJS({
|
|
|
27762
27762
|
exports2.contentType = contentType;
|
|
27763
27763
|
exports2.extension = extension;
|
|
27764
27764
|
exports2.extensions = /* @__PURE__ */ Object.create(null);
|
|
27765
|
-
exports2.lookup =
|
|
27765
|
+
exports2.lookup = lookup2;
|
|
27766
27766
|
exports2.types = /* @__PURE__ */ Object.create(null);
|
|
27767
27767
|
exports2._extensionConflicts = [];
|
|
27768
27768
|
populateMaps(exports2.extensions, exports2.types);
|
|
@@ -27805,7 +27805,7 @@ var require_mime_types = __commonJS({
|
|
|
27805
27805
|
}
|
|
27806
27806
|
return exts[0];
|
|
27807
27807
|
}
|
|
27808
|
-
function
|
|
27808
|
+
function lookup2(path99) {
|
|
27809
27809
|
if (!path99 || typeof path99 !== "string") {
|
|
27810
27810
|
return false;
|
|
27811
27811
|
}
|
|
@@ -31311,7 +31311,7 @@ var require_view = __commonJS({
|
|
|
31311
31311
|
this.engine = opts.engines[this.ext];
|
|
31312
31312
|
this.path = this.lookup(fileName);
|
|
31313
31313
|
}
|
|
31314
|
-
View.prototype.lookup = function
|
|
31314
|
+
View.prototype.lookup = function lookup2(name3) {
|
|
31315
31315
|
var path100;
|
|
31316
31316
|
var roots = [].concat(this.root);
|
|
31317
31317
|
debug2('lookup "%s"', name3);
|
|
@@ -43576,12 +43576,12 @@ var require_base64_js = __commonJS({
|
|
|
43576
43576
|
exports2.byteLength = byteLength;
|
|
43577
43577
|
exports2.toByteArray = toByteArray;
|
|
43578
43578
|
exports2.fromByteArray = fromByteArray;
|
|
43579
|
-
var
|
|
43579
|
+
var lookup2 = [];
|
|
43580
43580
|
var revLookup = [];
|
|
43581
43581
|
var Arr = typeof Uint8Array !== "undefined" ? Uint8Array : Array;
|
|
43582
43582
|
var code = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
43583
43583
|
for (i3 = 0, len = code.length; i3 < len; ++i3) {
|
|
43584
|
-
|
|
43584
|
+
lookup2[i3] = code[i3];
|
|
43585
43585
|
revLookup[code.charCodeAt(i3)] = i3;
|
|
43586
43586
|
}
|
|
43587
43587
|
var i3;
|
|
@@ -43634,7 +43634,7 @@ var require_base64_js = __commonJS({
|
|
|
43634
43634
|
return arr;
|
|
43635
43635
|
}
|
|
43636
43636
|
function tripletToBase64(num) {
|
|
43637
|
-
return
|
|
43637
|
+
return lookup2[num >> 18 & 63] + lookup2[num >> 12 & 63] + lookup2[num >> 6 & 63] + lookup2[num & 63];
|
|
43638
43638
|
}
|
|
43639
43639
|
function encodeChunk(uint8, start2, end) {
|
|
43640
43640
|
var tmp;
|
|
@@ -43657,12 +43657,12 @@ var require_base64_js = __commonJS({
|
|
|
43657
43657
|
if (extraBytes === 1) {
|
|
43658
43658
|
tmp = uint8[len2 - 1];
|
|
43659
43659
|
parts2.push(
|
|
43660
|
-
|
|
43660
|
+
lookup2[tmp >> 2] + lookup2[tmp << 4 & 63] + "=="
|
|
43661
43661
|
);
|
|
43662
43662
|
} else if (extraBytes === 2) {
|
|
43663
43663
|
tmp = (uint8[len2 - 2] << 8) + uint8[len2 - 1];
|
|
43664
43664
|
parts2.push(
|
|
43665
|
-
|
|
43665
|
+
lookup2[tmp >> 10] + lookup2[tmp >> 4 & 63] + lookup2[tmp << 2 & 63] + "="
|
|
43666
43666
|
);
|
|
43667
43667
|
}
|
|
43668
43668
|
return parts2.join("");
|
|
@@ -71326,11 +71326,11 @@ var require_suffix_array = __commonJS({
|
|
|
71326
71326
|
}
|
|
71327
71327
|
}
|
|
71328
71328
|
}
|
|
71329
|
-
function compare(string3,
|
|
71330
|
-
return string3[m3] - string3[n2] || (m3 % 3 === 2 ? string3[m3 + 1] - string3[n2 + 1] ||
|
|
71329
|
+
function compare(string3, lookup2, m3, n2) {
|
|
71330
|
+
return string3[m3] - string3[n2] || (m3 % 3 === 2 ? string3[m3 + 1] - string3[n2 + 1] || lookup2[m3 + 2] - lookup2[n2 + 2] : lookup2[m3 + 1] - lookup2[n2 + 1]);
|
|
71331
71331
|
}
|
|
71332
71332
|
function build(string3, l2) {
|
|
71333
|
-
var a = [], b2 = [], al = 2 * l2 / 3 | 0, bl = l2 - al, r3 = al + 1 >> 1, i3 = al, j2 = 0, k2,
|
|
71333
|
+
var a = [], b2 = [], al = 2 * l2 / 3 | 0, bl = l2 - al, r3 = al + 1 >> 1, i3 = al, j2 = 0, k2, lookup2 = [], result2 = [];
|
|
71334
71334
|
if (l2 === 1)
|
|
71335
71335
|
return [0];
|
|
71336
71336
|
while (i3--)
|
|
@@ -71349,9 +71349,9 @@ var require_suffix_array = __commonJS({
|
|
|
71349
71349
|
a[i3] = b2[i3] < r3 ? b2[i3] * 3 + 1 : (b2[i3] - r3) * 3 + 2;
|
|
71350
71350
|
}
|
|
71351
71351
|
for (i3 = al; i3--; )
|
|
71352
|
-
|
|
71353
|
-
|
|
71354
|
-
|
|
71352
|
+
lookup2[a[i3]] = i3;
|
|
71353
|
+
lookup2[l2] = -1;
|
|
71354
|
+
lookup2[l2 + 1] = -2;
|
|
71355
71355
|
b2 = l2 % 3 === 1 ? [l2 - 1] : [];
|
|
71356
71356
|
for (i3 = 0; i3 < al; i3++) {
|
|
71357
71357
|
if (a[i3] % 3 === 1)
|
|
@@ -71359,7 +71359,7 @@ var require_suffix_array = __commonJS({
|
|
|
71359
71359
|
}
|
|
71360
71360
|
sort(string3, b2, 0);
|
|
71361
71361
|
for (i3 = 0, j2 = 0, k2 = 0; i3 < al && j2 < bl; )
|
|
71362
|
-
result2[k2++] = compare(string3,
|
|
71362
|
+
result2[k2++] = compare(string3, lookup2, a[i3], b2[j2]) < 0 ? a[i3++] : b2[j2++];
|
|
71363
71363
|
while (i3 < al)
|
|
71364
71364
|
result2[k2++] = a[i3++];
|
|
71365
71365
|
while (j2 < bl)
|
|
@@ -149010,7 +149010,7 @@ var require_namespace = __commonJS({
|
|
|
149010
149010
|
});
|
|
149011
149011
|
return this;
|
|
149012
149012
|
};
|
|
149013
|
-
Namespace.prototype.lookup = function
|
|
149013
|
+
Namespace.prototype.lookup = function lookup2(path99, filterTypes, parentAlreadyChecked) {
|
|
149014
149014
|
if (typeof filterTypes === "boolean") {
|
|
149015
149015
|
parentAlreadyChecked = filterTypes;
|
|
149016
149016
|
filterTypes = void 0;
|
|
@@ -149045,7 +149045,7 @@ var require_namespace = __commonJS({
|
|
|
149045
149045
|
}
|
|
149046
149046
|
return null;
|
|
149047
149047
|
};
|
|
149048
|
-
Namespace.prototype._lookupImpl = function
|
|
149048
|
+
Namespace.prototype._lookupImpl = function lookup2(path99, flatPath) {
|
|
149049
149049
|
if (Object.prototype.hasOwnProperty.call(this._lookupCache, flatPath)) {
|
|
149050
149050
|
return this._lookupCache[flatPath];
|
|
149051
149051
|
}
|
|
@@ -221064,8 +221064,8 @@ var GIT_COMMIT_INFO, CLI_VERSION;
|
|
|
221064
221064
|
var init_git_commit = __esm({
|
|
221065
221065
|
"packages/core/dist/src/generated/git-commit.js"() {
|
|
221066
221066
|
"use strict";
|
|
221067
|
-
GIT_COMMIT_INFO = "
|
|
221068
|
-
CLI_VERSION = "0.
|
|
221067
|
+
GIT_COMMIT_INFO = "3c311beac";
|
|
221068
|
+
CLI_VERSION = "0.59.0-nightly.20260827.g3c311beac";
|
|
221069
221069
|
}
|
|
221070
221070
|
});
|
|
221071
221071
|
|
|
@@ -322929,7 +322929,7 @@ var require_dns = __commonJS({
|
|
|
322929
322929
|
"packages/core/node_modules/undici/lib/interceptor/dns.js"(exports2, module2) {
|
|
322930
322930
|
"use strict";
|
|
322931
322931
|
var { isIP: isIP3 } = __require("node:net");
|
|
322932
|
-
var { lookup } = __require("node:dns");
|
|
322932
|
+
var { lookup: lookup2 } = __require("node:dns");
|
|
322933
322933
|
var DecoratorHandler = require_decorator_handler();
|
|
322934
322934
|
var { InvalidArgumentError, InformationalError } = require_errors7();
|
|
322935
322935
|
var maxInt = Math.pow(2, 31) - 1;
|
|
@@ -323019,7 +323019,7 @@ var require_dns = __commonJS({
|
|
|
323019
323019
|
}
|
|
323020
323020
|
}
|
|
323021
323021
|
#defaultLookup(origin, opts, cb) {
|
|
323022
|
-
|
|
323022
|
+
lookup2(
|
|
323023
323023
|
origin.hostname,
|
|
323024
323024
|
{
|
|
323025
323025
|
all: true,
|
|
@@ -336796,7 +336796,7 @@ function getVersion() {
|
|
|
336796
336796
|
}
|
|
336797
336797
|
versionPromise = (async () => {
|
|
336798
336798
|
const pkgJson = await getPackageJson(__dirname4);
|
|
336799
|
-
return "0.
|
|
336799
|
+
return "0.59.0-nightly.20260827.g3c311beac";
|
|
336800
336800
|
})();
|
|
336801
336801
|
return versionPromise;
|
|
336802
336802
|
}
|
|
@@ -359661,6 +359661,10 @@ function updateGlobalFetchTimeouts(timeoutMs) {
|
|
|
359661
359661
|
function sanitizeHostname(hostname3) {
|
|
359662
359662
|
return hostname3.startsWith("[") && hostname3.endsWith("]") ? hostname3.slice(1, -1) : hostname3;
|
|
359663
359663
|
}
|
|
359664
|
+
function isLoopbackHost(hostname3) {
|
|
359665
|
+
const sanitized = sanitizeHostname(hostname3);
|
|
359666
|
+
return sanitized === "localhost" || sanitized === "127.0.0.1" || sanitized === "::1";
|
|
359667
|
+
}
|
|
359664
359668
|
function isPrivateIp(url5) {
|
|
359665
359669
|
try {
|
|
359666
359670
|
const hostname3 = new URL7(url5).hostname;
|
|
@@ -374542,18 +374546,97 @@ var init_http_provider = __esm({
|
|
|
374542
374546
|
});
|
|
374543
374547
|
|
|
374544
374548
|
// packages/core/dist/src/mcp/oauth-utils.js
|
|
374545
|
-
|
|
374549
|
+
import { lookup } from "node:dns/promises";
|
|
374550
|
+
function isLoopbackUrl(urlStr) {
|
|
374551
|
+
try {
|
|
374552
|
+
const url5 = new URL(urlStr);
|
|
374553
|
+
return isLoopbackHost(url5.hostname);
|
|
374554
|
+
} catch {
|
|
374555
|
+
return false;
|
|
374556
|
+
}
|
|
374557
|
+
}
|
|
374558
|
+
async function validateOAuthEndpointUrl(urlStr, options) {
|
|
374559
|
+
let resolvedUrl = urlStr.trim();
|
|
374560
|
+
if (options?.allowRelative && options.baseUri) {
|
|
374561
|
+
try {
|
|
374562
|
+
resolvedUrl = new URL(resolvedUrl, options.baseUri).toString();
|
|
374563
|
+
} catch (e3) {
|
|
374564
|
+
throw new OAuthSecurityError(`Failed to resolve relative OAuth URL "${urlStr}" against base "${options.baseUri}": ${getErrorMessage(e3)}`);
|
|
374565
|
+
}
|
|
374566
|
+
}
|
|
374567
|
+
let parsed;
|
|
374568
|
+
try {
|
|
374569
|
+
parsed = new URL(resolvedUrl);
|
|
374570
|
+
} catch (e3) {
|
|
374571
|
+
throw new OAuthSecurityError(`Invalid OAuth endpoint URL "${resolvedUrl}": ${getErrorMessage(e3)}`);
|
|
374572
|
+
}
|
|
374573
|
+
const isHttp = parsed.protocol === "http:";
|
|
374574
|
+
const isHttps = parsed.protocol === "https:";
|
|
374575
|
+
if (!isHttp && !isHttps) {
|
|
374576
|
+
throw new OAuthSecurityError(`Invalid OAuth endpoint protocol "${parsed.protocol}". Only HTTPS (and HTTP for local development) is supported.`);
|
|
374577
|
+
}
|
|
374578
|
+
const hostname3 = sanitizeHostname(parsed.hostname);
|
|
374579
|
+
const isLoopback = isLoopbackHost(hostname3);
|
|
374580
|
+
if (isHttp && (!options?.allowLoopback || !isLoopback)) {
|
|
374581
|
+
throw new OAuthSecurityError(`Insecure HTTP OAuth endpoint "${resolvedUrl}" is not allowed. OAuth endpoints must use HTTPS unless connecting to localhost.`);
|
|
374582
|
+
}
|
|
374583
|
+
if (options?.expectedOrigin) {
|
|
374584
|
+
let expected;
|
|
374585
|
+
try {
|
|
374586
|
+
expected = new URL(options.expectedOrigin).origin;
|
|
374587
|
+
} catch {
|
|
374588
|
+
throw new OAuthSecurityError(`Invalid expected origin "${options.expectedOrigin}".`);
|
|
374589
|
+
}
|
|
374590
|
+
if (parsed.origin !== expected) {
|
|
374591
|
+
throw new OAuthSecurityError(`OAuth endpoint origin "${parsed.origin}" does not match expected origin "${expected}".`);
|
|
374592
|
+
}
|
|
374593
|
+
}
|
|
374594
|
+
if (isLoopback) {
|
|
374595
|
+
if (!options?.allowLoopback) {
|
|
374596
|
+
throw new OAuthSecurityError(`Loopback OAuth endpoint "${resolvedUrl}" is not allowed for remote MCP servers.`);
|
|
374597
|
+
}
|
|
374598
|
+
return parsed.toString();
|
|
374599
|
+
}
|
|
374600
|
+
if (isAddressPrivate(hostname3)) {
|
|
374601
|
+
throw new OAuthSecurityError(`OAuth endpoint "${resolvedUrl}" points to private or reserved IP address which is blocked.`);
|
|
374602
|
+
}
|
|
374603
|
+
try {
|
|
374604
|
+
const addresses = await lookup(hostname3, { all: true });
|
|
374605
|
+
if (!addresses || addresses.length === 0) {
|
|
374606
|
+
throw new OAuthSecurityError(`Failed to resolve hostname "${hostname3}" for OAuth endpoint "${resolvedUrl}".`);
|
|
374607
|
+
}
|
|
374608
|
+
for (const addr2 of addresses) {
|
|
374609
|
+
if (isAddressPrivate(addr2.address)) {
|
|
374610
|
+
throw new OAuthSecurityError(`OAuth endpoint "${resolvedUrl}" resolves to private network address "${addr2.address}" which is blocked.`);
|
|
374611
|
+
}
|
|
374612
|
+
}
|
|
374613
|
+
} catch (error2) {
|
|
374614
|
+
if (error2 instanceof OAuthSecurityError) {
|
|
374615
|
+
throw error2;
|
|
374616
|
+
}
|
|
374617
|
+
throw new OAuthSecurityError(`DNS lookup failed for OAuth endpoint host "${hostname3}": ${getErrorMessage(error2)}`);
|
|
374618
|
+
}
|
|
374619
|
+
return parsed.toString();
|
|
374620
|
+
}
|
|
374621
|
+
var ResourceMismatchError, OAuthSecurityError, FIVE_MIN_BUFFER_MS, OAuthUtils;
|
|
374546
374622
|
var init_oauth_utils = __esm({
|
|
374547
374623
|
"packages/core/dist/src/mcp/oauth-utils.js"() {
|
|
374548
374624
|
"use strict";
|
|
374549
374625
|
init_errors2();
|
|
374550
374626
|
init_debugLogger();
|
|
374627
|
+
init_fetch();
|
|
374551
374628
|
ResourceMismatchError = class extends Error {
|
|
374552
374629
|
constructor(message) {
|
|
374553
374630
|
super(message);
|
|
374554
374631
|
this.name = "ResourceMismatchError";
|
|
374555
374632
|
}
|
|
374556
374633
|
};
|
|
374634
|
+
OAuthSecurityError = class extends Error {
|
|
374635
|
+
constructor(message) {
|
|
374636
|
+
super(message);
|
|
374637
|
+
this.name = "OAuthSecurityError";
|
|
374638
|
+
}
|
|
374639
|
+
};
|
|
374557
374640
|
FIVE_MIN_BUFFER_MS = 5 * 60 * 1e3;
|
|
374558
374641
|
OAuthUtils = class {
|
|
374559
374642
|
/**
|
|
@@ -374583,16 +374666,24 @@ var init_oauth_utils = __esm({
|
|
|
374583
374666
|
* Fetch OAuth protected resource metadata.
|
|
374584
374667
|
*
|
|
374585
374668
|
* @param resourceMetadataUrl The protected resource metadata URL
|
|
374669
|
+
* @param options Validation options including loopback allowance and expected origin
|
|
374586
374670
|
* @returns The protected resource metadata or null if not available
|
|
374587
374671
|
*/
|
|
374588
|
-
static async fetchProtectedResourceMetadata(resourceMetadataUrl) {
|
|
374672
|
+
static async fetchProtectedResourceMetadata(resourceMetadataUrl, options) {
|
|
374589
374673
|
try {
|
|
374590
|
-
const
|
|
374674
|
+
const validatedUrl = await validateOAuthEndpointUrl(resourceMetadataUrl, {
|
|
374675
|
+
allowLoopback: options?.allowLoopback,
|
|
374676
|
+
expectedOrigin: options?.expectedOrigin
|
|
374677
|
+
});
|
|
374678
|
+
const response = await fetch(validatedUrl);
|
|
374591
374679
|
if (!response.ok) {
|
|
374592
374680
|
return null;
|
|
374593
374681
|
}
|
|
374594
374682
|
return await response.json();
|
|
374595
374683
|
} catch (error2) {
|
|
374684
|
+
if (error2 instanceof OAuthSecurityError) {
|
|
374685
|
+
throw error2;
|
|
374686
|
+
}
|
|
374596
374687
|
debugLogger.debug(`Failed to fetch protected resource metadata from ${resourceMetadataUrl}: ${getErrorMessage(error2)}`);
|
|
374597
374688
|
return null;
|
|
374598
374689
|
}
|
|
@@ -374601,16 +374692,23 @@ var init_oauth_utils = __esm({
|
|
|
374601
374692
|
* Fetch OAuth authorization server metadata.
|
|
374602
374693
|
*
|
|
374603
374694
|
* @param authServerMetadataUrl The authorization server metadata URL
|
|
374695
|
+
* @param options Validation options including loopback allowance
|
|
374604
374696
|
* @returns The authorization server metadata or null if not available
|
|
374605
374697
|
*/
|
|
374606
|
-
static async fetchAuthorizationServerMetadata(authServerMetadataUrl) {
|
|
374698
|
+
static async fetchAuthorizationServerMetadata(authServerMetadataUrl, options) {
|
|
374607
374699
|
try {
|
|
374608
|
-
const
|
|
374700
|
+
const validatedUrl = await validateOAuthEndpointUrl(authServerMetadataUrl, {
|
|
374701
|
+
allowLoopback: options?.allowLoopback
|
|
374702
|
+
});
|
|
374703
|
+
const response = await fetch(validatedUrl);
|
|
374609
374704
|
if (!response.ok) {
|
|
374610
374705
|
return null;
|
|
374611
374706
|
}
|
|
374612
374707
|
return await response.json();
|
|
374613
374708
|
} catch (error2) {
|
|
374709
|
+
if (error2 instanceof OAuthSecurityError) {
|
|
374710
|
+
throw error2;
|
|
374711
|
+
}
|
|
374614
374712
|
debugLogger.debug(`Failed to fetch authorization server metadata from ${authServerMetadataUrl}: ${getErrorMessage(error2)}`);
|
|
374615
374713
|
return null;
|
|
374616
374714
|
}
|
|
@@ -374635,10 +374733,14 @@ var init_oauth_utils = __esm({
|
|
|
374635
374733
|
* trying the standard well-known endpoints.
|
|
374636
374734
|
*
|
|
374637
374735
|
* @param authServerUrl The authorization server URL
|
|
374736
|
+
* @param options Validation options including loopback allowance
|
|
374638
374737
|
* @returns The authorization server metadata or null if not found
|
|
374639
374738
|
*/
|
|
374640
|
-
static async discoverAuthorizationServerMetadata(authServerUrl) {
|
|
374641
|
-
const
|
|
374739
|
+
static async discoverAuthorizationServerMetadata(authServerUrl, options) {
|
|
374740
|
+
const validatedBaseUrl = await validateOAuthEndpointUrl(authServerUrl, {
|
|
374741
|
+
allowLoopback: options?.allowLoopback
|
|
374742
|
+
});
|
|
374743
|
+
const authServerUrlObj = new URL(validatedBaseUrl);
|
|
374642
374744
|
const base = `${authServerUrlObj.protocol}//${authServerUrlObj.host}`;
|
|
374643
374745
|
const endpointsToTry = [];
|
|
374644
374746
|
if (authServerUrlObj.pathname !== "/") {
|
|
@@ -374649,7 +374751,7 @@ var init_oauth_utils = __esm({
|
|
|
374649
374751
|
endpointsToTry.push(new URL("/.well-known/oauth-authorization-server", base).toString());
|
|
374650
374752
|
endpointsToTry.push(new URL("/.well-known/openid-configuration", base).toString());
|
|
374651
374753
|
for (const endpoint of endpointsToTry) {
|
|
374652
|
-
const authServerMetadata = await this.fetchAuthorizationServerMetadata(endpoint);
|
|
374754
|
+
const authServerMetadata = await this.fetchAuthorizationServerMetadata(endpoint, options);
|
|
374653
374755
|
if (authServerMetadata) {
|
|
374654
374756
|
return authServerMetadata;
|
|
374655
374757
|
}
|
|
@@ -374665,13 +374767,15 @@ var init_oauth_utils = __esm({
|
|
|
374665
374767
|
*/
|
|
374666
374768
|
static async discoverOAuthConfig(serverUrl) {
|
|
374667
374769
|
try {
|
|
374770
|
+
const allowLoopback = isLoopbackUrl(serverUrl);
|
|
374771
|
+
const expectedOrigin = new URL(serverUrl).origin;
|
|
374668
374772
|
const wellKnownUrls = this.buildWellKnownUrls(serverUrl);
|
|
374669
|
-
let resourceMetadata = await this.fetchProtectedResourceMetadata(wellKnownUrls.protectedResource);
|
|
374773
|
+
let resourceMetadata = await this.fetchProtectedResourceMetadata(wellKnownUrls.protectedResource, { allowLoopback, expectedOrigin });
|
|
374670
374774
|
if (!resourceMetadata) {
|
|
374671
374775
|
const url5 = new URL(serverUrl);
|
|
374672
374776
|
if (url5.pathname && url5.pathname !== "/") {
|
|
374673
374777
|
const rootBasedUrls = this.buildWellKnownUrls(serverUrl, true);
|
|
374674
|
-
resourceMetadata = await this.fetchProtectedResourceMetadata(rootBasedUrls.protectedResource);
|
|
374778
|
+
resourceMetadata = await this.fetchProtectedResourceMetadata(rootBasedUrls.protectedResource, { allowLoopback, expectedOrigin });
|
|
374675
374779
|
}
|
|
374676
374780
|
}
|
|
374677
374781
|
if (resourceMetadata) {
|
|
@@ -374682,7 +374786,9 @@ var init_oauth_utils = __esm({
|
|
|
374682
374786
|
}
|
|
374683
374787
|
if (resourceMetadata?.authorization_servers?.length) {
|
|
374684
374788
|
const authServerUrl = resourceMetadata.authorization_servers[0];
|
|
374685
|
-
const authServerMetadata2 = await this.discoverAuthorizationServerMetadata(authServerUrl
|
|
374789
|
+
const authServerMetadata2 = await this.discoverAuthorizationServerMetadata(authServerUrl, {
|
|
374790
|
+
allowLoopback
|
|
374791
|
+
});
|
|
374686
374792
|
if (authServerMetadata2) {
|
|
374687
374793
|
const config2 = this.metadataToOAuthConfig(authServerMetadata2);
|
|
374688
374794
|
if (authServerMetadata2.registration_endpoint) {
|
|
@@ -374692,7 +374798,9 @@ var init_oauth_utils = __esm({
|
|
|
374692
374798
|
}
|
|
374693
374799
|
}
|
|
374694
374800
|
debugLogger.debug(`Trying OAuth discovery fallback at ${serverUrl}`);
|
|
374695
|
-
const authServerMetadata = await this.discoverAuthorizationServerMetadata(serverUrl
|
|
374801
|
+
const authServerMetadata = await this.discoverAuthorizationServerMetadata(serverUrl, {
|
|
374802
|
+
allowLoopback
|
|
374803
|
+
});
|
|
374696
374804
|
if (authServerMetadata) {
|
|
374697
374805
|
const config2 = this.metadataToOAuthConfig(authServerMetadata);
|
|
374698
374806
|
if (authServerMetadata.registration_endpoint) {
|
|
@@ -374702,7 +374810,7 @@ var init_oauth_utils = __esm({
|
|
|
374702
374810
|
}
|
|
374703
374811
|
return null;
|
|
374704
374812
|
} catch (error2) {
|
|
374705
|
-
if (error2 instanceof ResourceMismatchError) {
|
|
374813
|
+
if (error2 instanceof ResourceMismatchError || error2 instanceof OAuthSecurityError) {
|
|
374706
374814
|
throw error2;
|
|
374707
374815
|
}
|
|
374708
374816
|
debugLogger.debug(`Failed to discover OAuth configuration: ${getErrorMessage(error2)}`);
|
|
@@ -374716,9 +374824,9 @@ var init_oauth_utils = __esm({
|
|
|
374716
374824
|
* @returns The resource metadata URI if found
|
|
374717
374825
|
*/
|
|
374718
374826
|
static parseWWWAuthenticateHeader(header) {
|
|
374719
|
-
const match2 = header.match(/resource_metadata="([^"]+)"/);
|
|
374827
|
+
const match2 = header.match(/resource_metadata=(?:"([^"]+)"|([^\s,]+))/);
|
|
374720
374828
|
if (match2) {
|
|
374721
|
-
return match2[1];
|
|
374829
|
+
return match2[1] || match2[2] || null;
|
|
374722
374830
|
}
|
|
374723
374831
|
return null;
|
|
374724
374832
|
}
|
|
@@ -374734,7 +374842,18 @@ var init_oauth_utils = __esm({
|
|
|
374734
374842
|
if (!resourceMetadataUri) {
|
|
374735
374843
|
return null;
|
|
374736
374844
|
}
|
|
374737
|
-
const
|
|
374845
|
+
const allowLoopback = mcpServerUrl ? isLoopbackUrl(mcpServerUrl) : false;
|
|
374846
|
+
const expectedOrigin = mcpServerUrl ? new URL(mcpServerUrl).origin : void 0;
|
|
374847
|
+
const validatedResourceMetadataUrl = await validateOAuthEndpointUrl(resourceMetadataUri, {
|
|
374848
|
+
allowLoopback,
|
|
374849
|
+
expectedOrigin,
|
|
374850
|
+
allowRelative: true,
|
|
374851
|
+
baseUri: mcpServerUrl
|
|
374852
|
+
});
|
|
374853
|
+
const resourceMetadata = await this.fetchProtectedResourceMetadata(validatedResourceMetadataUrl, {
|
|
374854
|
+
allowLoopback,
|
|
374855
|
+
expectedOrigin
|
|
374856
|
+
});
|
|
374738
374857
|
if (resourceMetadata && mcpServerUrl) {
|
|
374739
374858
|
const expectedResource = this.buildResourceParameter(mcpServerUrl);
|
|
374740
374859
|
if (!this.isEquivalentResourceIdentifier(resourceMetadata.resource, expectedResource)) {
|
|
@@ -374745,7 +374864,9 @@ var init_oauth_utils = __esm({
|
|
|
374745
374864
|
return null;
|
|
374746
374865
|
}
|
|
374747
374866
|
const authServerUrl = resourceMetadata.authorization_servers[0];
|
|
374748
|
-
const authServerMetadata = await this.discoverAuthorizationServerMetadata(authServerUrl
|
|
374867
|
+
const authServerMetadata = await this.discoverAuthorizationServerMetadata(authServerUrl, {
|
|
374868
|
+
allowLoopback
|
|
374869
|
+
});
|
|
374749
374870
|
if (authServerMetadata) {
|
|
374750
374871
|
return this.metadataToOAuthConfig(authServerMetadata);
|
|
374751
374872
|
}
|
|
@@ -378613,7 +378734,11 @@ async function exchangeCodeForToken(config2, code, codeVerifier, redirectPort, r
|
|
|
378613
378734
|
if (resource) {
|
|
378614
378735
|
params.append("resource", resource);
|
|
378615
378736
|
}
|
|
378616
|
-
const
|
|
378737
|
+
const allowLoopback = resource ? isLoopbackUrl(resource) : isLoopbackUrl(config2.tokenUrl);
|
|
378738
|
+
const validatedTokenUrl = await validateOAuthEndpointUrl(config2.tokenUrl, {
|
|
378739
|
+
allowLoopback
|
|
378740
|
+
});
|
|
378741
|
+
const response = await fetch(validatedTokenUrl, {
|
|
378617
378742
|
method: "POST",
|
|
378618
378743
|
headers: {
|
|
378619
378744
|
"Content-Type": "application/x-www-form-urlencoded",
|
|
@@ -378641,7 +378766,11 @@ async function refreshAccessToken(config2, refreshToken, tokenUrl, resource) {
|
|
|
378641
378766
|
if (resource) {
|
|
378642
378767
|
params.append("resource", resource);
|
|
378643
378768
|
}
|
|
378644
|
-
const
|
|
378769
|
+
const allowLoopback = resource ? isLoopbackUrl(resource) : isLoopbackUrl(tokenUrl);
|
|
378770
|
+
const validatedTokenUrl = await validateOAuthEndpointUrl(tokenUrl, {
|
|
378771
|
+
allowLoopback
|
|
378772
|
+
});
|
|
378773
|
+
const response = await fetch(validatedTokenUrl, {
|
|
378645
378774
|
method: "POST",
|
|
378646
378775
|
headers: {
|
|
378647
378776
|
"Content-Type": "application/x-www-form-urlencoded",
|
|
@@ -378656,6 +378785,7 @@ var init_oauth_flow = __esm({
|
|
|
378656
378785
|
"packages/core/dist/src/utils/oauth-flow.js"() {
|
|
378657
378786
|
"use strict";
|
|
378658
378787
|
init_debugLogger();
|
|
378788
|
+
init_oauth_utils();
|
|
378659
378789
|
REDIRECT_PATH = "/oauth/callback";
|
|
378660
378790
|
HTTP_OK = 200;
|
|
378661
378791
|
}
|
|
@@ -407152,7 +407282,11 @@ var init_oauth_provider = __esm({
|
|
|
407152
407282
|
* @param redirectPort The port to use for the redirect URI
|
|
407153
407283
|
* @returns The registered client information
|
|
407154
407284
|
*/
|
|
407155
|
-
async registerClient(registrationUrl, config2, redirectPort) {
|
|
407285
|
+
async registerClient(registrationUrl, config2, redirectPort, mcpServerUrl) {
|
|
407286
|
+
const allowLoopback = mcpServerUrl ? isLoopbackUrl(mcpServerUrl) : isLoopbackUrl(registrationUrl);
|
|
407287
|
+
const validatedRegistrationUrl = await validateOAuthEndpointUrl(registrationUrl, {
|
|
407288
|
+
allowLoopback
|
|
407289
|
+
});
|
|
407156
407290
|
const redirectUri = getRedirectUri(config2, redirectPort);
|
|
407157
407291
|
const registrationRequest = {
|
|
407158
407292
|
client_name: "Gemini CLI MCP Client",
|
|
@@ -407163,7 +407297,7 @@ var init_oauth_provider = __esm({
|
|
|
407163
407297
|
// Public client
|
|
407164
407298
|
scope: config2.scopes?.join(" ") || ""
|
|
407165
407299
|
};
|
|
407166
|
-
const response = await fetch(
|
|
407300
|
+
const response = await fetch(validatedRegistrationUrl, {
|
|
407167
407301
|
method: "POST",
|
|
407168
407302
|
headers: {
|
|
407169
407303
|
"Content-Type": "application/json"
|
|
@@ -407185,7 +407319,8 @@ var init_oauth_provider = __esm({
|
|
|
407185
407319
|
async discoverOAuthFromMCPServer(mcpServerUrl) {
|
|
407186
407320
|
return OAuthUtils.discoverOAuthConfig(mcpServerUrl);
|
|
407187
407321
|
}
|
|
407188
|
-
async discoverAuthServerMetadataForRegistration(issuer) {
|
|
407322
|
+
async discoverAuthServerMetadataForRegistration(issuer, mcpServerUrl) {
|
|
407323
|
+
const allowLoopback = mcpServerUrl ? isLoopbackUrl(mcpServerUrl) : isLoopbackUrl(issuer);
|
|
407189
407324
|
const authUrl = new URL9(issuer);
|
|
407190
407325
|
const oidcPatterns = [
|
|
407191
407326
|
"/protocol/openid-connect/auth",
|
|
@@ -407218,11 +407353,11 @@ var init_oauth_provider = __esm({
|
|
|
407218
407353
|
const attemptedIssuers = Array.from(issuerCandidates);
|
|
407219
407354
|
let selectedIssuer = attemptedIssuers[0];
|
|
407220
407355
|
let discoveredMetadata = null;
|
|
407221
|
-
for (const
|
|
407222
|
-
debugLogger.debug(` Trying issuer URL: ${
|
|
407223
|
-
const metadata2 = await OAuthUtils.discoverAuthorizationServerMetadata(
|
|
407356
|
+
for (const issuerCandidate of attemptedIssuers) {
|
|
407357
|
+
debugLogger.debug(` Trying issuer URL: ${issuerCandidate}`);
|
|
407358
|
+
const metadata2 = await OAuthUtils.discoverAuthorizationServerMetadata(issuerCandidate, { allowLoopback });
|
|
407224
407359
|
if (metadata2) {
|
|
407225
|
-
selectedIssuer =
|
|
407360
|
+
selectedIssuer = issuerCandidate;
|
|
407226
407361
|
discoveredMetadata = metadata2;
|
|
407227
407362
|
break;
|
|
407228
407363
|
}
|
|
@@ -407311,7 +407446,7 @@ var init_oauth_provider = __esm({
|
|
|
407311
407446
|
}
|
|
407312
407447
|
}
|
|
407313
407448
|
} catch (error2) {
|
|
407314
|
-
if (error2 instanceof ResourceMismatchError) {
|
|
407449
|
+
if (error2 instanceof ResourceMismatchError || error2 instanceof OAuthSecurityError) {
|
|
407315
407450
|
throw error2;
|
|
407316
407451
|
}
|
|
407317
407452
|
debugLogger.debug(`Failed to check endpoint for authentication requirements: ${getErrorMessage(error2)}`);
|
|
@@ -407347,11 +407482,11 @@ var init_oauth_provider = __esm({
|
|
|
407347
407482
|
throw new Error("Cannot perform dynamic registration without issuer");
|
|
407348
407483
|
}
|
|
407349
407484
|
debugLogger.debug("\u2192 Attempting dynamic client registration...");
|
|
407350
|
-
const { metadata: authServerMetadata } = await this.discoverAuthServerMetadataForRegistration(config2.issuer);
|
|
407485
|
+
const { metadata: authServerMetadata } = await this.discoverAuthServerMetadataForRegistration(config2.issuer, mcpServerUrl);
|
|
407351
407486
|
registrationUrl = authServerMetadata.registration_endpoint;
|
|
407352
407487
|
}
|
|
407353
407488
|
if (registrationUrl) {
|
|
407354
|
-
const clientRegistration = await this.registerClient(registrationUrl, config2, redirectPort);
|
|
407489
|
+
const clientRegistration = await this.registerClient(registrationUrl, config2, redirectPort, mcpServerUrl);
|
|
407355
407490
|
config2.clientId = clientRegistration.client_id;
|
|
407356
407491
|
if (clientRegistration.client_secret) {
|
|
407357
407492
|
config2.clientSecret = clientRegistration.client_secret;
|
|
@@ -407364,6 +407499,13 @@ var init_oauth_provider = __esm({
|
|
|
407364
407499
|
if (!config2.clientId || !config2.authorizationUrl || !config2.tokenUrl) {
|
|
407365
407500
|
throw new Error("Missing required OAuth configuration after discovery and registration");
|
|
407366
407501
|
}
|
|
407502
|
+
const allowLoopback = mcpServerUrl ? isLoopbackUrl(mcpServerUrl) : (config2.authorizationUrl ? isLoopbackUrl(config2.authorizationUrl) : false) || (config2.tokenUrl ? isLoopbackUrl(config2.tokenUrl) : false);
|
|
407503
|
+
await validateOAuthEndpointUrl(config2.authorizationUrl, {
|
|
407504
|
+
allowLoopback
|
|
407505
|
+
});
|
|
407506
|
+
await validateOAuthEndpointUrl(config2.tokenUrl, {
|
|
407507
|
+
allowLoopback
|
|
407508
|
+
});
|
|
407367
407509
|
const flowConfig = {
|
|
407368
407510
|
clientId: config2.clientId,
|
|
407369
407511
|
clientSecret: config2.clientSecret,
|