@vitemcp/server 1.9.16 → 1.10.0
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/README.md +60 -1
- package/dist/{OAuthProvider-DNKBMBPU.d.cts → OAuthProvider-STkC4R2N.d.cts} +39 -1
- package/dist/{OAuthProvider-DNKBMBPU.d.ts → OAuthProvider-STkC4R2N.d.ts} +39 -1
- package/dist/ViteMCP.cjs +4 -4
- package/dist/ViteMCP.d.cts +20 -3
- package/dist/ViteMCP.d.ts +20 -3
- package/dist/ViteMCP.js +3 -3
- package/dist/auth/index.cjs +2 -2
- package/dist/auth/index.d.cts +17 -3
- package/dist/auth/index.d.ts +17 -3
- package/dist/auth/index.js +1 -1
- package/dist/{chunk-PXH56Q3F.js → chunk-AOZIQIXA.js} +143 -18
- package/dist/chunk-AOZIQIXA.js.map +1 -0
- package/dist/{chunk-JMDI672G.js → chunk-BLXUZUZ4.js} +16 -1
- package/dist/chunk-BLXUZUZ4.js.map +1 -0
- package/dist/{chunk-LZTRZ62V.js → chunk-BMW6BWBO.js} +33 -12
- package/dist/chunk-BMW6BWBO.js.map +1 -0
- package/dist/{chunk-HDJEH7NK.cjs → chunk-CJLWQH7G.cjs} +38 -17
- package/dist/chunk-CJLWQH7G.cjs.map +1 -0
- package/dist/{chunk-QPVEGWOL.cjs → chunk-NZGRSB2D.cjs} +17 -2
- package/dist/chunk-NZGRSB2D.cjs.map +1 -0
- package/dist/{chunk-TWYBLPRQ.cjs → chunk-R3JUTGZL.cjs} +162 -37
- package/dist/chunk-R3JUTGZL.cjs.map +1 -0
- package/dist/edge/index.cjs +23 -10
- package/dist/edge/index.cjs.map +1 -1
- package/dist/edge/index.d.cts +11 -0
- package/dist/edge/index.d.ts +11 -0
- package/dist/edge/index.js +19 -6
- package/dist/edge/index.js.map +1 -1
- package/dist/openapi/index.cjs +43 -43
- package/dist/openapi/index.cjs.map +1 -1
- package/dist/openapi/index.d.cts +1 -1
- package/dist/openapi/index.d.ts +1 -1
- package/dist/openapi/index.js +33 -33
- package/dist/openapi/index.js.map +1 -1
- package/package.json +4 -4
- package/dist/chunk-HDJEH7NK.cjs.map +0 -1
- package/dist/chunk-JMDI672G.js.map +0 -1
- package/dist/chunk-LZTRZ62V.js.map +0 -1
- package/dist/chunk-PXH56Q3F.js.map +0 -1
- package/dist/chunk-QPVEGWOL.cjs.map +0 -1
- package/dist/chunk-TWYBLPRQ.cjs.map +0 -1
|
@@ -392,6 +392,7 @@ var oauthTransactionStorageSchema = _zod.z.object({
|
|
|
392
392
|
clientCodeChallenge: _zod.z.string(),
|
|
393
393
|
clientCodeChallengeMethod: _zod.z.string(),
|
|
394
394
|
clientId: _zod.z.string(),
|
|
395
|
+
consentBinding: _zod.z.string().optional(),
|
|
395
396
|
consentGiven: _zod.z.boolean().optional(),
|
|
396
397
|
createdAt: storedDateSchema,
|
|
397
398
|
expiresAt: storedDateSchema,
|
|
@@ -713,22 +714,31 @@ var ConsentManager = class {
|
|
|
713
714
|
}
|
|
714
715
|
/**
|
|
715
716
|
* Create HTTP response with consent screen
|
|
717
|
+
*
|
|
718
|
+
* `cookie` is a `Set-Cookie` value that ties the request to the browser the
|
|
719
|
+
* screen is shown to. The screen may not be framed: a page that embeds it
|
|
720
|
+
* could have the user approve without seeing what they are approving.
|
|
716
721
|
*/
|
|
717
|
-
createConsentResponse(transaction, provider) {
|
|
722
|
+
createConsentResponse(transaction, provider, options = {}) {
|
|
718
723
|
const consentData = {
|
|
719
|
-
clientName: "MCP Client",
|
|
724
|
+
clientName: options.clientName || "MCP Client",
|
|
720
725
|
provider,
|
|
726
|
+
redirectUri: transaction.clientCallbackUrl,
|
|
721
727
|
scope: transaction.scope,
|
|
722
728
|
timestamp: Date.now(),
|
|
723
729
|
transactionId: transaction.id
|
|
724
730
|
};
|
|
725
731
|
const html = this.generateConsentScreen(consentData);
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
732
|
+
const headers = new Headers({
|
|
733
|
+
"Cache-Control": "no-store",
|
|
734
|
+
"Content-Security-Policy": "frame-ancestors 'none'",
|
|
735
|
+
"Content-Type": "text/html; charset=utf-8",
|
|
736
|
+
"X-Frame-Options": "DENY"
|
|
731
737
|
});
|
|
738
|
+
if (options.cookie) {
|
|
739
|
+
headers.append("Set-Cookie", options.cookie);
|
|
740
|
+
}
|
|
741
|
+
return new Response(html, { headers, status: 200 });
|
|
732
742
|
}
|
|
733
743
|
/**
|
|
734
744
|
* Generate HTML for consent screen
|
|
@@ -739,7 +749,8 @@ var ConsentManager = class {
|
|
|
739
749
|
* one no route answers, and Approve came back 404.
|
|
740
750
|
*/
|
|
741
751
|
generateConsentScreen(data) {
|
|
742
|
-
const { clientName, provider, scope, transactionId } = data;
|
|
752
|
+
const { clientName, provider, redirectUri, scope, transactionId } = data;
|
|
753
|
+
const destination = redirectUri && this.describeDestination(redirectUri);
|
|
743
754
|
return `
|
|
744
755
|
<!DOCTYPE html>
|
|
745
756
|
<html lang="en">
|
|
@@ -807,6 +818,12 @@ var ConsentManager = class {
|
|
|
807
818
|
font-weight: 600;
|
|
808
819
|
}
|
|
809
820
|
|
|
821
|
+
.destination {
|
|
822
|
+
color: #4a5568;
|
|
823
|
+
font-size: 14px;
|
|
824
|
+
overflow-wrap: anywhere;
|
|
825
|
+
}
|
|
826
|
+
|
|
810
827
|
.permissions {
|
|
811
828
|
margin-top: 16px;
|
|
812
829
|
}
|
|
@@ -905,10 +922,15 @@ var ConsentManager = class {
|
|
|
905
922
|
|
|
906
923
|
<div class="app-info">
|
|
907
924
|
<h2>
|
|
908
|
-
<span class="app-name">${this.escapeHtml(clientName || "An application")}</span>
|
|
925
|
+
<span class="app-name">${this.escapeHtml((clientName || "An application").slice(0, 100))}</span>
|
|
909
926
|
requests access
|
|
910
927
|
</h2>
|
|
911
|
-
|
|
928
|
+
${destination ? `
|
|
929
|
+
<p class="destination">
|
|
930
|
+
If you approve, you will be sent to
|
|
931
|
+
<strong>${this.escapeHtml(destination)}</strong>
|
|
932
|
+
</p>
|
|
933
|
+
` : ""}
|
|
912
934
|
<div class="permissions">
|
|
913
935
|
<h3>This will allow the app to:</h3>
|
|
914
936
|
<ul>
|
|
@@ -978,6 +1000,23 @@ var ConsentManager = class {
|
|
|
978
1000
|
return null;
|
|
979
1001
|
}
|
|
980
1002
|
}
|
|
1003
|
+
/**
|
|
1004
|
+
* Where a redirect URI leads, as the browser will read it rather than as it
|
|
1005
|
+
* was typed: the parsed host, so that a look-alike character, a tab or a
|
|
1006
|
+
* backslash shows for what it does. A long host keeps its end, which is the
|
|
1007
|
+
* part that says whose it is.
|
|
1008
|
+
*/
|
|
1009
|
+
describeDestination(redirectUri) {
|
|
1010
|
+
let url;
|
|
1011
|
+
try {
|
|
1012
|
+
url = new URL(redirectUri);
|
|
1013
|
+
} catch (e6) {
|
|
1014
|
+
return void 0;
|
|
1015
|
+
}
|
|
1016
|
+
const host = url.host.length > 80 ? `\u2026${url.host.slice(-80)}` : url.host;
|
|
1017
|
+
const path = url.pathname.length > 80 ? `${url.pathname.slice(0, 80)}\u2026` : url.pathname;
|
|
1018
|
+
return host ? `${url.protocol}//${host}${path}` : `${url.protocol}${path}`;
|
|
1019
|
+
}
|
|
981
1020
|
/**
|
|
982
1021
|
* Escape HTML to prevent XSS
|
|
983
1022
|
*/
|
|
@@ -1185,7 +1224,7 @@ function isLoopbackHostname(hostname) {
|
|
|
1185
1224
|
var parse = (uri) => {
|
|
1186
1225
|
try {
|
|
1187
1226
|
return new URL(uri);
|
|
1188
|
-
} catch (
|
|
1227
|
+
} catch (e7) {
|
|
1189
1228
|
return null;
|
|
1190
1229
|
}
|
|
1191
1230
|
};
|
|
@@ -1215,6 +1254,7 @@ function loopbackRedirectMatches(declared, requested) {
|
|
|
1215
1254
|
|
|
1216
1255
|
// src/auth/utils/pkce.ts
|
|
1217
1256
|
|
|
1257
|
+
var CODE_VERIFIER = /^[A-Za-z0-9._~-]{43,128}$/;
|
|
1218
1258
|
var PKCEUtils = class _PKCEUtils {
|
|
1219
1259
|
/**
|
|
1220
1260
|
* Generate a code challenge from a verifier
|
|
@@ -1270,6 +1310,9 @@ var PKCEUtils = class _PKCEUtils {
|
|
|
1270
1310
|
if (!verifier || !challenge) {
|
|
1271
1311
|
return false;
|
|
1272
1312
|
}
|
|
1313
|
+
if (!CODE_VERIFIER.test(verifier)) {
|
|
1314
|
+
return false;
|
|
1315
|
+
}
|
|
1273
1316
|
if (method === "plain") {
|
|
1274
1317
|
return equalsConstantTime(verifier, challenge);
|
|
1275
1318
|
}
|
|
@@ -1511,7 +1554,6 @@ var OAuthProxy = (_class4 = class {
|
|
|
1511
1554
|
constructor(config) {;_class4.prototype.__init5.call(this);_class4.prototype.__init6.call(this);_class4.prototype.__init7.call(this);_class4.prototype.__init8.call(this);
|
|
1512
1555
|
this.config = {
|
|
1513
1556
|
authorizationCodeTtl: DEFAULT_AUTHORIZATION_CODE_TTL,
|
|
1514
|
-
consentRequired: true,
|
|
1515
1557
|
enableTokenSwap: true,
|
|
1516
1558
|
// Enabled by default for security
|
|
1517
1559
|
redirectPath: DEFAULT_REDIRECT_PATH,
|
|
@@ -1519,7 +1561,10 @@ var OAuthProxy = (_class4 = class {
|
|
|
1519
1561
|
upstreamRequestTimeoutMs: DEFAULT_UPSTREAM_REQUEST_TIMEOUT_MS,
|
|
1520
1562
|
upstreamTokenEndpointAuthMethod: "client_secret_basic",
|
|
1521
1563
|
...config,
|
|
1522
|
-
baseUrl: withoutTrailingSlash(config.baseUrl)
|
|
1564
|
+
baseUrl: withoutTrailingSlash(config.baseUrl),
|
|
1565
|
+
// Spreading an explicit `undefined` over the default would turn consent
|
|
1566
|
+
// off for a caller that only meant to pass an option along.
|
|
1567
|
+
consentRequired: _nullishCoalesce(config.consentRequired, () => ( true))
|
|
1523
1568
|
};
|
|
1524
1569
|
let storage = config.tokenStorage;
|
|
1525
1570
|
if (!storage) {
|
|
@@ -1560,8 +1605,13 @@ var OAuthProxy = (_class4 = class {
|
|
|
1560
1605
|
}
|
|
1561
1606
|
/**
|
|
1562
1607
|
* OAuth authorization endpoint
|
|
1608
|
+
*
|
|
1609
|
+
* With consent required the response is the consent screen, and it sets the
|
|
1610
|
+
* cookie that the request is approved and finished with: return its headers
|
|
1611
|
+
* to the browser. Pass that browser's `request` as well, so that one with
|
|
1612
|
+
* several authorization requests open keeps a single cookie for all of them.
|
|
1563
1613
|
*/
|
|
1564
|
-
async authorize(params) {
|
|
1614
|
+
async authorize(params, request2) {
|
|
1565
1615
|
if (!params.client_id || !params.redirect_uri || !params.response_type) {
|
|
1566
1616
|
throw new OAuthProxyError(
|
|
1567
1617
|
"invalid_request",
|
|
@@ -1613,11 +1663,17 @@ var OAuthProxy = (_class4 = class {
|
|
|
1613
1663
|
);
|
|
1614
1664
|
}
|
|
1615
1665
|
}
|
|
1616
|
-
const
|
|
1617
|
-
|
|
1666
|
+
const consentBinding = this.config.consentRequired ? _nullishCoalesce((request2 && this.consentCookieValue(request2)), () => ( this.generateId())) : void 0;
|
|
1667
|
+
const transaction = await this.createTransaction(params, consentBinding);
|
|
1668
|
+
if (consentBinding && !transaction.consentGiven) {
|
|
1669
|
+
const clientName = _optionalChain([registeredClient, 'access', _16 => _16.metadata, 'optionalAccess', _17 => _17.client_name]);
|
|
1618
1670
|
return this.consentManager.createConsentResponse(
|
|
1619
1671
|
transaction,
|
|
1620
|
-
this.getProviderName()
|
|
1672
|
+
this.getProviderName(),
|
|
1673
|
+
{
|
|
1674
|
+
clientName: typeof clientName === "string" ? clientName : void 0,
|
|
1675
|
+
cookie: this.consentCookie(consentBinding)
|
|
1676
|
+
}
|
|
1621
1677
|
);
|
|
1622
1678
|
}
|
|
1623
1679
|
return this.redirectToUpstream(transaction);
|
|
@@ -1630,7 +1686,7 @@ var OAuthProxy = (_class4 = class {
|
|
|
1630
1686
|
clearInterval(this.cleanupInterval);
|
|
1631
1687
|
this.cleanupInterval = null;
|
|
1632
1688
|
}
|
|
1633
|
-
_optionalChain([this, 'access',
|
|
1689
|
+
_optionalChain([this, 'access', _18 => _18.ownedTokenStorage, 'optionalAccess', _19 => _19.destroy, 'call', _20 => _20()]);
|
|
1634
1690
|
this.registeredClientsByClientId.clear();
|
|
1635
1691
|
}
|
|
1636
1692
|
/**
|
|
@@ -1788,7 +1844,7 @@ var OAuthProxy = (_class4 = class {
|
|
|
1788
1844
|
const error = url.searchParams.get("error");
|
|
1789
1845
|
const description = url.searchParams.get("error_description") || void 0;
|
|
1790
1846
|
if (error) {
|
|
1791
|
-
if (!state || url.searchParams.getAll("state").length !== 1 || !GENERATED_ID.test(state) || await _asyncOptionalChain([(await this.stateStore.getTransaction(state)), 'optionalAccess', async
|
|
1847
|
+
if (!state || url.searchParams.getAll("state").length !== 1 || !GENERATED_ID.test(state) || await _asyncOptionalChain([(await this.stateStore.getTransaction(state)), 'optionalAccess', async _21 => _21.id]) !== state) {
|
|
1792
1848
|
throw new OAuthProxyError(error, description);
|
|
1793
1849
|
}
|
|
1794
1850
|
} else if (!code || !state) {
|
|
@@ -1801,6 +1857,12 @@ var OAuthProxy = (_class4 = class {
|
|
|
1801
1857
|
if (!transaction) {
|
|
1802
1858
|
throw new OAuthProxyError("invalid_request", "Invalid or expired state");
|
|
1803
1859
|
}
|
|
1860
|
+
if (this.config.consentRequired && !(transaction.consentGiven && this.isConsentBoundTo(request2, transaction))) {
|
|
1861
|
+
throw new OAuthProxyError(
|
|
1862
|
+
"access_denied",
|
|
1863
|
+
"This authorization request was not approved in this browser"
|
|
1864
|
+
);
|
|
1865
|
+
}
|
|
1804
1866
|
if (!await this.isTransactionCallbackRegistered(transaction)) {
|
|
1805
1867
|
throw new OAuthProxyError(
|
|
1806
1868
|
"invalid_request",
|
|
@@ -1850,6 +1912,12 @@ var OAuthProxy = (_class4 = class {
|
|
|
1850
1912
|
"Invalid or expired transaction"
|
|
1851
1913
|
);
|
|
1852
1914
|
}
|
|
1915
|
+
if (!this.isConsentBoundTo(request2, transaction)) {
|
|
1916
|
+
throw new OAuthProxyError(
|
|
1917
|
+
"invalid_request",
|
|
1918
|
+
"Consent must be given in the browser that requested it"
|
|
1919
|
+
);
|
|
1920
|
+
}
|
|
1853
1921
|
if (action === "deny") {
|
|
1854
1922
|
await this.stateStore.deleteTransaction(transactionId);
|
|
1855
1923
|
if (!await this.isTransactionCallbackRegistered(transaction)) {
|
|
@@ -1878,7 +1946,7 @@ var OAuthProxy = (_class4 = class {
|
|
|
1878
1946
|
return null;
|
|
1879
1947
|
}
|
|
1880
1948
|
const result = await this.jwtIssuer.verify(vitemcpToken);
|
|
1881
|
-
if (!result.valid || !_optionalChain([result, 'access',
|
|
1949
|
+
if (!result.valid || !_optionalChain([result, 'access', _22 => _22.claims, 'optionalAccess', _23 => _23.jti])) {
|
|
1882
1950
|
return null;
|
|
1883
1951
|
}
|
|
1884
1952
|
if (result.claims.token_use !== "access") {
|
|
@@ -2044,10 +2112,49 @@ var OAuthProxy = (_class4 = class {
|
|
|
2044
2112
|
);
|
|
2045
2113
|
});
|
|
2046
2114
|
}
|
|
2115
|
+
/**
|
|
2116
|
+
* The cookie that ties consent requests to the browser they were shown to.
|
|
2117
|
+
* A browser holds one, shared by every request it has open, and it lasts as
|
|
2118
|
+
* long as a request does. `Lax` lets it travel with the provider's redirect
|
|
2119
|
+
* back to the callback, which is a cross-site navigation. Over HTTPS the
|
|
2120
|
+
* `__Host-` prefix keeps another host on the same site from setting it.
|
|
2121
|
+
*/
|
|
2122
|
+
consentCookie(value) {
|
|
2123
|
+
return [
|
|
2124
|
+
`${this.consentCookieName()}=${value}`,
|
|
2125
|
+
"Path=/",
|
|
2126
|
+
`Max-Age=${this.config.transactionTtl || DEFAULT_TRANSACTION_TTL}`,
|
|
2127
|
+
"HttpOnly",
|
|
2128
|
+
"SameSite=Lax",
|
|
2129
|
+
...this.isServedOverHttps() ? ["Secure"] : []
|
|
2130
|
+
].join("; ");
|
|
2131
|
+
}
|
|
2132
|
+
consentCookieName() {
|
|
2133
|
+
return `${this.isServedOverHttps() ? "__Host-" : ""}vitemcp-consent`;
|
|
2134
|
+
}
|
|
2135
|
+
/**
|
|
2136
|
+
* The consent cookie `request` carries, if it carries a well-formed one.
|
|
2137
|
+
*
|
|
2138
|
+
* Only the spaces and tabs that may surround a cookie are dropped. Trimming
|
|
2139
|
+
* all white space would take a cookie whose name begins with, say, a
|
|
2140
|
+
* no-break space for this one, and a browser does not hold such a name to
|
|
2141
|
+
* the `__Host-` rules.
|
|
2142
|
+
*/
|
|
2143
|
+
consentCookieValue(request2) {
|
|
2144
|
+
const name = this.consentCookieName();
|
|
2145
|
+
for (const pair of (_nullishCoalesce(request2.headers.get("cookie"), () => ( ""))).split(";")) {
|
|
2146
|
+
const separator = pair.indexOf("=");
|
|
2147
|
+
if (separator !== -1 && withoutOptionalWhitespace(pair.slice(0, separator)) === name) {
|
|
2148
|
+
const value = withoutOptionalWhitespace(pair.slice(separator + 1));
|
|
2149
|
+
return GENERATED_ID.test(value) ? value : void 0;
|
|
2150
|
+
}
|
|
2151
|
+
}
|
|
2152
|
+
return void 0;
|
|
2153
|
+
}
|
|
2047
2154
|
/**
|
|
2048
2155
|
* Create a new OAuth transaction
|
|
2049
2156
|
*/
|
|
2050
|
-
async createTransaction(params) {
|
|
2157
|
+
async createTransaction(params, consentBinding) {
|
|
2051
2158
|
const transactionId = this.generateId();
|
|
2052
2159
|
const proxyPkce = PKCEUtils.generatePair("S256");
|
|
2053
2160
|
const transaction = {
|
|
@@ -2055,6 +2162,7 @@ var OAuthProxy = (_class4 = class {
|
|
|
2055
2162
|
clientCodeChallenge: params.code_challenge || "",
|
|
2056
2163
|
clientCodeChallengeMethod: params.code_challenge_method || "plain",
|
|
2057
2164
|
clientId: params.client_id,
|
|
2165
|
+
...consentBinding && { consentBinding: sha256(consentBinding) },
|
|
2058
2166
|
createdAt: /* @__PURE__ */ new Date(),
|
|
2059
2167
|
expiresAt: new Date(
|
|
2060
2168
|
Date.now() + (this.config.transactionTtl || 600) * 1e3
|
|
@@ -2098,7 +2206,7 @@ var OAuthProxy = (_class4 = class {
|
|
|
2098
2206
|
const error = await this.readUpstreamError(tokenResponse);
|
|
2099
2207
|
errorCode = error.error || "server_error";
|
|
2100
2208
|
errorDescription = error.error_description;
|
|
2101
|
-
} catch (
|
|
2209
|
+
} catch (e8) {
|
|
2102
2210
|
errorDescription = `Upstream returned HTTP ${tokenResponse.status} ${tokenResponse.statusText}`;
|
|
2103
2211
|
}
|
|
2104
2212
|
throw new OAuthProxyError(errorCode, errorDescription);
|
|
@@ -2126,7 +2234,7 @@ var OAuthProxy = (_class4 = class {
|
|
|
2126
2234
|
throw new Error("JWT issuer not initialized");
|
|
2127
2235
|
}
|
|
2128
2236
|
const result = await this.jwtIssuer.verify(token);
|
|
2129
|
-
if (!result.valid || !_optionalChain([result, 'access',
|
|
2237
|
+
if (!result.valid || !_optionalChain([result, 'access', _24 => _24.claims, 'optionalAccess', _25 => _25.jti])) {
|
|
2130
2238
|
throw new Error("Failed to extract JTI from token");
|
|
2131
2239
|
}
|
|
2132
2240
|
return result.claims.jti;
|
|
@@ -2302,7 +2410,7 @@ var OAuthProxy = (_class4 = class {
|
|
|
2302
2410
|
const error = await this.readUpstreamError(tokenResponse);
|
|
2303
2411
|
errorCode = error.error || "invalid_grant";
|
|
2304
2412
|
errorDescription = error.error_description;
|
|
2305
|
-
} catch (
|
|
2413
|
+
} catch (e9) {
|
|
2306
2414
|
errorDescription = `Upstream returned HTTP ${tokenResponse.status} ${tokenResponse.statusText}`;
|
|
2307
2415
|
}
|
|
2308
2416
|
throw new OAuthProxyError(errorCode, errorDescription);
|
|
@@ -2425,6 +2533,21 @@ var OAuthProxy = (_class4 = class {
|
|
|
2425
2533
|
throw error;
|
|
2426
2534
|
}
|
|
2427
2535
|
}
|
|
2536
|
+
/**
|
|
2537
|
+
* Whether `request` comes from the browser the transaction's consent screen
|
|
2538
|
+
* was shown to: it carries the cookie that screen set. A transaction that
|
|
2539
|
+
* never had a consent screen is bound to no browser.
|
|
2540
|
+
*/
|
|
2541
|
+
isConsentBoundTo(request2, transaction) {
|
|
2542
|
+
const presented = this.consentCookieValue(request2);
|
|
2543
|
+
return Boolean(
|
|
2544
|
+
presented && transaction.consentBinding && secretsMatch(sha256(presented), transaction.consentBinding)
|
|
2545
|
+
);
|
|
2546
|
+
}
|
|
2547
|
+
/** Whether browsers reach this proxy over HTTPS, going by its `baseUrl`. */
|
|
2548
|
+
isServedOverHttps() {
|
|
2549
|
+
return /^https:/i.test(this.config.baseUrl);
|
|
2550
|
+
}
|
|
2428
2551
|
/**
|
|
2429
2552
|
* Issue swapped tokens (JWT pattern)
|
|
2430
2553
|
* Issues short-lived ViteMCP JWTs and stores upstream tokens securely
|
|
@@ -2576,7 +2699,7 @@ var OAuthProxy = (_class4 = class {
|
|
|
2576
2699
|
let client;
|
|
2577
2700
|
try {
|
|
2578
2701
|
client = await this.resolveClient(transaction.clientId);
|
|
2579
|
-
} catch (
|
|
2702
|
+
} catch (e10) {
|
|
2580
2703
|
return false;
|
|
2581
2704
|
}
|
|
2582
2705
|
return client.redirectUris.some(
|
|
@@ -2705,7 +2828,7 @@ var OAuthProxy = (_class4 = class {
|
|
|
2705
2828
|
try {
|
|
2706
2829
|
return JSON.parse(text);
|
|
2707
2830
|
} catch (cause) {
|
|
2708
|
-
const mediaType = _optionalChain([response, 'access',
|
|
2831
|
+
const mediaType = _optionalChain([response, 'access', _26 => _26.headers, 'access', _27 => _27.get, 'call', _28 => _28("content-type"), 'optionalAccess', _29 => _29.split, 'call', _30 => _30(";", 1), 'access', _31 => _31[0], 'optionalAccess', _32 => _32.trim, 'call', _33 => _33(), 'access', _34 => _34.toLowerCase, 'call', _35 => _35()]);
|
|
2709
2832
|
if (mediaType === "application/x-www-form-urlencoded") {
|
|
2710
2833
|
const params = new URLSearchParams(text);
|
|
2711
2834
|
const error = params.get("error");
|
|
@@ -2807,7 +2930,7 @@ var OAuthProxy = (_class4 = class {
|
|
|
2807
2930
|
const error = await this.readUpstreamError(tokenResponse);
|
|
2808
2931
|
errorCode = error.error || "invalid_grant";
|
|
2809
2932
|
errorDescription = error.error_description || "Upstream refresh failed";
|
|
2810
|
-
} catch (
|
|
2933
|
+
} catch (e11) {
|
|
2811
2934
|
errorDescription = `Upstream returned HTTP ${tokenResponse.status} ${tokenResponse.statusText}`;
|
|
2812
2935
|
}
|
|
2813
2936
|
throw new OAuthProxyError(errorCode, errorDescription);
|
|
@@ -2945,7 +3068,7 @@ var OAuthProxy = (_class4 = class {
|
|
|
2945
3068
|
this.cleanupInterval = setInterval(() => {
|
|
2946
3069
|
this.cleanup();
|
|
2947
3070
|
}, 6e4);
|
|
2948
|
-
_optionalChain([this, 'access',
|
|
3071
|
+
_optionalChain([this, 'access', _36 => _36.cleanupInterval, 'access', _37 => _37.unref, 'optionalCall', _38 => _38()]);
|
|
2949
3072
|
}
|
|
2950
3073
|
/**
|
|
2951
3074
|
* PKCE challenge methods this proxy accepts, advertised in the authorization
|
|
@@ -2997,7 +3120,7 @@ var OAuthProxy = (_class4 = class {
|
|
|
2997
3120
|
let url;
|
|
2998
3121
|
try {
|
|
2999
3122
|
url = new URL(uri);
|
|
3000
|
-
} catch (
|
|
3123
|
+
} catch (e12) {
|
|
3001
3124
|
return false;
|
|
3002
3125
|
}
|
|
3003
3126
|
if (url.username !== "" || url.password !== "") {
|
|
@@ -3062,7 +3185,7 @@ var isLoopbackRedirectUri = (uri) => {
|
|
|
3062
3185
|
return isLoopbackHostname(url.hostname);
|
|
3063
3186
|
}
|
|
3064
3187
|
return url.protocol !== "";
|
|
3065
|
-
} catch (
|
|
3188
|
+
} catch (e13) {
|
|
3066
3189
|
return false;
|
|
3067
3190
|
}
|
|
3068
3191
|
};
|
|
@@ -3081,6 +3204,8 @@ var secretsMatch = (presented, expected) => _crypto.timingSafeEqual.call(void 0,
|
|
|
3081
3204
|
_crypto.createHash.call(void 0, "sha256").update(presented).digest(),
|
|
3082
3205
|
_crypto.createHash.call(void 0, "sha256").update(expected).digest()
|
|
3083
3206
|
);
|
|
3207
|
+
var sha256 = (value) => _crypto.createHash.call(void 0, "sha256").update(value).digest("base64url");
|
|
3208
|
+
var withoutOptionalWhitespace = (value) => value.replace(/^[ \t]+|[ \t]+$/g, "");
|
|
3084
3209
|
var OAuthProxyError = class extends Error {
|
|
3085
3210
|
constructor(code, description, statusCode = 400) {
|
|
3086
3211
|
super(code);
|
|
@@ -3144,9 +3269,9 @@ var AuthProvider = (_class5 = class {
|
|
|
3144
3269
|
if (!request2) {
|
|
3145
3270
|
return void 0;
|
|
3146
3271
|
}
|
|
3147
|
-
const token = _optionalChain([/^bearer +(\S.*)$/i, 'access',
|
|
3272
|
+
const token = _optionalChain([/^bearer +(\S.*)$/i, 'access', _39 => _39.exec, 'call', _40 => _40(
|
|
3148
3273
|
_nullishCoalesce(request2.headers.get("authorization"), () => ( ""))
|
|
3149
|
-
), 'optionalAccess',
|
|
3274
|
+
), 'optionalAccess', _41 => _41[1]]);
|
|
3150
3275
|
if (!token) {
|
|
3151
3276
|
return void 0;
|
|
3152
3277
|
}
|
|
@@ -3175,7 +3300,7 @@ var AuthProvider = (_class5 = class {
|
|
|
3175
3300
|
*/
|
|
3176
3301
|
destroy() {
|
|
3177
3302
|
this._destroyed = true;
|
|
3178
|
-
_optionalChain([this, 'access',
|
|
3303
|
+
_optionalChain([this, 'access', _42 => _42._proxy, 'optionalAccess', _43 => _43.destroy, 'call', _44 => _44()]);
|
|
3179
3304
|
this._proxy = void 0;
|
|
3180
3305
|
}
|
|
3181
3306
|
/**
|
|
@@ -3390,7 +3515,7 @@ var DiskStore = (_class6 = class {
|
|
|
3390
3515
|
this.cleanupInterval = setInterval(() => {
|
|
3391
3516
|
void this.cleanup();
|
|
3392
3517
|
}, cleanupIntervalMs);
|
|
3393
|
-
_optionalChain([this, 'access',
|
|
3518
|
+
_optionalChain([this, 'access', _45 => _45.cleanupInterval, 'access', _46 => _46.unref, 'optionalCall', _47 => _47()]);
|
|
3394
3519
|
}
|
|
3395
3520
|
/**
|
|
3396
3521
|
* Clean up expired entries.
|
|
@@ -3482,7 +3607,7 @@ var DiskStore = (_class6 = class {
|
|
|
3482
3607
|
await this.ensureDirectory();
|
|
3483
3608
|
const files = await _promises.readdir.call(void 0, this.directory);
|
|
3484
3609
|
return files.filter((f) => f.endsWith(this.fileExtension)).length;
|
|
3485
|
-
} catch (
|
|
3610
|
+
} catch (e14) {
|
|
3486
3611
|
return 0;
|
|
3487
3612
|
}
|
|
3488
3613
|
}
|
|
@@ -3564,7 +3689,7 @@ var DiskStore = (_class6 = class {
|
|
|
3564
3689
|
console.warn(`Failed to read/parse file ${file}, deleting:`, error);
|
|
3565
3690
|
try {
|
|
3566
3691
|
await _promises.rm.call(void 0, _path.join.call(void 0, this.directory, file));
|
|
3567
|
-
} catch (
|
|
3692
|
+
} catch (e15) {
|
|
3568
3693
|
}
|
|
3569
3694
|
}
|
|
3570
3695
|
}
|
|
@@ -3754,4 +3879,4 @@ Original error: ${error.message}`
|
|
|
3754
3879
|
|
|
3755
3880
|
|
|
3756
3881
|
exports.withoutTrailingSlash = withoutTrailingSlash; exports.getAuthSession = getAuthSession; exports.requireAll = requireAll; exports.requireAny = requireAny; exports.requireAuth = requireAuth; exports.requireRole = requireRole; exports.requireScopes = requireScopes; exports.DEFAULT_ACCESS_TOKEN_TTL = DEFAULT_ACCESS_TOKEN_TTL; exports.DEFAULT_ACCESS_TOKEN_TTL_NO_REFRESH = DEFAULT_ACCESS_TOKEN_TTL_NO_REFRESH; exports.DEFAULT_REFRESH_TOKEN_TTL = DEFAULT_REFRESH_TOKEN_TTL; exports.DEFAULT_AUTHORIZATION_CODE_TTL = DEFAULT_AUTHORIZATION_CODE_TTL; exports.DEFAULT_TRANSACTION_TTL = DEFAULT_TRANSACTION_TTL; exports.ConsentManager = ConsentManager; exports.JWTIssuer = JWTIssuer; exports.PKCEUtils = PKCEUtils; exports.EncryptedTokenStorage = EncryptedTokenStorage; exports.MemoryTokenStorage = MemoryTokenStorage; exports.OAuthProxy = OAuthProxy; exports.OAuthProxyError = OAuthProxyError; exports.AuthProvider = AuthProvider; exports.AzureProvider = AzureProvider; exports.GitHubProvider = GitHubProvider; exports.GoogleProvider = GoogleProvider; exports.OAuthProvider = OAuthProvider; exports.DiskStore = DiskStore; exports.JWKSVerifier = JWKSVerifier;
|
|
3757
|
-
//# sourceMappingURL=chunk-
|
|
3882
|
+
//# sourceMappingURL=chunk-R3JUTGZL.cjs.map
|