fastmcp 4.0.1 → 4.0.2

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 CHANGED
@@ -2270,3 +2270,5 @@ Refer to this [issue](https://github.com/punkpeye/fastmcp/issues/25#issuecomment
2270
2270
  - FastMCP is inspired by the [Python implementation](https://github.com/jlowin/fastmcp) by [Jonathan Lowin](https://github.com/jlowin).
2271
2271
  - Parts of codebase were adopted from [LiteMCP](https://github.com/wong2/litemcp).
2272
2272
  - Parts of codebase were adopted from [Model Context protocolでSSEをやってみる](https://dev.classmethod.jp/articles/mcp-sse/).
2273
+
2274
+ This project is tested with BrowserStack.
package/dist/FastMCP.cjs CHANGED
@@ -20,7 +20,7 @@ var _chunkEXZZ3NKLcjs = require('./chunk-EXZZ3NKL.cjs');
20
20
 
21
21
 
22
22
 
23
- var _chunkSSVFQCSNcjs = require('./chunk-SSVFQCSN.cjs');
23
+ var _chunkOARN6YYKcjs = require('./chunk-OARN6YYK.cjs');
24
24
 
25
25
 
26
26
 
@@ -41,5 +41,5 @@ var _chunkSSVFQCSNcjs = require('./chunk-SSVFQCSN.cjs');
41
41
 
42
42
 
43
43
 
44
- exports.AuthProvider = _chunkSSVFQCSNcjs.AuthProvider; exports.AzureProvider = _chunkSSVFQCSNcjs.AzureProvider; exports.DiscoveryDocumentCache = _chunkEXZZ3NKLcjs.DiscoveryDocumentCache; exports.FastMCP = _chunkEXZZ3NKLcjs.FastMCP; exports.FastMCPSession = _chunkEXZZ3NKLcjs.FastMCPSession; exports.GitHubProvider = _chunkSSVFQCSNcjs.GitHubProvider; exports.GoogleProvider = _chunkSSVFQCSNcjs.GoogleProvider; exports.OAuthProvider = _chunkSSVFQCSNcjs.OAuthProvider; exports.ServerState = _chunkEXZZ3NKLcjs.ServerState; exports.UnexpectedStateError = _chunkEXZZ3NKLcjs.UnexpectedStateError; exports.UserError = _chunkEXZZ3NKLcjs.UserError; exports.audioContent = _chunkEXZZ3NKLcjs.audioContent; exports.getAuthSession = _chunkSSVFQCSNcjs.getAuthSession; exports.imageContent = _chunkEXZZ3NKLcjs.imageContent; exports.requireAll = _chunkSSVFQCSNcjs.requireAll; exports.requireAny = _chunkSSVFQCSNcjs.requireAny; exports.requireAuth = _chunkSSVFQCSNcjs.requireAuth; exports.requireRole = _chunkSSVFQCSNcjs.requireRole; exports.requireScopes = _chunkSSVFQCSNcjs.requireScopes;
44
+ exports.AuthProvider = _chunkOARN6YYKcjs.AuthProvider; exports.AzureProvider = _chunkOARN6YYKcjs.AzureProvider; exports.DiscoveryDocumentCache = _chunkEXZZ3NKLcjs.DiscoveryDocumentCache; exports.FastMCP = _chunkEXZZ3NKLcjs.FastMCP; exports.FastMCPSession = _chunkEXZZ3NKLcjs.FastMCPSession; exports.GitHubProvider = _chunkOARN6YYKcjs.GitHubProvider; exports.GoogleProvider = _chunkOARN6YYKcjs.GoogleProvider; exports.OAuthProvider = _chunkOARN6YYKcjs.OAuthProvider; exports.ServerState = _chunkEXZZ3NKLcjs.ServerState; exports.UnexpectedStateError = _chunkEXZZ3NKLcjs.UnexpectedStateError; exports.UserError = _chunkEXZZ3NKLcjs.UserError; exports.audioContent = _chunkEXZZ3NKLcjs.audioContent; exports.getAuthSession = _chunkOARN6YYKcjs.getAuthSession; exports.imageContent = _chunkEXZZ3NKLcjs.imageContent; exports.requireAll = _chunkOARN6YYKcjs.requireAll; exports.requireAny = _chunkOARN6YYKcjs.requireAny; exports.requireAuth = _chunkOARN6YYKcjs.requireAuth; exports.requireRole = _chunkOARN6YYKcjs.requireRole; exports.requireScopes = _chunkOARN6YYKcjs.requireScopes;
45
45
  //# sourceMappingURL=FastMCP.cjs.map
@@ -10,8 +10,8 @@ import { Hono } from 'hono';
10
10
  import http from 'http';
11
11
  import { StrictEventEmitter } from 'strict-event-emitter-types';
12
12
  import { z } from 'zod';
13
- import { A as AuthProvider, O as OAuthSession, a as OAuthProxy } from './OAuthProvider-BV6EpF_k.cjs';
14
- 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, g as getAuthSession, r as requireAll, e as requireAny, f as requireAuth, h as requireRole, i as requireScopes } from './OAuthProvider-BV6EpF_k.cjs';
13
+ import { A as AuthProvider, O as OAuthSession, a as OAuthProxy } from './OAuthProvider-BS7O-cik.cjs';
14
+ 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, g as getAuthSession, r as requireAll, e as requireAny, f as requireAuth, h as requireRole, i as requireScopes } from './OAuthProvider-BS7O-cik.cjs';
15
15
  import 'node:http';
16
16
 
17
17
  declare class DiscoveryDocumentCache {
package/dist/FastMCP.d.ts CHANGED
@@ -10,8 +10,8 @@ import { Hono } from 'hono';
10
10
  import http from 'http';
11
11
  import { StrictEventEmitter } from 'strict-event-emitter-types';
12
12
  import { z } from 'zod';
13
- import { A as AuthProvider, O as OAuthSession, a as OAuthProxy } from './OAuthProvider-BV6EpF_k.js';
14
- 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, g as getAuthSession, r as requireAll, e as requireAny, f as requireAuth, h as requireRole, i as requireScopes } from './OAuthProvider-BV6EpF_k.js';
13
+ import { A as AuthProvider, O as OAuthSession, a as OAuthProxy } from './OAuthProvider-BS7O-cik.js';
14
+ 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, g as getAuthSession, r as requireAll, e as requireAny, f as requireAuth, h as requireRole, i as requireScopes } from './OAuthProvider-BS7O-cik.js';
15
15
  import 'node:http';
16
16
 
17
17
  declare class DiscoveryDocumentCache {
package/dist/FastMCP.js CHANGED
@@ -20,7 +20,7 @@ import {
20
20
  requireAuth,
21
21
  requireRole,
22
22
  requireScopes
23
- } from "./chunk-UN72PIH2.js";
23
+ } from "./chunk-HGUUOYR4.js";
24
24
  export {
25
25
  AuthProvider,
26
26
  AzureProvider,
@@ -192,15 +192,17 @@ interface OAuthProxyConfig {
192
192
  * matches one of these patterns (exact string or glob with `*` / `?`);
193
193
  * otherwise the registration is rejected with `invalid_redirect_uri`. Once
194
194
  * registered, the same exact URI must be echoed back at /oauth/authorize —
195
- * the proxy performs exact string comparison per RFC 6749 §3.1.2.3.
195
+ * the proxy performs an exact per-client match per RFC 6749 §3.1.2.3.
196
196
  *
197
- * Default: `[]` (DCR rejects everything — explicit opt-in required).
197
+ * Behaviour by value:
198
+ * - `undefined` (default): allow `http://localhost:*` and `http://127.0.0.1:*`
199
+ * only. Covers the standard MCP use-case of dynamic loopback ports.
200
+ * - `[]` (empty array): DCR rejects every URI — use for deployments that
201
+ * configure patterns explicitly and want no implicit fallback.
202
+ * - `["pattern", ...]`: accept URIs matching any glob pattern in the list.
198
203
  *
199
- * Prior versions defaulted to `["https://*", "http://localhost:*"]` with an
200
- * implicit fallback that allowed any https URL. This enabled CWE-601
201
- * open-redirect / authorization-code theft: an attacker could DCR their own
202
- * URL and then steal victim codes via /oauth/authorize. Do not loosen this
203
- * default without understanding that threat model.
204
+ * Do not widen the default beyond loopback addresses — allowing arbitrary
205
+ * https URLs enables CWE-601 open-redirect / authorization-code theft.
204
206
  */
205
207
  allowedRedirectUriPatterns?: string[];
206
208
  /** Authorization code TTL in seconds (default: 300) */
@@ -293,14 +295,16 @@ interface PKCEPair {
293
295
  * Dynamic client registration data
294
296
  */
295
297
  interface ProxyDCRClient {
296
- /** Registered callback URL */
298
+ /** Primary (first) registered callback URL */
297
299
  callbackUrl: string;
298
- /** Generated or assigned client ID */
300
+ /** Proxy-issued client ID (not the upstream provider's client_id) */
299
301
  clientId: string;
300
- /** Client secret (optional) */
302
+ /** Proxy-issued client secret (not the upstream provider's client_secret) */
301
303
  clientSecret?: string;
302
304
  /** Client metadata from registration request */
303
305
  metadata?: DCRClientMetadata;
306
+ /** All redirect URIs registered by this client */
307
+ redirectUris: string[];
304
308
  /** Client registration timestamp */
305
309
  registeredAt: Date;
306
310
  }
@@ -419,7 +423,10 @@ declare class OAuthProxy {
419
423
  private config;
420
424
  private consentManager;
421
425
  private jwtIssuer?;
426
+ /** Keyed by redirect_uri for defence-in-depth checks in handleCallback/handleConsent */
422
427
  private registeredClients;
428
+ /** Keyed by proxy-issued client_id for authorize/token-exchange lookups */
429
+ private registeredClientsByClientId;
423
430
  private tokenStorage;
424
431
  private transactions;
425
432
  constructor(config: OAuthProxyConfig);
@@ -566,14 +573,17 @@ declare class OAuthProxy {
566
573
  /**
567
574
  * Validate a redirect URI against the configured allow-list.
568
575
  *
569
- * Returns `true` only if the URI is syntactically valid AND matches one of
570
- * the explicitly configured `allowedRedirectUriPatterns`. An empty or unset
571
- * pattern list means DCR will reject every URI framework users must
572
- * opt-in by listing the exact URIs (or wildcards) they trust.
576
+ * Behaviour by configuration value:
577
+ * - `undefined` (not set): allow localhost/127.0.0.1 only safe default
578
+ * that covers the common MCP use-case of dynamic loopback ports without
579
+ * opening the proxy to arbitrary redirect URIs.
580
+ * - `[]` (empty array): reject every URI — opt-in strict mode for deployments
581
+ * that want full control and will configure patterns explicitly.
582
+ * - `["pattern", ...]`: accept URIs matching any of the glob patterns.
573
583
  *
574
- * Prior versions also fell back to allowing any https URL or localhost,
575
- * which enabled attackers to DCR an arbitrary URL and then abuse it via
576
- * /oauth/authorize (CWE-601). Do not re-introduce that fallback.
584
+ * Prior versions defaulted to `["https://*", "http://localhost:*"]` which
585
+ * matched any https URL, enabling CWE-601 open-redirect / authorization-code
586
+ * theft. Do not loosen the default beyond loopback addresses.
577
587
  */
578
588
  private validateRedirectUri;
579
589
  }
@@ -192,15 +192,17 @@ interface OAuthProxyConfig {
192
192
  * matches one of these patterns (exact string or glob with `*` / `?`);
193
193
  * otherwise the registration is rejected with `invalid_redirect_uri`. Once
194
194
  * registered, the same exact URI must be echoed back at /oauth/authorize —
195
- * the proxy performs exact string comparison per RFC 6749 §3.1.2.3.
195
+ * the proxy performs an exact per-client match per RFC 6749 §3.1.2.3.
196
196
  *
197
- * Default: `[]` (DCR rejects everything — explicit opt-in required).
197
+ * Behaviour by value:
198
+ * - `undefined` (default): allow `http://localhost:*` and `http://127.0.0.1:*`
199
+ * only. Covers the standard MCP use-case of dynamic loopback ports.
200
+ * - `[]` (empty array): DCR rejects every URI — use for deployments that
201
+ * configure patterns explicitly and want no implicit fallback.
202
+ * - `["pattern", ...]`: accept URIs matching any glob pattern in the list.
198
203
  *
199
- * Prior versions defaulted to `["https://*", "http://localhost:*"]` with an
200
- * implicit fallback that allowed any https URL. This enabled CWE-601
201
- * open-redirect / authorization-code theft: an attacker could DCR their own
202
- * URL and then steal victim codes via /oauth/authorize. Do not loosen this
203
- * default without understanding that threat model.
204
+ * Do not widen the default beyond loopback addresses — allowing arbitrary
205
+ * https URLs enables CWE-601 open-redirect / authorization-code theft.
204
206
  */
205
207
  allowedRedirectUriPatterns?: string[];
206
208
  /** Authorization code TTL in seconds (default: 300) */
@@ -293,14 +295,16 @@ interface PKCEPair {
293
295
  * Dynamic client registration data
294
296
  */
295
297
  interface ProxyDCRClient {
296
- /** Registered callback URL */
298
+ /** Primary (first) registered callback URL */
297
299
  callbackUrl: string;
298
- /** Generated or assigned client ID */
300
+ /** Proxy-issued client ID (not the upstream provider's client_id) */
299
301
  clientId: string;
300
- /** Client secret (optional) */
302
+ /** Proxy-issued client secret (not the upstream provider's client_secret) */
301
303
  clientSecret?: string;
302
304
  /** Client metadata from registration request */
303
305
  metadata?: DCRClientMetadata;
306
+ /** All redirect URIs registered by this client */
307
+ redirectUris: string[];
304
308
  /** Client registration timestamp */
305
309
  registeredAt: Date;
306
310
  }
@@ -419,7 +423,10 @@ declare class OAuthProxy {
419
423
  private config;
420
424
  private consentManager;
421
425
  private jwtIssuer?;
426
+ /** Keyed by redirect_uri for defence-in-depth checks in handleCallback/handleConsent */
422
427
  private registeredClients;
428
+ /** Keyed by proxy-issued client_id for authorize/token-exchange lookups */
429
+ private registeredClientsByClientId;
423
430
  private tokenStorage;
424
431
  private transactions;
425
432
  constructor(config: OAuthProxyConfig);
@@ -566,14 +573,17 @@ declare class OAuthProxy {
566
573
  /**
567
574
  * Validate a redirect URI against the configured allow-list.
568
575
  *
569
- * Returns `true` only if the URI is syntactically valid AND matches one of
570
- * the explicitly configured `allowedRedirectUriPatterns`. An empty or unset
571
- * pattern list means DCR will reject every URI framework users must
572
- * opt-in by listing the exact URIs (or wildcards) they trust.
576
+ * Behaviour by configuration value:
577
+ * - `undefined` (not set): allow localhost/127.0.0.1 only safe default
578
+ * that covers the common MCP use-case of dynamic loopback ports without
579
+ * opening the proxy to arbitrary redirect URIs.
580
+ * - `[]` (empty array): reject every URI — opt-in strict mode for deployments
581
+ * that want full control and will configure patterns explicitly.
582
+ * - `["pattern", ...]`: accept URIs matching any of the glob patterns.
573
583
  *
574
- * Prior versions also fell back to allowing any https URL or localhost,
575
- * which enabled attackers to DCR an arbitrary URL and then abuse it via
576
- * /oauth/authorize (CWE-601). Do not re-introduce that fallback.
584
+ * Prior versions defaulted to `["https://*", "http://localhost:*"]` which
585
+ * matched any https URL, enabling CWE-601 open-redirect / authorization-code
586
+ * theft. Do not loosen the default beyond loopback addresses.
577
587
  */
578
588
  private validateRedirectUri;
579
589
  }
@@ -24,7 +24,7 @@
24
24
 
25
25
 
26
26
 
27
- var _chunkSSVFQCSNcjs = require('../chunk-SSVFQCSN.cjs');
27
+ var _chunkOARN6YYKcjs = require('../chunk-OARN6YYK.cjs');
28
28
 
29
29
 
30
30
 
@@ -51,5 +51,5 @@ var _chunkSSVFQCSNcjs = require('../chunk-SSVFQCSN.cjs');
51
51
 
52
52
 
53
53
 
54
- exports.AuthProvider = _chunkSSVFQCSNcjs.AuthProvider; exports.AzureProvider = _chunkSSVFQCSNcjs.AzureProvider; exports.ConsentManager = _chunkSSVFQCSNcjs.ConsentManager; exports.DEFAULT_ACCESS_TOKEN_TTL = _chunkSSVFQCSNcjs.DEFAULT_ACCESS_TOKEN_TTL; exports.DEFAULT_ACCESS_TOKEN_TTL_NO_REFRESH = _chunkSSVFQCSNcjs.DEFAULT_ACCESS_TOKEN_TTL_NO_REFRESH; exports.DEFAULT_AUTHORIZATION_CODE_TTL = _chunkSSVFQCSNcjs.DEFAULT_AUTHORIZATION_CODE_TTL; exports.DEFAULT_REFRESH_TOKEN_TTL = _chunkSSVFQCSNcjs.DEFAULT_REFRESH_TOKEN_TTL; exports.DEFAULT_TRANSACTION_TTL = _chunkSSVFQCSNcjs.DEFAULT_TRANSACTION_TTL; exports.DiskStore = _chunkSSVFQCSNcjs.DiskStore; exports.EncryptedTokenStorage = _chunkSSVFQCSNcjs.EncryptedTokenStorage; exports.GitHubProvider = _chunkSSVFQCSNcjs.GitHubProvider; exports.GoogleProvider = _chunkSSVFQCSNcjs.GoogleProvider; exports.JWKSVerifier = _chunkSSVFQCSNcjs.JWKSVerifier; exports.JWTIssuer = _chunkSSVFQCSNcjs.JWTIssuer; exports.MemoryTokenStorage = _chunkSSVFQCSNcjs.MemoryTokenStorage; exports.OAuthProvider = _chunkSSVFQCSNcjs.OAuthProvider; exports.OAuthProxy = _chunkSSVFQCSNcjs.OAuthProxy; exports.OAuthProxyError = _chunkSSVFQCSNcjs.OAuthProxyError; exports.PKCEUtils = _chunkSSVFQCSNcjs.PKCEUtils; exports.getAuthSession = _chunkSSVFQCSNcjs.getAuthSession; exports.requireAll = _chunkSSVFQCSNcjs.requireAll; exports.requireAny = _chunkSSVFQCSNcjs.requireAny; exports.requireAuth = _chunkSSVFQCSNcjs.requireAuth; exports.requireRole = _chunkSSVFQCSNcjs.requireRole; exports.requireScopes = _chunkSSVFQCSNcjs.requireScopes;
54
+ exports.AuthProvider = _chunkOARN6YYKcjs.AuthProvider; exports.AzureProvider = _chunkOARN6YYKcjs.AzureProvider; exports.ConsentManager = _chunkOARN6YYKcjs.ConsentManager; exports.DEFAULT_ACCESS_TOKEN_TTL = _chunkOARN6YYKcjs.DEFAULT_ACCESS_TOKEN_TTL; exports.DEFAULT_ACCESS_TOKEN_TTL_NO_REFRESH = _chunkOARN6YYKcjs.DEFAULT_ACCESS_TOKEN_TTL_NO_REFRESH; exports.DEFAULT_AUTHORIZATION_CODE_TTL = _chunkOARN6YYKcjs.DEFAULT_AUTHORIZATION_CODE_TTL; exports.DEFAULT_REFRESH_TOKEN_TTL = _chunkOARN6YYKcjs.DEFAULT_REFRESH_TOKEN_TTL; exports.DEFAULT_TRANSACTION_TTL = _chunkOARN6YYKcjs.DEFAULT_TRANSACTION_TTL; exports.DiskStore = _chunkOARN6YYKcjs.DiskStore; exports.EncryptedTokenStorage = _chunkOARN6YYKcjs.EncryptedTokenStorage; exports.GitHubProvider = _chunkOARN6YYKcjs.GitHubProvider; exports.GoogleProvider = _chunkOARN6YYKcjs.GoogleProvider; exports.JWKSVerifier = _chunkOARN6YYKcjs.JWKSVerifier; exports.JWTIssuer = _chunkOARN6YYKcjs.JWTIssuer; exports.MemoryTokenStorage = _chunkOARN6YYKcjs.MemoryTokenStorage; exports.OAuthProvider = _chunkOARN6YYKcjs.OAuthProvider; exports.OAuthProxy = _chunkOARN6YYKcjs.OAuthProxy; exports.OAuthProxyError = _chunkOARN6YYKcjs.OAuthProxyError; exports.PKCEUtils = _chunkOARN6YYKcjs.PKCEUtils; exports.getAuthSession = _chunkOARN6YYKcjs.getAuthSession; exports.requireAll = _chunkOARN6YYKcjs.requireAll; exports.requireAny = _chunkOARN6YYKcjs.requireAny; exports.requireAuth = _chunkOARN6YYKcjs.requireAuth; exports.requireRole = _chunkOARN6YYKcjs.requireRole; exports.requireScopes = _chunkOARN6YYKcjs.requireScopes;
55
55
  //# sourceMappingURL=index.cjs.map
@@ -1,5 +1,5 @@
1
- import { p as OAuthTransaction, C as ConsentData, T as TokenStorage, q as TokenVerifier, s as TokenVerificationResult, P as PKCEPair } from '../OAuthProvider-BV6EpF_k.cjs';
2
- export { A as AuthProvider, j as AuthProviderConfig, y as AuthorizationParams, b as AzureProvider, k as AzureProviderConfig, l as AzureSession, z as ClientCode, B as DCRClientMetadata, E as DCRRequest, F as DCRResponse, D as DEFAULT_ACCESS_TOKEN_TTL, u as DEFAULT_ACCESS_TOKEN_TTL_NO_REFRESH, v as DEFAULT_AUTHORIZATION_CODE_TTL, w as DEFAULT_REFRESH_TOKEN_TTL, x as DEFAULT_TRANSACTION_TTL, m as GenericOAuthProviderConfig, G as GitHubProvider, n as GitHubSession, c as GoogleProvider, o as GoogleSession, H as OAuthError, d as OAuthProvider, I as OAuthProviderConfig, a as OAuthProxy, J as OAuthProxyConfig, t as OAuthProxyError, O as OAuthSession, K as ProxyDCRClient, R as RefreshRequest, L as TokenMapping, M as TokenRequest, N as TokenResponse, U as UpstreamTokenSet, g as getAuthSession, r as requireAll, e as requireAny, f as requireAuth, h as requireRole, i as requireScopes } from '../OAuthProvider-BV6EpF_k.cjs';
1
+ import { p as OAuthTransaction, C as ConsentData, T as TokenStorage, q as TokenVerifier, s as TokenVerificationResult, P as PKCEPair } from '../OAuthProvider-BS7O-cik.cjs';
2
+ export { A as AuthProvider, j as AuthProviderConfig, y as AuthorizationParams, b as AzureProvider, k as AzureProviderConfig, l as AzureSession, z as ClientCode, B as DCRClientMetadata, E as DCRRequest, F as DCRResponse, D as DEFAULT_ACCESS_TOKEN_TTL, u as DEFAULT_ACCESS_TOKEN_TTL_NO_REFRESH, v as DEFAULT_AUTHORIZATION_CODE_TTL, w as DEFAULT_REFRESH_TOKEN_TTL, x as DEFAULT_TRANSACTION_TTL, m as GenericOAuthProviderConfig, G as GitHubProvider, n as GitHubSession, c as GoogleProvider, o as GoogleSession, H as OAuthError, d as OAuthProvider, I as OAuthProviderConfig, a as OAuthProxy, J as OAuthProxyConfig, t as OAuthProxyError, O as OAuthSession, K as ProxyDCRClient, R as RefreshRequest, L as TokenMapping, M as TokenRequest, N as TokenResponse, U as UpstreamTokenSet, g as getAuthSession, r as requireAll, e as requireAny, f as requireAuth, h as requireRole, i as requireScopes } from '../OAuthProvider-BS7O-cik.cjs';
3
3
  import 'node:http';
4
4
 
5
5
  /**
@@ -1,5 +1,5 @@
1
- import { p as OAuthTransaction, C as ConsentData, T as TokenStorage, q as TokenVerifier, s as TokenVerificationResult, P as PKCEPair } from '../OAuthProvider-BV6EpF_k.js';
2
- export { A as AuthProvider, j as AuthProviderConfig, y as AuthorizationParams, b as AzureProvider, k as AzureProviderConfig, l as AzureSession, z as ClientCode, B as DCRClientMetadata, E as DCRRequest, F as DCRResponse, D as DEFAULT_ACCESS_TOKEN_TTL, u as DEFAULT_ACCESS_TOKEN_TTL_NO_REFRESH, v as DEFAULT_AUTHORIZATION_CODE_TTL, w as DEFAULT_REFRESH_TOKEN_TTL, x as DEFAULT_TRANSACTION_TTL, m as GenericOAuthProviderConfig, G as GitHubProvider, n as GitHubSession, c as GoogleProvider, o as GoogleSession, H as OAuthError, d as OAuthProvider, I as OAuthProviderConfig, a as OAuthProxy, J as OAuthProxyConfig, t as OAuthProxyError, O as OAuthSession, K as ProxyDCRClient, R as RefreshRequest, L as TokenMapping, M as TokenRequest, N as TokenResponse, U as UpstreamTokenSet, g as getAuthSession, r as requireAll, e as requireAny, f as requireAuth, h as requireRole, i as requireScopes } from '../OAuthProvider-BV6EpF_k.js';
1
+ import { p as OAuthTransaction, C as ConsentData, T as TokenStorage, q as TokenVerifier, s as TokenVerificationResult, P as PKCEPair } from '../OAuthProvider-BS7O-cik.js';
2
+ export { A as AuthProvider, j as AuthProviderConfig, y as AuthorizationParams, b as AzureProvider, k as AzureProviderConfig, l as AzureSession, z as ClientCode, B as DCRClientMetadata, E as DCRRequest, F as DCRResponse, D as DEFAULT_ACCESS_TOKEN_TTL, u as DEFAULT_ACCESS_TOKEN_TTL_NO_REFRESH, v as DEFAULT_AUTHORIZATION_CODE_TTL, w as DEFAULT_REFRESH_TOKEN_TTL, x as DEFAULT_TRANSACTION_TTL, m as GenericOAuthProviderConfig, G as GitHubProvider, n as GitHubSession, c as GoogleProvider, o as GoogleSession, H as OAuthError, d as OAuthProvider, I as OAuthProviderConfig, a as OAuthProxy, J as OAuthProxyConfig, t as OAuthProxyError, O as OAuthSession, K as ProxyDCRClient, R as RefreshRequest, L as TokenMapping, M as TokenRequest, N as TokenResponse, U as UpstreamTokenSet, g as getAuthSession, r as requireAll, e as requireAny, f as requireAuth, h as requireRole, i as requireScopes } from '../OAuthProvider-BS7O-cik.js';
3
3
  import 'node:http';
4
4
 
5
5
  /**
@@ -24,7 +24,7 @@ import {
24
24
  requireAuth,
25
25
  requireRole,
26
26
  requireScopes
27
- } from "../chunk-UN72PIH2.js";
27
+ } from "../chunk-HGUUOYR4.js";
28
28
  export {
29
29
  AuthProvider,
30
30
  AzureProvider,
@@ -858,16 +858,14 @@ var OAuthProxy = class {
858
858
  config;
859
859
  consentManager;
860
860
  jwtIssuer;
861
+ /** Keyed by redirect_uri for defence-in-depth checks in handleCallback/handleConsent */
861
862
  registeredClients = /* @__PURE__ */ new Map();
863
+ /** Keyed by proxy-issued client_id for authorize/token-exchange lookups */
864
+ registeredClientsByClientId = /* @__PURE__ */ new Map();
862
865
  tokenStorage;
863
866
  transactions = /* @__PURE__ */ new Map();
864
867
  constructor(config) {
865
868
  this.config = {
866
- // Empty by default. Framework users must explicitly configure the URIs they
867
- // trust, per RFC 6819 §4.1.5. The previous default (`["https://*", "http://localhost:*"]`)
868
- // allowed open DCR registration of any https URL, enabling CWE-601 open-redirect
869
- // attacks against /oauth/authorize.
870
- allowedRedirectUriPatterns: [],
871
869
  authorizationCodeTtl: DEFAULT_AUTHORIZATION_CODE_TTL,
872
870
  consentRequired: true,
873
871
  enableTokenSwap: true,
@@ -917,10 +915,13 @@ var OAuthProxy = class {
917
915
  "Only 'code' response type is supported"
918
916
  );
919
917
  }
920
- if (params.client_id !== this.config.upstreamClientId) {
918
+ const registeredClient = this.registeredClientsByClientId.get(
919
+ params.client_id
920
+ );
921
+ if (!registeredClient) {
921
922
  throw new OAuthProxyError("invalid_client", "Unknown client_id");
922
923
  }
923
- if (!this.registeredClients.has(params.redirect_uri)) {
924
+ if (!registeredClient.redirectUris.includes(params.redirect_uri)) {
924
925
  throw new OAuthProxyError(
925
926
  "invalid_request",
926
927
  "redirect_uri is not registered for this client"
@@ -952,6 +953,7 @@ var OAuthProxy = class {
952
953
  this.transactions.clear();
953
954
  this.clientCodes.clear();
954
955
  this.registeredClients.clear();
956
+ this.registeredClientsByClientId.clear();
955
957
  }
956
958
  /**
957
959
  * Token endpoint - exchange authorization code for tokens
@@ -963,7 +965,7 @@ var OAuthProxy = class {
963
965
  "Only authorization_code grant type is supported"
964
966
  );
965
967
  }
966
- if (request.client_id !== this.config.upstreamClientId) {
968
+ if (!this.registeredClientsByClientId.has(request.client_id)) {
967
969
  throw new OAuthProxyError("invalid_client", "Unknown client_id");
968
970
  }
969
971
  const clientCode = this.clientCodes.get(request.code);
@@ -1185,11 +1187,12 @@ var OAuthProxy = class {
1185
1187
  );
1186
1188
  }
1187
1189
  }
1188
- const clientId = this.config.upstreamClientId;
1190
+ const proxyClientId = randomBytes4(16).toString("hex");
1191
+ const proxyClientSecret = randomBytes4(32).toString("base64url");
1189
1192
  const client = {
1190
1193
  callbackUrl: request.redirect_uris[0],
1191
- clientId,
1192
- clientSecret: this.config.upstreamClientSecret,
1194
+ clientId: proxyClientId,
1195
+ clientSecret: proxyClientSecret,
1193
1196
  metadata: {
1194
1197
  client_name: request.client_name,
1195
1198
  client_uri: request.client_uri,
@@ -1203,17 +1206,19 @@ var OAuthProxy = class {
1203
1206
  software_version: request.software_version,
1204
1207
  tos_uri: request.tos_uri
1205
1208
  },
1209
+ redirectUris: request.redirect_uris,
1206
1210
  registeredAt: /* @__PURE__ */ new Date()
1207
1211
  };
1212
+ this.registeredClientsByClientId.set(proxyClientId, client);
1208
1213
  for (const uri of request.redirect_uris) {
1209
1214
  this.registeredClients.set(uri, client);
1210
1215
  }
1211
1216
  const response = {
1212
- client_id: clientId,
1217
+ client_id: proxyClientId,
1213
1218
  client_id_issued_at: Math.floor(Date.now() / 1e3),
1214
1219
  // Echo back optional metadata
1215
1220
  client_name: request.client_name,
1216
- client_secret: this.config.upstreamClientSecret,
1221
+ client_secret: proxyClientSecret,
1217
1222
  client_secret_expires_at: 0,
1218
1223
  // Never expires
1219
1224
  client_uri: request.client_uri,
@@ -1812,14 +1817,17 @@ var OAuthProxy = class {
1812
1817
  /**
1813
1818
  * Validate a redirect URI against the configured allow-list.
1814
1819
  *
1815
- * Returns `true` only if the URI is syntactically valid AND matches one of
1816
- * the explicitly configured `allowedRedirectUriPatterns`. An empty or unset
1817
- * pattern list means DCR will reject every URI framework users must
1818
- * opt-in by listing the exact URIs (or wildcards) they trust.
1820
+ * Behaviour by configuration value:
1821
+ * - `undefined` (not set): allow localhost/127.0.0.1 only safe default
1822
+ * that covers the common MCP use-case of dynamic loopback ports without
1823
+ * opening the proxy to arbitrary redirect URIs.
1824
+ * - `[]` (empty array): reject every URI — opt-in strict mode for deployments
1825
+ * that want full control and will configure patterns explicitly.
1826
+ * - `["pattern", ...]`: accept URIs matching any of the glob patterns.
1819
1827
  *
1820
- * Prior versions also fell back to allowing any https URL or localhost,
1821
- * which enabled attackers to DCR an arbitrary URL and then abuse it via
1822
- * /oauth/authorize (CWE-601). Do not re-introduce that fallback.
1828
+ * Prior versions defaulted to `["https://*", "http://localhost:*"]` which
1829
+ * matched any https URL, enabling CWE-601 open-redirect / authorization-code
1830
+ * theft. Do not loosen the default beyond loopback addresses.
1823
1831
  */
1824
1832
  validateRedirectUri(uri) {
1825
1833
  try {
@@ -1827,11 +1835,17 @@ var OAuthProxy = class {
1827
1835
  } catch {
1828
1836
  return false;
1829
1837
  }
1830
- const patterns = this.config.allowedRedirectUriPatterns || [];
1831
- if (patterns.length === 0) {
1838
+ const patterns = this.config.allowedRedirectUriPatterns;
1839
+ if (Array.isArray(patterns) && patterns.length === 0) {
1832
1840
  return false;
1833
1841
  }
1834
- return patterns.some((pattern) => this.matchesPattern(uri, pattern));
1842
+ const effectivePatterns = patterns ?? [
1843
+ "http://localhost:*",
1844
+ "http://127.0.0.1:*"
1845
+ ];
1846
+ return effectivePatterns.some(
1847
+ (pattern) => this.matchesPattern(uri, pattern)
1848
+ );
1835
1849
  }
1836
1850
  };
1837
1851
  var OAuthProxyError = class extends Error {
@@ -2378,4 +2392,4 @@ export {
2378
2392
  DiskStore,
2379
2393
  JWKSVerifier
2380
2394
  };
2381
- //# sourceMappingURL=chunk-UN72PIH2.js.map
2395
+ //# sourceMappingURL=chunk-HGUUOYR4.js.map