@vitemcp/server 1.6.1 → 1.6.3

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.
@@ -2318,13 +2318,54 @@ var OAuthProxy = (_class4 = class {
2318
2318
  return response;
2319
2319
  }
2320
2320
  /**
2321
- * Match URI against pattern (supports wildcards)
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.
2324
+ *
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:
2328
+ *
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.
2322
2344
  */
2323
2345
  matchesPattern(uri, pattern) {
2324
- const regex = new RegExp(
2325
- "^" + pattern.replace(/\*/g, ".*").replace(/\?/g, ".") + "$"
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;
2356
+ }
2357
+ if (!globComponent(parsed.authority.port).test(uri.port)) {
2358
+ return false;
2359
+ }
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}`
2326
2368
  );
2327
- return regex.test(uri);
2328
2369
  }
2329
2370
  /**
2330
2371
  * Parse token response that can be either JSON or URL-encoded
@@ -2548,11 +2589,15 @@ var OAuthProxy = (_class4 = class {
2548
2589
  * theft. Do not loosen the default beyond loopback addresses.
2549
2590
  */
2550
2591
  validateRedirectUri(uri) {
2592
+ let url;
2551
2593
  try {
2552
- new URL(uri);
2594
+ url = new URL(uri);
2553
2595
  } catch (e8) {
2554
2596
  return false;
2555
2597
  }
2598
+ if (url.username !== "" || url.password !== "") {
2599
+ return false;
2600
+ }
2556
2601
  const patterns = this.config.allowedRedirectUriPatterns;
2557
2602
  if (Array.isArray(patterns) && patterns.length === 0) {
2558
2603
  return false;
@@ -2562,10 +2607,49 @@ var OAuthProxy = (_class4 = class {
2562
2607
  "http://127.0.0.1:*"
2563
2608
  ]));
2564
2609
  return effectivePatterns.some(
2565
- (pattern) => this.matchesPattern(uri, pattern)
2610
+ (pattern) => this.matchesPattern(url, pattern)
2566
2611
  );
2567
2612
  }
2568
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
+ };
2569
2653
  var isLoopbackRedirectUri = (uri) => {
2570
2654
  try {
2571
2655
  const url = new URL(uri);
@@ -2958,7 +3042,10 @@ var DiskStore = (_class6 = class {
2958
3042
  value
2959
3043
  };
2960
3044
  try {
2961
- await _promises.writeFile.call(void 0, filePath, JSON.stringify(entry, null, 2), "utf-8");
3045
+ await _promises.writeFile.call(void 0, filePath, JSON.stringify(entry, null, 2), {
3046
+ encoding: "utf-8",
3047
+ mode: 384
3048
+ });
2962
3049
  } catch (error) {
2963
3050
  console.error(`Failed to save key ${key}:`, error);
2964
3051
  throw error;
@@ -3017,7 +3104,7 @@ var DiskStore = (_class6 = class {
3017
3104
  }
3018
3105
  } catch (error) {
3019
3106
  if (error.code === "ENOENT") {
3020
- await _promises.mkdir.call(void 0, this.directory, { recursive: true });
3107
+ await _promises.mkdir.call(void 0, this.directory, { mode: 448, recursive: true });
3021
3108
  } else {
3022
3109
  throw error;
3023
3110
  }
@@ -3196,4 +3283,4 @@ Original error: ${error.message}`
3196
3283
 
3197
3284
 
3198
3285
  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;
3199
- //# sourceMappingURL=chunk-XC4BVJQZ.cjs.map
3286
+ //# sourceMappingURL=chunk-UTQ425O2.cjs.map