@vitemcp/server 1.6.2 → 1.6.4

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.
@@ -665,19 +665,29 @@ declare class OAuthProxy {
665
665
  */
666
666
  private issueSwappedTokensForRefresh;
667
667
  /**
668
- * Match a URI against an allow-list glob: `*` spans any run of characters,
669
- * `?` exactly one, and everything else is literal.
668
+ * Match a parsed URI against an allow-list pattern, one URI component at a
669
+ * time: scheme, host, port, then everything from the path onwards. A `*`
670
+ * therefore stops where its component stops.
670
671
  *
671
- * "Everything else is literal" is the security-relevant half. Left unescaped,
672
- * a `.` reaches the RegExp as "any character", so the pattern an operator
673
- * wrote for one host — `https://client.example.com/*` — also admits
674
- * `https://clientXexampleYcom/steal`, a name an attacker can register. DCR
675
- * would accept it and `handleCallback()` would later 302 a fresh
676
- * authorization code to it, reopening the CWE-601 path this allow-list
677
- * exists to close. `+ ^ $ ( ) [ ] { } |` widen a pattern the same way.
672
+ * That containment is the whole point. Matching the pattern against the raw
673
+ * string let a wildcard run straight through the delimiters that decide
674
+ * where the browser actually navigates:
678
675
  *
679
- * Escaping and wildcard expansion happen in one pass, so a backslash this
680
- * inserts can never be re-read as the metacharacter of a later pass.
676
+ * - `http://localhost:*` matched `http://localhost:@evil.com/cb`, where
677
+ * `localhost:` is userinfo and the real host is `evil.com`.
678
+ * - `https://*.example.com/*` matched
679
+ * `https://evil.com/a.example.com/cb`, because the wildcard covered
680
+ * `evil.com/a` — authority and path at once.
681
+ *
682
+ * Both register cleanly under the old matcher, and `handleCallback()` would
683
+ * then 302 a fresh authorization code to the attacker's host: the CWE-601
684
+ * theft path this allow-list exists to close. Comparing against `URL`'s
685
+ * parse makes the delimiters structural rather than incidental, so no
686
+ * pattern can span them however it is written.
687
+ *
688
+ * A pattern that omits the path (`http://localhost:*`, the loopback default)
689
+ * constrains scheme, host and port only — an ephemeral client chooses its
690
+ * own callback path. Write a path to pin one.
681
691
  */
682
692
  private matchesPattern;
683
693
  /**
@@ -665,19 +665,29 @@ declare class OAuthProxy {
665
665
  */
666
666
  private issueSwappedTokensForRefresh;
667
667
  /**
668
- * Match a URI against an allow-list glob: `*` spans any run of characters,
669
- * `?` exactly one, and everything else is literal.
668
+ * Match a parsed URI against an allow-list pattern, one URI component at a
669
+ * time: scheme, host, port, then everything from the path onwards. A `*`
670
+ * therefore stops where its component stops.
670
671
  *
671
- * "Everything else is literal" is the security-relevant half. Left unescaped,
672
- * a `.` reaches the RegExp as "any character", so the pattern an operator
673
- * wrote for one host — `https://client.example.com/*` — also admits
674
- * `https://clientXexampleYcom/steal`, a name an attacker can register. DCR
675
- * would accept it and `handleCallback()` would later 302 a fresh
676
- * authorization code to it, reopening the CWE-601 path this allow-list
677
- * exists to close. `+ ^ $ ( ) [ ] { } |` widen a pattern the same way.
672
+ * That containment is the whole point. Matching the pattern against the raw
673
+ * string let a wildcard run straight through the delimiters that decide
674
+ * where the browser actually navigates:
678
675
  *
679
- * Escaping and wildcard expansion happen in one pass, so a backslash this
680
- * inserts can never be re-read as the metacharacter of a later pass.
676
+ * - `http://localhost:*` matched `http://localhost:@evil.com/cb`, where
677
+ * `localhost:` is userinfo and the real host is `evil.com`.
678
+ * - `https://*.example.com/*` matched
679
+ * `https://evil.com/a.example.com/cb`, because the wildcard covered
680
+ * `evil.com/a` — authority and path at once.
681
+ *
682
+ * Both register cleanly under the old matcher, and `handleCallback()` would
683
+ * then 302 a fresh authorization code to the attacker's host: the CWE-601
684
+ * theft path this allow-list exists to close. Comparing against `URL`'s
685
+ * parse makes the delimiters structural rather than incidental, so no
686
+ * pattern can span them however it is written.
687
+ *
688
+ * A pattern that omits the path (`http://localhost:*`, the loopback default)
689
+ * constrains scheme, host and port only — an ephemeral client chooses its
690
+ * own callback path. Write a path to pin one.
681
691
  */
682
692
  private matchesPattern;
683
693
  /**
package/dist/ViteMCP.cjs CHANGED
@@ -12,7 +12,7 @@
12
12
 
13
13
 
14
14
 
15
- var _chunk54WICBSYcjs = require('./chunk-54WICBSY.cjs');
15
+ var _chunk252JIXOLcjs = require('./chunk-252JIXOL.cjs');
16
16
 
17
17
  // src/ViteMCP.ts
18
18
 
@@ -1352,5 +1352,5 @@ var normalizeToolResult = (result, hasOutputSchema) => {
1352
1352
 
1353
1353
 
1354
1354
 
1355
- exports.AuthProvider = _chunk54WICBSYcjs.AuthProvider; exports.AzureProvider = _chunk54WICBSYcjs.AzureProvider; exports.DiscoveryDocumentCache = DiscoveryDocumentCache; exports.GitHubProvider = _chunk54WICBSYcjs.GitHubProvider; exports.GoogleProvider = _chunk54WICBSYcjs.GoogleProvider; exports.MEDIA_FETCH_TIMEOUT_MS = MEDIA_FETCH_TIMEOUT_MS; exports.OAuthProvider = _chunk54WICBSYcjs.OAuthProvider; exports.OAuthProxy = _chunk54WICBSYcjs.OAuthProxy; exports.OAuthProxyError = _chunk54WICBSYcjs.OAuthProxyError; exports.ServerState = ServerState; exports.UnexpectedStateError = UnexpectedStateError; exports.UserError = UserError; exports.ViteMCP = ViteMCP; exports.ViteMCPError = ViteMCPError; exports.audioContent = audioContent; exports.delay = _promises3.setTimeout; exports.getAuthSession = _chunk54WICBSYcjs.getAuthSession; exports.imageContent = imageContent; exports.jsonSchemaAdapter = jsonSchemaAdapter; exports.requireAll = _chunk54WICBSYcjs.requireAll; exports.requireAny = _chunk54WICBSYcjs.requireAny; exports.requireAuth = _chunk54WICBSYcjs.requireAuth; exports.requireRole = _chunk54WICBSYcjs.requireRole; exports.requireScopes = _chunk54WICBSYcjs.requireScopes;
1355
+ exports.AuthProvider = _chunk252JIXOLcjs.AuthProvider; exports.AzureProvider = _chunk252JIXOLcjs.AzureProvider; exports.DiscoveryDocumentCache = DiscoveryDocumentCache; exports.GitHubProvider = _chunk252JIXOLcjs.GitHubProvider; exports.GoogleProvider = _chunk252JIXOLcjs.GoogleProvider; exports.MEDIA_FETCH_TIMEOUT_MS = MEDIA_FETCH_TIMEOUT_MS; exports.OAuthProvider = _chunk252JIXOLcjs.OAuthProvider; exports.OAuthProxy = _chunk252JIXOLcjs.OAuthProxy; exports.OAuthProxyError = _chunk252JIXOLcjs.OAuthProxyError; exports.ServerState = ServerState; exports.UnexpectedStateError = UnexpectedStateError; exports.UserError = UserError; exports.ViteMCP = ViteMCP; exports.ViteMCPError = ViteMCPError; exports.audioContent = audioContent; exports.delay = _promises3.setTimeout; exports.getAuthSession = _chunk252JIXOLcjs.getAuthSession; exports.imageContent = imageContent; exports.jsonSchemaAdapter = jsonSchemaAdapter; exports.requireAll = _chunk252JIXOLcjs.requireAll; exports.requireAny = _chunk252JIXOLcjs.requireAny; exports.requireAuth = _chunk252JIXOLcjs.requireAuth; exports.requireRole = _chunk252JIXOLcjs.requireRole; exports.requireScopes = _chunk252JIXOLcjs.requireScopes;
1356
1356
  //# 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-Dwj2x-De.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-Dwj2x-De.cjs';
7
+ import { A as AuthProvider, O as OAuthSession, a as OAuthProxy } from './OAuthProvider-CWBi3c3D.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-CWBi3c3D.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-Dwj2x-De.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-Dwj2x-De.js';
7
+ import { A as AuthProvider, O as OAuthSession, a as OAuthProxy } from './OAuthProvider-CWBi3c3D.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-CWBi3c3D.js';
9
9
 
10
10
  declare class DiscoveryDocumentCache {
11
11
  #private;
package/dist/ViteMCP.js CHANGED
@@ -12,7 +12,7 @@ import {
12
12
  requireAuth,
13
13
  requireRole,
14
14
  requireScopes
15
- } from "./chunk-3XFM6H44.js";
15
+ } from "./chunk-J2FAZRSL.js";
16
16
 
17
17
  // src/ViteMCP.ts
18
18
  import {
@@ -24,7 +24,7 @@
24
24
 
25
25
 
26
26
 
27
- var _chunk54WICBSYcjs = require('../chunk-54WICBSY.cjs');
27
+ var _chunk252JIXOLcjs = require('../chunk-252JIXOL.cjs');
28
28
 
29
29
 
30
30
 
@@ -51,5 +51,5 @@ var _chunk54WICBSYcjs = require('../chunk-54WICBSY.cjs');
51
51
 
52
52
 
53
53
 
54
- exports.AuthProvider = _chunk54WICBSYcjs.AuthProvider; exports.AzureProvider = _chunk54WICBSYcjs.AzureProvider; exports.ConsentManager = _chunk54WICBSYcjs.ConsentManager; exports.DEFAULT_ACCESS_TOKEN_TTL = _chunk54WICBSYcjs.DEFAULT_ACCESS_TOKEN_TTL; exports.DEFAULT_ACCESS_TOKEN_TTL_NO_REFRESH = _chunk54WICBSYcjs.DEFAULT_ACCESS_TOKEN_TTL_NO_REFRESH; exports.DEFAULT_AUTHORIZATION_CODE_TTL = _chunk54WICBSYcjs.DEFAULT_AUTHORIZATION_CODE_TTL; exports.DEFAULT_REFRESH_TOKEN_TTL = _chunk54WICBSYcjs.DEFAULT_REFRESH_TOKEN_TTL; exports.DEFAULT_TRANSACTION_TTL = _chunk54WICBSYcjs.DEFAULT_TRANSACTION_TTL; exports.DiskStore = _chunk54WICBSYcjs.DiskStore; exports.EncryptedTokenStorage = _chunk54WICBSYcjs.EncryptedTokenStorage; exports.GitHubProvider = _chunk54WICBSYcjs.GitHubProvider; exports.GoogleProvider = _chunk54WICBSYcjs.GoogleProvider; exports.JWKSVerifier = _chunk54WICBSYcjs.JWKSVerifier; exports.JWTIssuer = _chunk54WICBSYcjs.JWTIssuer; exports.MemoryTokenStorage = _chunk54WICBSYcjs.MemoryTokenStorage; exports.OAuthProvider = _chunk54WICBSYcjs.OAuthProvider; exports.OAuthProxy = _chunk54WICBSYcjs.OAuthProxy; exports.OAuthProxyError = _chunk54WICBSYcjs.OAuthProxyError; exports.PKCEUtils = _chunk54WICBSYcjs.PKCEUtils; exports.getAuthSession = _chunk54WICBSYcjs.getAuthSession; exports.requireAll = _chunk54WICBSYcjs.requireAll; exports.requireAny = _chunk54WICBSYcjs.requireAny; exports.requireAuth = _chunk54WICBSYcjs.requireAuth; exports.requireRole = _chunk54WICBSYcjs.requireRole; exports.requireScopes = _chunk54WICBSYcjs.requireScopes;
54
+ exports.AuthProvider = _chunk252JIXOLcjs.AuthProvider; exports.AzureProvider = _chunk252JIXOLcjs.AzureProvider; exports.ConsentManager = _chunk252JIXOLcjs.ConsentManager; exports.DEFAULT_ACCESS_TOKEN_TTL = _chunk252JIXOLcjs.DEFAULT_ACCESS_TOKEN_TTL; exports.DEFAULT_ACCESS_TOKEN_TTL_NO_REFRESH = _chunk252JIXOLcjs.DEFAULT_ACCESS_TOKEN_TTL_NO_REFRESH; exports.DEFAULT_AUTHORIZATION_CODE_TTL = _chunk252JIXOLcjs.DEFAULT_AUTHORIZATION_CODE_TTL; exports.DEFAULT_REFRESH_TOKEN_TTL = _chunk252JIXOLcjs.DEFAULT_REFRESH_TOKEN_TTL; exports.DEFAULT_TRANSACTION_TTL = _chunk252JIXOLcjs.DEFAULT_TRANSACTION_TTL; exports.DiskStore = _chunk252JIXOLcjs.DiskStore; exports.EncryptedTokenStorage = _chunk252JIXOLcjs.EncryptedTokenStorage; exports.GitHubProvider = _chunk252JIXOLcjs.GitHubProvider; exports.GoogleProvider = _chunk252JIXOLcjs.GoogleProvider; exports.JWKSVerifier = _chunk252JIXOLcjs.JWKSVerifier; exports.JWTIssuer = _chunk252JIXOLcjs.JWTIssuer; exports.MemoryTokenStorage = _chunk252JIXOLcjs.MemoryTokenStorage; exports.OAuthProvider = _chunk252JIXOLcjs.OAuthProvider; exports.OAuthProxy = _chunk252JIXOLcjs.OAuthProxy; exports.OAuthProxyError = _chunk252JIXOLcjs.OAuthProxyError; exports.PKCEUtils = _chunk252JIXOLcjs.PKCEUtils; exports.getAuthSession = _chunk252JIXOLcjs.getAuthSession; exports.requireAll = _chunk252JIXOLcjs.requireAll; exports.requireAny = _chunk252JIXOLcjs.requireAny; exports.requireAuth = _chunk252JIXOLcjs.requireAuth; exports.requireRole = _chunk252JIXOLcjs.requireRole; exports.requireScopes = _chunk252JIXOLcjs.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-Dwj2x-De.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-Dwj2x-De.cjs';
1
+ import { q as OAuthTransaction, C as ConsentData, T as TokenStorage, s as TokenVerifier, t as TokenVerificationResult, P as PKCEPair } from '../OAuthProvider-CWBi3c3D.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-CWBi3c3D.cjs';
3
3
 
4
4
  /**
5
5
  * Consent Management
@@ -72,12 +72,19 @@ interface DiskStoreOptions {
72
72
  * Persists tokens to filesystem for survival across server restarts
73
73
  */
74
74
  declare class DiskStore implements TokenStorage {
75
+ private cleanupInFlight;
75
76
  private cleanupInterval;
76
77
  private directory;
77
78
  private fileExtension;
78
79
  constructor(options: DiskStoreOptions);
79
80
  /**
80
- * Clean up expired entries
81
+ * Clean up expired entries.
82
+ *
83
+ * A sweep walks the whole directory and reads every entry, so on a large
84
+ * store it can outlast the cleanup interval. Callers arriving while one is
85
+ * running — the timer below, the OAuth proxy's own cleanup timer, or a
86
+ * direct call — join the sweep in flight instead of starting a second walk
87
+ * over the same files, which would only make a slow sweep slower.
81
88
  */
82
89
  cleanup(): Promise<void>;
83
90
  /**
@@ -117,6 +124,11 @@ declare class DiskStore implements TokenStorage {
117
124
  * Get file path for a key
118
125
  */
119
126
  private getFilePath;
127
+ /**
128
+ * One directory sweep. Always call through {@link cleanup}, which keeps
129
+ * concurrent sweeps from overlapping.
130
+ */
131
+ private runCleanup;
120
132
  }
121
133
 
122
134
  /**
@@ -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-Dwj2x-De.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-Dwj2x-De.js';
1
+ import { q as OAuthTransaction, C as ConsentData, T as TokenStorage, s as TokenVerifier, t as TokenVerificationResult, P as PKCEPair } from '../OAuthProvider-CWBi3c3D.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-CWBi3c3D.js';
3
3
 
4
4
  /**
5
5
  * Consent Management
@@ -72,12 +72,19 @@ interface DiskStoreOptions {
72
72
  * Persists tokens to filesystem for survival across server restarts
73
73
  */
74
74
  declare class DiskStore implements TokenStorage {
75
+ private cleanupInFlight;
75
76
  private cleanupInterval;
76
77
  private directory;
77
78
  private fileExtension;
78
79
  constructor(options: DiskStoreOptions);
79
80
  /**
80
- * Clean up expired entries
81
+ * Clean up expired entries.
82
+ *
83
+ * A sweep walks the whole directory and reads every entry, so on a large
84
+ * store it can outlast the cleanup interval. Callers arriving while one is
85
+ * running — the timer below, the OAuth proxy's own cleanup timer, or a
86
+ * direct call — join the sweep in flight instead of starting a second walk
87
+ * over the same files, which would only make a slow sweep slower.
81
88
  */
82
89
  cleanup(): Promise<void>;
83
90
  /**
@@ -117,6 +124,11 @@ declare class DiskStore implements TokenStorage {
117
124
  * Get file path for a key
118
125
  */
119
126
  private getFilePath;
127
+ /**
128
+ * One directory sweep. Always call through {@link cleanup}, which keeps
129
+ * concurrent sweeps from overlapping.
130
+ */
131
+ private runCleanup;
120
132
  }
121
133
 
122
134
  /**
@@ -24,7 +24,7 @@ import {
24
24
  requireAuth,
25
25
  requireRole,
26
26
  requireScopes
27
- } from "../chunk-3XFM6H44.js";
27
+ } from "../chunk-J2FAZRSL.js";
28
28
  export {
29
29
  AuthProvider,
30
30
  AzureProvider,
@@ -2318,31 +2318,54 @@ var OAuthProxy = (_class4 = class {
2318
2318
  return response;
2319
2319
  }
2320
2320
  /**
2321
- * Match a URI against an allow-list glob: `*` spans any run of characters,
2322
- * `?` exactly one, and everything else is literal.
2321
+ * Match a parsed URI against an allow-list pattern, one URI component at a
2322
+ * time: scheme, host, port, then everything from the path onwards. A `*`
2323
+ * therefore stops where its component stops.
2323
2324
  *
2324
- * "Everything else is literal" is the security-relevant half. Left unescaped,
2325
- * a `.` reaches the RegExp as "any character", so the pattern an operator
2326
- * wrote for one host — `https://client.example.com/*` — also admits
2327
- * `https://clientXexampleYcom/steal`, a name an attacker can register. DCR
2328
- * would accept it and `handleCallback()` would later 302 a fresh
2329
- * authorization code to it, reopening the CWE-601 path this allow-list
2330
- * exists to close. `+ ^ $ ( ) [ ] { } |` widen a pattern the same way.
2325
+ * That containment is the whole point. Matching the pattern against the raw
2326
+ * string let a wildcard run straight through the delimiters that decide
2327
+ * where the browser actually navigates:
2331
2328
  *
2332
- * Escaping and wildcard expansion happen in one pass, so a backslash this
2333
- * inserts can never be re-read as the metacharacter of a later pass.
2329
+ * - `http://localhost:*` matched `http://localhost:@evil.com/cb`, where
2330
+ * `localhost:` is userinfo and the real host is `evil.com`.
2331
+ * - `https://*.example.com/*` matched
2332
+ * `https://evil.com/a.example.com/cb`, because the wildcard covered
2333
+ * `evil.com/a` — authority and path at once.
2334
+ *
2335
+ * Both register cleanly under the old matcher, and `handleCallback()` would
2336
+ * then 302 a fresh authorization code to the attacker's host: the CWE-601
2337
+ * theft path this allow-list exists to close. Comparing against `URL`'s
2338
+ * parse makes the delimiters structural rather than incidental, so no
2339
+ * pattern can span them however it is written.
2340
+ *
2341
+ * A pattern that omits the path (`http://localhost:*`, the loopback default)
2342
+ * constrains scheme, host and port only — an ephemeral client chooses its
2343
+ * own callback path. Write a path to pin one.
2334
2344
  */
2335
2345
  matchesPattern(uri, pattern) {
2336
- const source = pattern.replace(/[.*+?^${}()|[\]\\]/g, (character) => {
2337
- if (character === "*") {
2338
- return ".*";
2346
+ const parsed = parseUriPattern(pattern);
2347
+ if (!parsed) {
2348
+ return false;
2349
+ }
2350
+ if (uri.protocol.slice(0, -1) !== parsed.scheme) {
2351
+ return false;
2352
+ }
2353
+ if (parsed.authority) {
2354
+ if (!globComponent(parsed.authority.host).test(uri.hostname)) {
2355
+ return false;
2339
2356
  }
2340
- if (character === "?") {
2341
- return ".";
2357
+ if (!globComponent(parsed.authority.port).test(uri.port)) {
2358
+ return false;
2342
2359
  }
2343
- return `\\${character}`;
2344
- });
2345
- return new RegExp(`^${source}$`).test(uri);
2360
+ } else if (uri.host !== "") {
2361
+ return false;
2362
+ }
2363
+ if (parsed.rest === "") {
2364
+ return true;
2365
+ }
2366
+ return globComponent(parsed.rest).test(
2367
+ `${uri.pathname}${uri.search}${uri.hash}`
2368
+ );
2346
2369
  }
2347
2370
  /**
2348
2371
  * Parse token response that can be either JSON or URL-encoded
@@ -2566,11 +2589,15 @@ var OAuthProxy = (_class4 = class {
2566
2589
  * theft. Do not loosen the default beyond loopback addresses.
2567
2590
  */
2568
2591
  validateRedirectUri(uri) {
2592
+ let url;
2569
2593
  try {
2570
- new URL(uri);
2594
+ url = new URL(uri);
2571
2595
  } catch (e8) {
2572
2596
  return false;
2573
2597
  }
2598
+ if (url.username !== "" || url.password !== "") {
2599
+ return false;
2600
+ }
2574
2601
  const patterns = this.config.allowedRedirectUriPatterns;
2575
2602
  if (Array.isArray(patterns) && patterns.length === 0) {
2576
2603
  return false;
@@ -2580,10 +2607,49 @@ var OAuthProxy = (_class4 = class {
2580
2607
  "http://127.0.0.1:*"
2581
2608
  ]));
2582
2609
  return effectivePatterns.some(
2583
- (pattern) => this.matchesPattern(uri, pattern)
2610
+ (pattern) => this.matchesPattern(url, pattern)
2584
2611
  );
2585
2612
  }
2586
2613
  }, _class4);
2614
+ var globComponent = (glob) => {
2615
+ const source = glob.replace(/[.*+?^${}()|[\]\\]/g, (character) => {
2616
+ if (character === "*") {
2617
+ return ".*";
2618
+ }
2619
+ if (character === "?") {
2620
+ return ".";
2621
+ }
2622
+ return `\\${character}`;
2623
+ });
2624
+ return new RegExp(`^${source}$`);
2625
+ };
2626
+ var parseUriPattern = (pattern) => {
2627
+ const schemeEnd = pattern.indexOf(":");
2628
+ if (schemeEnd <= 0) {
2629
+ return null;
2630
+ }
2631
+ const scheme = pattern.slice(0, schemeEnd).toLowerCase();
2632
+ const afterScheme = pattern.slice(schemeEnd + 1);
2633
+ if (!afterScheme.startsWith("//")) {
2634
+ return { authority: null, rest: afterScheme, scheme };
2635
+ }
2636
+ const hierarchical = afterScheme.slice(2);
2637
+ const restStart = hierarchical.search(/[#/?]/);
2638
+ const authority = restStart === -1 ? hierarchical : hierarchical.slice(0, restStart);
2639
+ if (authority.includes("@")) {
2640
+ return null;
2641
+ }
2642
+ const hostEnd = authority.startsWith("[") ? authority.indexOf("]") + 1 : 0;
2643
+ const portSeparator = authority.indexOf(":", hostEnd);
2644
+ return {
2645
+ authority: {
2646
+ host: (portSeparator === -1 ? authority : authority.slice(0, portSeparator)).toLowerCase(),
2647
+ port: portSeparator === -1 ? "" : authority.slice(portSeparator + 1)
2648
+ },
2649
+ rest: restStart === -1 ? "" : hierarchical.slice(restStart),
2650
+ scheme
2651
+ };
2652
+ };
2587
2653
  var isLoopbackRedirectUri = (uri) => {
2588
2654
  try {
2589
2655
  const url = new URL(uri);
@@ -2878,10 +2944,11 @@ var OAuthProvider = class extends AuthProvider {
2878
2944
  var _promises = require('fs/promises');
2879
2945
  var _path = require('path');
2880
2946
  var DiskStore = (_class6 = class {
2881
- __init10() {this.cleanupInterval = null}
2947
+ __init10() {this.cleanupInFlight = null}
2948
+ __init11() {this.cleanupInterval = null}
2882
2949
 
2883
2950
 
2884
- constructor(options) {;_class6.prototype.__init10.call(this);
2951
+ constructor(options) {;_class6.prototype.__init10.call(this);_class6.prototype.__init11.call(this);
2885
2952
  this.directory = options.directory;
2886
2953
  this.fileExtension = options.fileExtension || ".json";
2887
2954
  void this.ensureDirectory();
@@ -2891,35 +2958,19 @@ var DiskStore = (_class6 = class {
2891
2958
  }, cleanupIntervalMs);
2892
2959
  }
2893
2960
  /**
2894
- * Clean up expired entries
2961
+ * Clean up expired entries.
2962
+ *
2963
+ * A sweep walks the whole directory and reads every entry, so on a large
2964
+ * store it can outlast the cleanup interval. Callers arriving while one is
2965
+ * running — the timer below, the OAuth proxy's own cleanup timer, or a
2966
+ * direct call — join the sweep in flight instead of starting a second walk
2967
+ * over the same files, which would only make a slow sweep slower.
2895
2968
  */
2896
2969
  async cleanup() {
2897
- try {
2898
- await this.ensureDirectory();
2899
- const files = await _promises.readdir.call(void 0, this.directory);
2900
- const now = Date.now();
2901
- for (const file of files) {
2902
- if (!file.endsWith(this.fileExtension)) {
2903
- continue;
2904
- }
2905
- try {
2906
- const filePath = _path.join.call(void 0, this.directory, file);
2907
- const content = await _promises.readFile.call(void 0, filePath, "utf-8");
2908
- const entry = JSON.parse(content);
2909
- if (entry.expiresAt < now) {
2910
- await _promises.rm.call(void 0, filePath);
2911
- }
2912
- } catch (error) {
2913
- console.warn(`Failed to read/parse file ${file}, deleting:`, error);
2914
- try {
2915
- await _promises.rm.call(void 0, _path.join.call(void 0, this.directory, file));
2916
- } catch (e10) {
2917
- }
2918
- }
2919
- }
2920
- } catch (error) {
2921
- console.error("Cleanup failed:", error);
2922
- }
2970
+ this.cleanupInFlight ??= this.runCleanup().finally(() => {
2971
+ this.cleanupInFlight = null;
2972
+ });
2973
+ return this.cleanupInFlight;
2923
2974
  }
2924
2975
  /**
2925
2976
  * Delete a value
@@ -2993,7 +3044,7 @@ var DiskStore = (_class6 = class {
2993
3044
  await this.ensureDirectory();
2994
3045
  const files = await _promises.readdir.call(void 0, this.directory);
2995
3046
  return files.filter((f) => f.endsWith(this.fileExtension)).length;
2996
- } catch (e11) {
3047
+ } catch (e10) {
2997
3048
  return 0;
2998
3049
  }
2999
3050
  }
@@ -3051,15 +3102,47 @@ var DiskStore = (_class6 = class {
3051
3102
  const sanitizedKey = key.replace(/[^a-zA-Z0-9_-]/g, "_");
3052
3103
  return _path.join.call(void 0, this.directory, `${sanitizedKey}${this.fileExtension}`);
3053
3104
  }
3105
+ /**
3106
+ * One directory sweep. Always call through {@link cleanup}, which keeps
3107
+ * concurrent sweeps from overlapping.
3108
+ */
3109
+ async runCleanup() {
3110
+ try {
3111
+ await this.ensureDirectory();
3112
+ const files = await _promises.readdir.call(void 0, this.directory);
3113
+ const now = Date.now();
3114
+ for (const file of files) {
3115
+ if (!file.endsWith(this.fileExtension)) {
3116
+ continue;
3117
+ }
3118
+ try {
3119
+ const filePath = _path.join.call(void 0, this.directory, file);
3120
+ const content = await _promises.readFile.call(void 0, filePath, "utf-8");
3121
+ const entry = JSON.parse(content);
3122
+ if (entry.expiresAt < now) {
3123
+ await _promises.rm.call(void 0, filePath);
3124
+ }
3125
+ } catch (error) {
3126
+ console.warn(`Failed to read/parse file ${file}, deleting:`, error);
3127
+ try {
3128
+ await _promises.rm.call(void 0, _path.join.call(void 0, this.directory, file));
3129
+ } catch (e11) {
3130
+ }
3131
+ }
3132
+ }
3133
+ } catch (error) {
3134
+ console.error("Cleanup failed:", error);
3135
+ }
3136
+ }
3054
3137
  }, _class6);
3055
3138
 
3056
3139
  // src/auth/utils/jwks.ts
3057
3140
  var JWKSVerifier = (_class7 = class {
3058
3141
 
3059
3142
 
3060
- __init11() {this.joseLoaded = false}
3143
+ __init12() {this.joseLoaded = false}
3061
3144
 
3062
- constructor(config) {;_class7.prototype.__init11.call(this);
3145
+ constructor(config) {;_class7.prototype.__init12.call(this);
3063
3146
  this.config = {
3064
3147
  cacheDuration: 36e5,
3065
3148
  // 1 hour
@@ -3217,4 +3300,4 @@ Original error: ${error.message}`
3217
3300
 
3218
3301
 
3219
3302
  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;
3220
- //# sourceMappingURL=chunk-54WICBSY.cjs.map
3303
+ //# sourceMappingURL=chunk-252JIXOL.cjs.map