@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 = z.object({
|
|
|
392
392
|
clientCodeChallenge: z.string(),
|
|
393
393
|
clientCodeChallengeMethod: z.string(),
|
|
394
394
|
clientId: z.string(),
|
|
395
|
+
consentBinding: z.string().optional(),
|
|
395
396
|
consentGiven: 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 {
|
|
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
|
*/
|
|
@@ -1215,6 +1254,7 @@ function loopbackRedirectMatches(declared, requested) {
|
|
|
1215
1254
|
|
|
1216
1255
|
// src/auth/utils/pkce.ts
|
|
1217
1256
|
import { createHash as createHash2, randomBytes as randomBytes2, timingSafeEqual as timingSafeEqual3 } from "crypto";
|
|
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 = class {
|
|
|
1511
1554
|
constructor(config) {
|
|
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 = 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: config.consentRequired ?? true
|
|
1523
1568
|
};
|
|
1524
1569
|
let storage = config.tokenStorage;
|
|
1525
1570
|
if (!storage) {
|
|
@@ -1560,8 +1605,13 @@ var OAuthProxy = 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 = class {
|
|
|
1613
1663
|
);
|
|
1614
1664
|
}
|
|
1615
1665
|
}
|
|
1616
|
-
const
|
|
1617
|
-
|
|
1666
|
+
const consentBinding = this.config.consentRequired ? (request2 && this.consentCookieValue(request2)) ?? this.generateId() : void 0;
|
|
1667
|
+
const transaction = await this.createTransaction(params, consentBinding);
|
|
1668
|
+
if (consentBinding && !transaction.consentGiven) {
|
|
1669
|
+
const clientName = registeredClient.metadata?.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);
|
|
@@ -1801,6 +1857,12 @@ var OAuthProxy = 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 = 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)) {
|
|
@@ -2044,10 +2112,49 @@ var OAuthProxy = 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 (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 = 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
|
|
@@ -2425,6 +2533,21 @@ var OAuthProxy = 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
|
|
@@ -3081,6 +3204,8 @@ var secretsMatch = (presented, expected) => timingSafeEqual4(
|
|
|
3081
3204
|
createHash3("sha256").update(presented).digest(),
|
|
3082
3205
|
createHash3("sha256").update(expected).digest()
|
|
3083
3206
|
);
|
|
3207
|
+
var sha256 = (value) => createHash3("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);
|
|
@@ -3754,4 +3879,4 @@ export {
|
|
|
3754
3879
|
DiskStore,
|
|
3755
3880
|
JWKSVerifier
|
|
3756
3881
|
};
|
|
3757
|
-
//# sourceMappingURL=chunk-
|
|
3882
|
+
//# sourceMappingURL=chunk-AOZIQIXA.js.map
|