@vitemcp/server 1.9.16 → 1.9.17

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.
@@ -77,6 +77,8 @@ interface ClientCode {
77
77
  interface ConsentData {
78
78
  clientName: string;
79
79
  provider: string;
80
+ /** Where the client is sent once the user approves. */
81
+ redirectUri?: string;
80
82
  scope: string[];
81
83
  timestamp: number;
82
84
  transactionId: string;
@@ -346,6 +348,11 @@ interface OAuthTransaction {
346
348
  clientCodeChallengeMethod: string;
347
349
  /** Client ID from registration */
348
350
  clientId: string;
351
+ /**
352
+ * Digest of the cookie held by the browser the consent screen was shown to.
353
+ * Approving the request and finishing it both take that cookie.
354
+ */
355
+ consentBinding?: string;
349
356
  /** Whether user consent was given */
350
357
  consentGiven?: boolean;
351
358
  /** Transaction creation timestamp */
@@ -578,8 +585,13 @@ declare class OAuthProxy {
578
585
  constructor(config: OAuthProxyConfig);
579
586
  /**
580
587
  * OAuth authorization endpoint
588
+ *
589
+ * With consent required the response is the consent screen, and it sets the
590
+ * cookie that the request is approved and finished with: return its headers
591
+ * to the browser. Pass that browser's `request` as well, so that one with
592
+ * several authorization requests open keeps a single cookie for all of them.
581
593
  */
582
- authorize(params: AuthorizationParams): Promise<Response>;
594
+ authorize(params: AuthorizationParams, request?: Request): Promise<Response>;
583
595
  /**
584
596
  * Stop cleanup interval and destroy resources
585
597
  */
@@ -663,6 +675,24 @@ declare class OAuthProxy {
663
675
  * Periodic maintenance hook. Expiry is enforced by the token storage.
664
676
  */
665
677
  private cleanup;
678
+ /**
679
+ * The cookie that ties consent requests to the browser they were shown to.
680
+ * A browser holds one, shared by every request it has open, and it lasts as
681
+ * long as a request does. `Lax` lets it travel with the provider's redirect
682
+ * back to the callback, which is a cross-site navigation. Over HTTPS the
683
+ * `__Host-` prefix keeps another host on the same site from setting it.
684
+ */
685
+ private consentCookie;
686
+ private consentCookieName;
687
+ /**
688
+ * The consent cookie `request` carries, if it carries a well-formed one.
689
+ *
690
+ * Only the spaces and tabs that may surround a cookie are dropped. Trimming
691
+ * all white space would take a cookie whose name begins with, say, a
692
+ * no-break space for this one, and a browser does not hold such a name to
693
+ * the `__Host-` rules.
694
+ */
695
+ private consentCookieValue;
666
696
  /**
667
697
  * Create a new OAuth transaction
668
698
  */
@@ -725,6 +755,14 @@ declare class OAuthProxy {
725
755
  * Handle swap mode refresh - verify ViteMCP JWT and issue new tokens
726
756
  */
727
757
  private handleSwapModeRefresh;
758
+ /**
759
+ * Whether `request` comes from the browser the transaction's consent screen
760
+ * was shown to: it carries the cookie that screen set. A transaction that
761
+ * never had a consent screen is bound to no browser.
762
+ */
763
+ private isConsentBoundTo;
764
+ /** Whether browsers reach this proxy over HTTPS, going by its `baseUrl`. */
765
+ private isServedOverHttps;
728
766
  /**
729
767
  * Issue swapped tokens (JWT pattern)
730
768
  * Issues short-lived ViteMCP JWTs and stores upstream tokens securely
@@ -77,6 +77,8 @@ interface ClientCode {
77
77
  interface ConsentData {
78
78
  clientName: string;
79
79
  provider: string;
80
+ /** Where the client is sent once the user approves. */
81
+ redirectUri?: string;
80
82
  scope: string[];
81
83
  timestamp: number;
82
84
  transactionId: string;
@@ -346,6 +348,11 @@ interface OAuthTransaction {
346
348
  clientCodeChallengeMethod: string;
347
349
  /** Client ID from registration */
348
350
  clientId: string;
351
+ /**
352
+ * Digest of the cookie held by the browser the consent screen was shown to.
353
+ * Approving the request and finishing it both take that cookie.
354
+ */
355
+ consentBinding?: string;
349
356
  /** Whether user consent was given */
350
357
  consentGiven?: boolean;
351
358
  /** Transaction creation timestamp */
@@ -578,8 +585,13 @@ declare class OAuthProxy {
578
585
  constructor(config: OAuthProxyConfig);
579
586
  /**
580
587
  * OAuth authorization endpoint
588
+ *
589
+ * With consent required the response is the consent screen, and it sets the
590
+ * cookie that the request is approved and finished with: return its headers
591
+ * to the browser. Pass that browser's `request` as well, so that one with
592
+ * several authorization requests open keeps a single cookie for all of them.
581
593
  */
582
- authorize(params: AuthorizationParams): Promise<Response>;
594
+ authorize(params: AuthorizationParams, request?: Request): Promise<Response>;
583
595
  /**
584
596
  * Stop cleanup interval and destroy resources
585
597
  */
@@ -663,6 +675,24 @@ declare class OAuthProxy {
663
675
  * Periodic maintenance hook. Expiry is enforced by the token storage.
664
676
  */
665
677
  private cleanup;
678
+ /**
679
+ * The cookie that ties consent requests to the browser they were shown to.
680
+ * A browser holds one, shared by every request it has open, and it lasts as
681
+ * long as a request does. `Lax` lets it travel with the provider's redirect
682
+ * back to the callback, which is a cross-site navigation. Over HTTPS the
683
+ * `__Host-` prefix keeps another host on the same site from setting it.
684
+ */
685
+ private consentCookie;
686
+ private consentCookieName;
687
+ /**
688
+ * The consent cookie `request` carries, if it carries a well-formed one.
689
+ *
690
+ * Only the spaces and tabs that may surround a cookie are dropped. Trimming
691
+ * all white space would take a cookie whose name begins with, say, a
692
+ * no-break space for this one, and a browser does not hold such a name to
693
+ * the `__Host-` rules.
694
+ */
695
+ private consentCookieValue;
666
696
  /**
667
697
  * Create a new OAuth transaction
668
698
  */
@@ -725,6 +755,14 @@ declare class OAuthProxy {
725
755
  * Handle swap mode refresh - verify ViteMCP JWT and issue new tokens
726
756
  */
727
757
  private handleSwapModeRefresh;
758
+ /**
759
+ * Whether `request` comes from the browser the transaction's consent screen
760
+ * was shown to: it carries the cookie that screen set. A transaction that
761
+ * never had a consent screen is bound to no browser.
762
+ */
763
+ private isConsentBoundTo;
764
+ /** Whether browsers reach this proxy over HTTPS, going by its `baseUrl`. */
765
+ private isServedOverHttps;
728
766
  /**
729
767
  * Issue swapped tokens (JWT pattern)
730
768
  * Issues short-lived ViteMCP JWTs and stores upstream tokens securely
package/dist/ViteMCP.cjs CHANGED
@@ -10,7 +10,7 @@
10
10
 
11
11
 
12
12
 
13
- var _chunkHDJEH7NKcjs = require('./chunk-HDJEH7NK.cjs');
13
+ var _chunkTNT3APOKcjs = require('./chunk-TNT3APOK.cjs');
14
14
 
15
15
 
16
16
 
@@ -25,7 +25,7 @@ var _chunkHDJEH7NKcjs = require('./chunk-HDJEH7NK.cjs');
25
25
 
26
26
 
27
27
 
28
- var _chunkTWYBLPRQcjs = require('./chunk-TWYBLPRQ.cjs');
28
+ var _chunkZEYQBA72cjs = require('./chunk-ZEYQBA72.cjs');
29
29
  require('./chunk-QPVEGWOL.cjs');
30
30
 
31
31
 
@@ -52,5 +52,5 @@ require('./chunk-QPVEGWOL.cjs');
52
52
 
53
53
 
54
54
 
55
- exports.AuthProvider = _chunkTWYBLPRQcjs.AuthProvider; exports.AzureProvider = _chunkTWYBLPRQcjs.AzureProvider; exports.DiscoveryDocumentCache = _chunkHDJEH7NKcjs.DiscoveryDocumentCache; exports.GitHubProvider = _chunkTWYBLPRQcjs.GitHubProvider; exports.GoogleProvider = _chunkTWYBLPRQcjs.GoogleProvider; exports.MEDIA_FETCH_TIMEOUT_MS = _chunkHDJEH7NKcjs.MEDIA_FETCH_TIMEOUT_MS; exports.OAuthProvider = _chunkTWYBLPRQcjs.OAuthProvider; exports.OAuthProxy = _chunkTWYBLPRQcjs.OAuthProxy; exports.OAuthProxyError = _chunkTWYBLPRQcjs.OAuthProxyError; exports.ServerState = _chunkHDJEH7NKcjs.ServerState; exports.UnexpectedStateError = _chunkHDJEH7NKcjs.UnexpectedStateError; exports.UserError = _chunkHDJEH7NKcjs.UserError; exports.ViteMCP = _chunkHDJEH7NKcjs.ViteMCP; exports.ViteMCPError = _chunkHDJEH7NKcjs.ViteMCPError; exports.audioContent = _chunkHDJEH7NKcjs.audioContent; exports.delay = _chunkHDJEH7NKcjs.delay; exports.getAuthSession = _chunkTWYBLPRQcjs.getAuthSession; exports.imageContent = _chunkHDJEH7NKcjs.imageContent; exports.jsonSchemaAdapter = _chunkHDJEH7NKcjs.jsonSchemaAdapter; exports.requireAll = _chunkTWYBLPRQcjs.requireAll; exports.requireAny = _chunkTWYBLPRQcjs.requireAny; exports.requireAuth = _chunkTWYBLPRQcjs.requireAuth; exports.requireRole = _chunkTWYBLPRQcjs.requireRole; exports.requireScopes = _chunkTWYBLPRQcjs.requireScopes;
55
+ exports.AuthProvider = _chunkZEYQBA72cjs.AuthProvider; exports.AzureProvider = _chunkZEYQBA72cjs.AzureProvider; exports.DiscoveryDocumentCache = _chunkTNT3APOKcjs.DiscoveryDocumentCache; exports.GitHubProvider = _chunkZEYQBA72cjs.GitHubProvider; exports.GoogleProvider = _chunkZEYQBA72cjs.GoogleProvider; exports.MEDIA_FETCH_TIMEOUT_MS = _chunkTNT3APOKcjs.MEDIA_FETCH_TIMEOUT_MS; exports.OAuthProvider = _chunkZEYQBA72cjs.OAuthProvider; exports.OAuthProxy = _chunkZEYQBA72cjs.OAuthProxy; exports.OAuthProxyError = _chunkZEYQBA72cjs.OAuthProxyError; exports.ServerState = _chunkTNT3APOKcjs.ServerState; exports.UnexpectedStateError = _chunkTNT3APOKcjs.UnexpectedStateError; exports.UserError = _chunkTNT3APOKcjs.UserError; exports.ViteMCP = _chunkTNT3APOKcjs.ViteMCP; exports.ViteMCPError = _chunkTNT3APOKcjs.ViteMCPError; exports.audioContent = _chunkTNT3APOKcjs.audioContent; exports.delay = _chunkTNT3APOKcjs.delay; exports.getAuthSession = _chunkZEYQBA72cjs.getAuthSession; exports.imageContent = _chunkTNT3APOKcjs.imageContent; exports.jsonSchemaAdapter = _chunkTNT3APOKcjs.jsonSchemaAdapter; exports.requireAll = _chunkZEYQBA72cjs.requireAll; exports.requireAny = _chunkZEYQBA72cjs.requireAny; exports.requireAuth = _chunkZEYQBA72cjs.requireAuth; exports.requireRole = _chunkZEYQBA72cjs.requireRole; exports.requireScopes = _chunkZEYQBA72cjs.requireScopes;
56
56
  //# sourceMappingURL=ViteMCP.cjs.map
@@ -4,8 +4,8 @@ import { StandardSchemaV1 } from '@standard-schema/spec';
4
4
  import { Hono } from 'hono';
5
5
  import { cors } from 'hono/cors';
6
6
  export { setTimeout as delay } from 'timers/promises';
7
- import { A as AuthProvider, O as OAuthSession, a as OAuthProxy } from './OAuthProvider-DNKBMBPU.cjs';
8
- export { j as AuthProviderConfig, b as AzureProvider, k as AzureProviderConfig, l as AzureSession, m as GenericOAuthProviderConfig, G as GitHubProvider, n as GitHubSession, c as GoogleProvider, o as GoogleSession, d as OAuthProvider, p as OAuthProxyError, g as getAuthSession, r as requireAll, e as requireAny, f as requireAuth, h as requireRole, i as requireScopes } from './OAuthProvider-DNKBMBPU.cjs';
7
+ import { A as AuthProvider, O as OAuthSession, a as OAuthProxy } from './OAuthProvider-STkC4R2N.cjs';
8
+ export { j as AuthProviderConfig, b as AzureProvider, k as AzureProviderConfig, l as AzureSession, m as GenericOAuthProviderConfig, G as GitHubProvider, n as GitHubSession, c as GoogleProvider, o as GoogleSession, d as OAuthProvider, p as OAuthProxyError, g as getAuthSession, r as requireAll, e as requireAny, f as requireAuth, h as requireRole, i as requireScopes } from './OAuthProvider-STkC4R2N.cjs';
9
9
 
10
10
  declare class DiscoveryDocumentCache {
11
11
  #private;
package/dist/ViteMCP.d.ts CHANGED
@@ -4,8 +4,8 @@ import { StandardSchemaV1 } from '@standard-schema/spec';
4
4
  import { Hono } from 'hono';
5
5
  import { cors } from 'hono/cors';
6
6
  export { setTimeout as delay } from 'timers/promises';
7
- import { A as AuthProvider, O as OAuthSession, a as OAuthProxy } from './OAuthProvider-DNKBMBPU.js';
8
- export { j as AuthProviderConfig, b as AzureProvider, k as AzureProviderConfig, l as AzureSession, m as GenericOAuthProviderConfig, G as GitHubProvider, n as GitHubSession, c as GoogleProvider, o as GoogleSession, d as OAuthProvider, p as OAuthProxyError, g as getAuthSession, r as requireAll, e as requireAny, f as requireAuth, h as requireRole, i as requireScopes } from './OAuthProvider-DNKBMBPU.js';
7
+ import { A as AuthProvider, O as OAuthSession, a as OAuthProxy } from './OAuthProvider-STkC4R2N.js';
8
+ export { j as AuthProviderConfig, b as AzureProvider, k as AzureProviderConfig, l as AzureSession, m as GenericOAuthProviderConfig, G as GitHubProvider, n as GitHubSession, c as GoogleProvider, o as GoogleSession, d as OAuthProvider, p as OAuthProxyError, g as getAuthSession, r as requireAll, e as requireAny, f as requireAuth, h as requireRole, i as requireScopes } from './OAuthProvider-STkC4R2N.js';
9
9
 
10
10
  declare class DiscoveryDocumentCache {
11
11
  #private;
package/dist/ViteMCP.js CHANGED
@@ -10,7 +10,7 @@ import {
10
10
  delay,
11
11
  imageContent,
12
12
  jsonSchemaAdapter
13
- } from "./chunk-LZTRZ62V.js";
13
+ } from "./chunk-B3LLXB6O.js";
14
14
  import {
15
15
  AuthProvider,
16
16
  AzureProvider,
@@ -25,7 +25,7 @@ import {
25
25
  requireAuth,
26
26
  requireRole,
27
27
  requireScopes
28
- } from "./chunk-PXH56Q3F.js";
28
+ } from "./chunk-4BX2CT5Z.js";
29
29
  import "./chunk-JMDI672G.js";
30
30
  export {
31
31
  AuthProvider,
@@ -24,7 +24,7 @@
24
24
 
25
25
 
26
26
 
27
- var _chunkTWYBLPRQcjs = require('../chunk-TWYBLPRQ.cjs');
27
+ var _chunkZEYQBA72cjs = require('../chunk-ZEYQBA72.cjs');
28
28
 
29
29
 
30
30
 
@@ -51,5 +51,5 @@ var _chunkTWYBLPRQcjs = require('../chunk-TWYBLPRQ.cjs');
51
51
 
52
52
 
53
53
 
54
- exports.AuthProvider = _chunkTWYBLPRQcjs.AuthProvider; exports.AzureProvider = _chunkTWYBLPRQcjs.AzureProvider; exports.ConsentManager = _chunkTWYBLPRQcjs.ConsentManager; exports.DEFAULT_ACCESS_TOKEN_TTL = _chunkTWYBLPRQcjs.DEFAULT_ACCESS_TOKEN_TTL; exports.DEFAULT_ACCESS_TOKEN_TTL_NO_REFRESH = _chunkTWYBLPRQcjs.DEFAULT_ACCESS_TOKEN_TTL_NO_REFRESH; exports.DEFAULT_AUTHORIZATION_CODE_TTL = _chunkTWYBLPRQcjs.DEFAULT_AUTHORIZATION_CODE_TTL; exports.DEFAULT_REFRESH_TOKEN_TTL = _chunkTWYBLPRQcjs.DEFAULT_REFRESH_TOKEN_TTL; exports.DEFAULT_TRANSACTION_TTL = _chunkTWYBLPRQcjs.DEFAULT_TRANSACTION_TTL; exports.DiskStore = _chunkTWYBLPRQcjs.DiskStore; exports.EncryptedTokenStorage = _chunkTWYBLPRQcjs.EncryptedTokenStorage; exports.GitHubProvider = _chunkTWYBLPRQcjs.GitHubProvider; exports.GoogleProvider = _chunkTWYBLPRQcjs.GoogleProvider; exports.JWKSVerifier = _chunkTWYBLPRQcjs.JWKSVerifier; exports.JWTIssuer = _chunkTWYBLPRQcjs.JWTIssuer; exports.MemoryTokenStorage = _chunkTWYBLPRQcjs.MemoryTokenStorage; exports.OAuthProvider = _chunkTWYBLPRQcjs.OAuthProvider; exports.OAuthProxy = _chunkTWYBLPRQcjs.OAuthProxy; exports.OAuthProxyError = _chunkTWYBLPRQcjs.OAuthProxyError; exports.PKCEUtils = _chunkTWYBLPRQcjs.PKCEUtils; exports.getAuthSession = _chunkTWYBLPRQcjs.getAuthSession; exports.requireAll = _chunkTWYBLPRQcjs.requireAll; exports.requireAny = _chunkTWYBLPRQcjs.requireAny; exports.requireAuth = _chunkTWYBLPRQcjs.requireAuth; exports.requireRole = _chunkTWYBLPRQcjs.requireRole; exports.requireScopes = _chunkTWYBLPRQcjs.requireScopes;
54
+ exports.AuthProvider = _chunkZEYQBA72cjs.AuthProvider; exports.AzureProvider = _chunkZEYQBA72cjs.AzureProvider; exports.ConsentManager = _chunkZEYQBA72cjs.ConsentManager; exports.DEFAULT_ACCESS_TOKEN_TTL = _chunkZEYQBA72cjs.DEFAULT_ACCESS_TOKEN_TTL; exports.DEFAULT_ACCESS_TOKEN_TTL_NO_REFRESH = _chunkZEYQBA72cjs.DEFAULT_ACCESS_TOKEN_TTL_NO_REFRESH; exports.DEFAULT_AUTHORIZATION_CODE_TTL = _chunkZEYQBA72cjs.DEFAULT_AUTHORIZATION_CODE_TTL; exports.DEFAULT_REFRESH_TOKEN_TTL = _chunkZEYQBA72cjs.DEFAULT_REFRESH_TOKEN_TTL; exports.DEFAULT_TRANSACTION_TTL = _chunkZEYQBA72cjs.DEFAULT_TRANSACTION_TTL; exports.DiskStore = _chunkZEYQBA72cjs.DiskStore; exports.EncryptedTokenStorage = _chunkZEYQBA72cjs.EncryptedTokenStorage; exports.GitHubProvider = _chunkZEYQBA72cjs.GitHubProvider; exports.GoogleProvider = _chunkZEYQBA72cjs.GoogleProvider; exports.JWKSVerifier = _chunkZEYQBA72cjs.JWKSVerifier; exports.JWTIssuer = _chunkZEYQBA72cjs.JWTIssuer; exports.MemoryTokenStorage = _chunkZEYQBA72cjs.MemoryTokenStorage; exports.OAuthProvider = _chunkZEYQBA72cjs.OAuthProvider; exports.OAuthProxy = _chunkZEYQBA72cjs.OAuthProxy; exports.OAuthProxyError = _chunkZEYQBA72cjs.OAuthProxyError; exports.PKCEUtils = _chunkZEYQBA72cjs.PKCEUtils; exports.getAuthSession = _chunkZEYQBA72cjs.getAuthSession; exports.requireAll = _chunkZEYQBA72cjs.requireAll; exports.requireAny = _chunkZEYQBA72cjs.requireAny; exports.requireAuth = _chunkZEYQBA72cjs.requireAuth; exports.requireRole = _chunkZEYQBA72cjs.requireRole; exports.requireScopes = _chunkZEYQBA72cjs.requireScopes;
55
55
  //# sourceMappingURL=index.cjs.map
@@ -1,5 +1,5 @@
1
- import { q as OAuthTransaction, C as ConsentData, T as TokenStorage, s as TokenVerifier, t as TokenVerificationResult, P as PKCEPair } from '../OAuthProvider-DNKBMBPU.cjs';
2
- export { A as AuthProvider, j as AuthProviderConfig, z as AuthorizationParams, b as AzureProvider, k as AzureProviderConfig, l as AzureSession, B as ClientCode, u as ClientIdMetadataOptions, E as CustomClaimsPassthroughConfig, F as DCRClientMetadata, H as DCRRequest, I as DCRResponse, D as DEFAULT_ACCESS_TOKEN_TTL, v as DEFAULT_ACCESS_TOKEN_TTL_NO_REFRESH, w as DEFAULT_AUTHORIZATION_CODE_TTL, x as DEFAULT_REFRESH_TOKEN_TTL, y as DEFAULT_TRANSACTION_TTL, m as GenericOAuthProviderConfig, G as GitHubProvider, n as GitHubSession, c as GoogleProvider, o as GoogleSession, J as OAuthError, d as OAuthProvider, K as OAuthProviderConfig, a as OAuthProxy, L as OAuthProxyConfig, p as OAuthProxyError, O as OAuthSession, M as ProxyDCRClient, R as RefreshRequest, S as SessionAuth, N as TokenMapping, Q as TokenRequest, U as TokenResponse, V as UpstreamTokenSet, g as getAuthSession, r as requireAll, e as requireAny, f as requireAuth, h as requireRole, i as requireScopes } from '../OAuthProvider-DNKBMBPU.cjs';
1
+ import { q as OAuthTransaction, C as ConsentData, T as TokenStorage, s as TokenVerifier, t as TokenVerificationResult, P as PKCEPair } from '../OAuthProvider-STkC4R2N.cjs';
2
+ export { A as AuthProvider, j as AuthProviderConfig, z as AuthorizationParams, b as AzureProvider, k as AzureProviderConfig, l as AzureSession, B as ClientCode, u as ClientIdMetadataOptions, E as CustomClaimsPassthroughConfig, F as DCRClientMetadata, H as DCRRequest, I as DCRResponse, D as DEFAULT_ACCESS_TOKEN_TTL, v as DEFAULT_ACCESS_TOKEN_TTL_NO_REFRESH, w as DEFAULT_AUTHORIZATION_CODE_TTL, x as DEFAULT_REFRESH_TOKEN_TTL, y as DEFAULT_TRANSACTION_TTL, m as GenericOAuthProviderConfig, G as GitHubProvider, n as GitHubSession, c as GoogleProvider, o as GoogleSession, J as OAuthError, d as OAuthProvider, K as OAuthProviderConfig, a as OAuthProxy, L as OAuthProxyConfig, p as OAuthProxyError, O as OAuthSession, M as ProxyDCRClient, R as RefreshRequest, S as SessionAuth, N as TokenMapping, Q as TokenRequest, U as TokenResponse, V as UpstreamTokenSet, g as getAuthSession, r as requireAll, e as requireAny, f as requireAuth, h as requireRole, i as requireScopes } from '../OAuthProvider-STkC4R2N.cjs';
3
3
 
4
4
  /**
5
5
  * Consent Management
@@ -14,8 +14,15 @@ declare class ConsentManager {
14
14
  constructor(signingKey: string);
15
15
  /**
16
16
  * Create HTTP response with consent screen
17
+ *
18
+ * `cookie` is a `Set-Cookie` value that ties the request to the browser the
19
+ * screen is shown to. The screen may not be framed: a page that embeds it
20
+ * could have the user approve without seeing what they are approving.
17
21
  */
18
- createConsentResponse(transaction: OAuthTransaction, provider: string): Response;
22
+ createConsentResponse(transaction: OAuthTransaction, provider: string, options?: {
23
+ clientName?: string;
24
+ cookie?: string;
25
+ }): Response;
19
26
  /**
20
27
  * Generate HTML for consent screen
21
28
  *
@@ -33,6 +40,13 @@ declare class ConsentManager {
33
40
  * Validate and parse consent cookie
34
41
  */
35
42
  validateConsentCookie(cookie: string): ConsentData | null;
43
+ /**
44
+ * Where a redirect URI leads, as the browser will read it rather than as it
45
+ * was typed: the parsed host, so that a look-alike character, a tab or a
46
+ * backslash shows for what it does. A long host keeps its end, which is the
47
+ * part that says whose it is.
48
+ */
49
+ private describeDestination;
36
50
  /**
37
51
  * Escape HTML to prevent XSS
38
52
  */
@@ -1,5 +1,5 @@
1
- import { q as OAuthTransaction, C as ConsentData, T as TokenStorage, s as TokenVerifier, t as TokenVerificationResult, P as PKCEPair } from '../OAuthProvider-DNKBMBPU.js';
2
- export { A as AuthProvider, j as AuthProviderConfig, z as AuthorizationParams, b as AzureProvider, k as AzureProviderConfig, l as AzureSession, B as ClientCode, u as ClientIdMetadataOptions, E as CustomClaimsPassthroughConfig, F as DCRClientMetadata, H as DCRRequest, I as DCRResponse, D as DEFAULT_ACCESS_TOKEN_TTL, v as DEFAULT_ACCESS_TOKEN_TTL_NO_REFRESH, w as DEFAULT_AUTHORIZATION_CODE_TTL, x as DEFAULT_REFRESH_TOKEN_TTL, y as DEFAULT_TRANSACTION_TTL, m as GenericOAuthProviderConfig, G as GitHubProvider, n as GitHubSession, c as GoogleProvider, o as GoogleSession, J as OAuthError, d as OAuthProvider, K as OAuthProviderConfig, a as OAuthProxy, L as OAuthProxyConfig, p as OAuthProxyError, O as OAuthSession, M as ProxyDCRClient, R as RefreshRequest, S as SessionAuth, N as TokenMapping, Q as TokenRequest, U as TokenResponse, V as UpstreamTokenSet, g as getAuthSession, r as requireAll, e as requireAny, f as requireAuth, h as requireRole, i as requireScopes } from '../OAuthProvider-DNKBMBPU.js';
1
+ import { q as OAuthTransaction, C as ConsentData, T as TokenStorage, s as TokenVerifier, t as TokenVerificationResult, P as PKCEPair } from '../OAuthProvider-STkC4R2N.js';
2
+ export { A as AuthProvider, j as AuthProviderConfig, z as AuthorizationParams, b as AzureProvider, k as AzureProviderConfig, l as AzureSession, B as ClientCode, u as ClientIdMetadataOptions, E as CustomClaimsPassthroughConfig, F as DCRClientMetadata, H as DCRRequest, I as DCRResponse, D as DEFAULT_ACCESS_TOKEN_TTL, v as DEFAULT_ACCESS_TOKEN_TTL_NO_REFRESH, w as DEFAULT_AUTHORIZATION_CODE_TTL, x as DEFAULT_REFRESH_TOKEN_TTL, y as DEFAULT_TRANSACTION_TTL, m as GenericOAuthProviderConfig, G as GitHubProvider, n as GitHubSession, c as GoogleProvider, o as GoogleSession, J as OAuthError, d as OAuthProvider, K as OAuthProviderConfig, a as OAuthProxy, L as OAuthProxyConfig, p as OAuthProxyError, O as OAuthSession, M as ProxyDCRClient, R as RefreshRequest, S as SessionAuth, N as TokenMapping, Q as TokenRequest, U as TokenResponse, V as UpstreamTokenSet, g as getAuthSession, r as requireAll, e as requireAny, f as requireAuth, h as requireRole, i as requireScopes } from '../OAuthProvider-STkC4R2N.js';
3
3
 
4
4
  /**
5
5
  * Consent Management
@@ -14,8 +14,15 @@ declare class ConsentManager {
14
14
  constructor(signingKey: string);
15
15
  /**
16
16
  * Create HTTP response with consent screen
17
+ *
18
+ * `cookie` is a `Set-Cookie` value that ties the request to the browser the
19
+ * screen is shown to. The screen may not be framed: a page that embeds it
20
+ * could have the user approve without seeing what they are approving.
17
21
  */
18
- createConsentResponse(transaction: OAuthTransaction, provider: string): Response;
22
+ createConsentResponse(transaction: OAuthTransaction, provider: string, options?: {
23
+ clientName?: string;
24
+ cookie?: string;
25
+ }): Response;
19
26
  /**
20
27
  * Generate HTML for consent screen
21
28
  *
@@ -33,6 +40,13 @@ declare class ConsentManager {
33
40
  * Validate and parse consent cookie
34
41
  */
35
42
  validateConsentCookie(cookie: string): ConsentData | null;
43
+ /**
44
+ * Where a redirect URI leads, as the browser will read it rather than as it
45
+ * was typed: the parsed host, so that a look-alike character, a tab or a
46
+ * backslash shows for what it does. A long host keeps its end, which is the
47
+ * part that says whose it is.
48
+ */
49
+ private describeDestination;
36
50
  /**
37
51
  * Escape HTML to prevent XSS
38
52
  */
@@ -24,7 +24,7 @@ import {
24
24
  requireAuth,
25
25
  requireRole,
26
26
  requireScopes
27
- } from "../chunk-PXH56Q3F.js";
27
+ } from "../chunk-4BX2CT5Z.js";
28
28
  export {
29
29
  AuthProvider,
30
30
  AzureProvider,
@@ -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
- return new Response(html, {
727
- headers: {
728
- "Content-Type": "text/html; charset=utf-8"
729
- },
730
- status: 200
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
  */
@@ -1511,7 +1550,6 @@ var OAuthProxy = class {
1511
1550
  constructor(config) {
1512
1551
  this.config = {
1513
1552
  authorizationCodeTtl: DEFAULT_AUTHORIZATION_CODE_TTL,
1514
- consentRequired: true,
1515
1553
  enableTokenSwap: true,
1516
1554
  // Enabled by default for security
1517
1555
  redirectPath: DEFAULT_REDIRECT_PATH,
@@ -1519,7 +1557,10 @@ var OAuthProxy = class {
1519
1557
  upstreamRequestTimeoutMs: DEFAULT_UPSTREAM_REQUEST_TIMEOUT_MS,
1520
1558
  upstreamTokenEndpointAuthMethod: "client_secret_basic",
1521
1559
  ...config,
1522
- baseUrl: withoutTrailingSlash(config.baseUrl)
1560
+ baseUrl: withoutTrailingSlash(config.baseUrl),
1561
+ // Spreading an explicit `undefined` over the default would turn consent
1562
+ // off for a caller that only meant to pass an option along.
1563
+ consentRequired: config.consentRequired ?? true
1523
1564
  };
1524
1565
  let storage = config.tokenStorage;
1525
1566
  if (!storage) {
@@ -1560,8 +1601,13 @@ var OAuthProxy = class {
1560
1601
  }
1561
1602
  /**
1562
1603
  * OAuth authorization endpoint
1604
+ *
1605
+ * With consent required the response is the consent screen, and it sets the
1606
+ * cookie that the request is approved and finished with: return its headers
1607
+ * to the browser. Pass that browser's `request` as well, so that one with
1608
+ * several authorization requests open keeps a single cookie for all of them.
1563
1609
  */
1564
- async authorize(params) {
1610
+ async authorize(params, request2) {
1565
1611
  if (!params.client_id || !params.redirect_uri || !params.response_type) {
1566
1612
  throw new OAuthProxyError(
1567
1613
  "invalid_request",
@@ -1613,11 +1659,17 @@ var OAuthProxy = class {
1613
1659
  );
1614
1660
  }
1615
1661
  }
1616
- const transaction = await this.createTransaction(params);
1617
- if (this.config.consentRequired && !transaction.consentGiven) {
1662
+ const consentBinding = this.config.consentRequired ? (request2 && this.consentCookieValue(request2)) ?? this.generateId() : void 0;
1663
+ const transaction = await this.createTransaction(params, consentBinding);
1664
+ if (consentBinding && !transaction.consentGiven) {
1665
+ const clientName = registeredClient.metadata?.client_name;
1618
1666
  return this.consentManager.createConsentResponse(
1619
1667
  transaction,
1620
- this.getProviderName()
1668
+ this.getProviderName(),
1669
+ {
1670
+ clientName: typeof clientName === "string" ? clientName : void 0,
1671
+ cookie: this.consentCookie(consentBinding)
1672
+ }
1621
1673
  );
1622
1674
  }
1623
1675
  return this.redirectToUpstream(transaction);
@@ -1801,6 +1853,12 @@ var OAuthProxy = class {
1801
1853
  if (!transaction) {
1802
1854
  throw new OAuthProxyError("invalid_request", "Invalid or expired state");
1803
1855
  }
1856
+ if (this.config.consentRequired && !(transaction.consentGiven && this.isConsentBoundTo(request2, transaction))) {
1857
+ throw new OAuthProxyError(
1858
+ "access_denied",
1859
+ "This authorization request was not approved in this browser"
1860
+ );
1861
+ }
1804
1862
  if (!await this.isTransactionCallbackRegistered(transaction)) {
1805
1863
  throw new OAuthProxyError(
1806
1864
  "invalid_request",
@@ -1850,6 +1908,12 @@ var OAuthProxy = class {
1850
1908
  "Invalid or expired transaction"
1851
1909
  );
1852
1910
  }
1911
+ if (!this.isConsentBoundTo(request2, transaction)) {
1912
+ throw new OAuthProxyError(
1913
+ "invalid_request",
1914
+ "Consent must be given in the browser that requested it"
1915
+ );
1916
+ }
1853
1917
  if (action === "deny") {
1854
1918
  await this.stateStore.deleteTransaction(transactionId);
1855
1919
  if (!await this.isTransactionCallbackRegistered(transaction)) {
@@ -2044,10 +2108,49 @@ var OAuthProxy = class {
2044
2108
  );
2045
2109
  });
2046
2110
  }
2111
+ /**
2112
+ * The cookie that ties consent requests to the browser they were shown to.
2113
+ * A browser holds one, shared by every request it has open, and it lasts as
2114
+ * long as a request does. `Lax` lets it travel with the provider's redirect
2115
+ * back to the callback, which is a cross-site navigation. Over HTTPS the
2116
+ * `__Host-` prefix keeps another host on the same site from setting it.
2117
+ */
2118
+ consentCookie(value) {
2119
+ return [
2120
+ `${this.consentCookieName()}=${value}`,
2121
+ "Path=/",
2122
+ `Max-Age=${this.config.transactionTtl || DEFAULT_TRANSACTION_TTL}`,
2123
+ "HttpOnly",
2124
+ "SameSite=Lax",
2125
+ ...this.isServedOverHttps() ? ["Secure"] : []
2126
+ ].join("; ");
2127
+ }
2128
+ consentCookieName() {
2129
+ return `${this.isServedOverHttps() ? "__Host-" : ""}vitemcp-consent`;
2130
+ }
2131
+ /**
2132
+ * The consent cookie `request` carries, if it carries a well-formed one.
2133
+ *
2134
+ * Only the spaces and tabs that may surround a cookie are dropped. Trimming
2135
+ * all white space would take a cookie whose name begins with, say, a
2136
+ * no-break space for this one, and a browser does not hold such a name to
2137
+ * the `__Host-` rules.
2138
+ */
2139
+ consentCookieValue(request2) {
2140
+ const name = this.consentCookieName();
2141
+ for (const pair of (request2.headers.get("cookie") ?? "").split(";")) {
2142
+ const separator = pair.indexOf("=");
2143
+ if (separator !== -1 && withoutOptionalWhitespace(pair.slice(0, separator)) === name) {
2144
+ const value = withoutOptionalWhitespace(pair.slice(separator + 1));
2145
+ return GENERATED_ID.test(value) ? value : void 0;
2146
+ }
2147
+ }
2148
+ return void 0;
2149
+ }
2047
2150
  /**
2048
2151
  * Create a new OAuth transaction
2049
2152
  */
2050
- async createTransaction(params) {
2153
+ async createTransaction(params, consentBinding) {
2051
2154
  const transactionId = this.generateId();
2052
2155
  const proxyPkce = PKCEUtils.generatePair("S256");
2053
2156
  const transaction = {
@@ -2055,6 +2158,7 @@ var OAuthProxy = class {
2055
2158
  clientCodeChallenge: params.code_challenge || "",
2056
2159
  clientCodeChallengeMethod: params.code_challenge_method || "plain",
2057
2160
  clientId: params.client_id,
2161
+ ...consentBinding && { consentBinding: sha256(consentBinding) },
2058
2162
  createdAt: /* @__PURE__ */ new Date(),
2059
2163
  expiresAt: new Date(
2060
2164
  Date.now() + (this.config.transactionTtl || 600) * 1e3
@@ -2425,6 +2529,21 @@ var OAuthProxy = class {
2425
2529
  throw error;
2426
2530
  }
2427
2531
  }
2532
+ /**
2533
+ * Whether `request` comes from the browser the transaction's consent screen
2534
+ * was shown to: it carries the cookie that screen set. A transaction that
2535
+ * never had a consent screen is bound to no browser.
2536
+ */
2537
+ isConsentBoundTo(request2, transaction) {
2538
+ const presented = this.consentCookieValue(request2);
2539
+ return Boolean(
2540
+ presented && transaction.consentBinding && secretsMatch(sha256(presented), transaction.consentBinding)
2541
+ );
2542
+ }
2543
+ /** Whether browsers reach this proxy over HTTPS, going by its `baseUrl`. */
2544
+ isServedOverHttps() {
2545
+ return /^https:/i.test(this.config.baseUrl);
2546
+ }
2428
2547
  /**
2429
2548
  * Issue swapped tokens (JWT pattern)
2430
2549
  * Issues short-lived ViteMCP JWTs and stores upstream tokens securely
@@ -3081,6 +3200,8 @@ var secretsMatch = (presented, expected) => timingSafeEqual4(
3081
3200
  createHash3("sha256").update(presented).digest(),
3082
3201
  createHash3("sha256").update(expected).digest()
3083
3202
  );
3203
+ var sha256 = (value) => createHash3("sha256").update(value).digest("base64url");
3204
+ var withoutOptionalWhitespace = (value) => value.replace(/^[ \t]+|[ \t]+$/g, "");
3084
3205
  var OAuthProxyError = class extends Error {
3085
3206
  constructor(code, description, statusCode = 400) {
3086
3207
  super(code);
@@ -3754,4 +3875,4 @@ export {
3754
3875
  DiskStore,
3755
3876
  JWKSVerifier
3756
3877
  };
3757
- //# sourceMappingURL=chunk-PXH56Q3F.js.map
3878
+ //# sourceMappingURL=chunk-4BX2CT5Z.js.map