@vitemcp/server 1.10.0 → 1.10.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.
@@ -3490,7 +3490,7 @@ var OAuthProvider = class extends AuthProvider {
3490
3490
  };
3491
3491
 
3492
3492
  // src/auth/utils/diskStore.ts
3493
- import { randomUUID } from "crypto";
3493
+ import { createHash as createHash4, randomUUID } from "crypto";
3494
3494
  import {
3495
3495
  mkdir,
3496
3496
  readdir,
@@ -3502,6 +3502,7 @@ import {
3502
3502
  } from "fs/promises";
3503
3503
  import { join } from "path";
3504
3504
  import { setTimeout as delay } from "timers/promises";
3505
+ var MAX_FILE_NAME_BYTES = 255;
3505
3506
  var DiskStore = class {
3506
3507
  cleanupInFlight = null;
3507
3508
  cleanupInterval = null;
@@ -3536,12 +3537,13 @@ var DiskStore = class {
3536
3537
  * Delete a value
3537
3538
  */
3538
3539
  async delete(key) {
3539
- const filePath = this.getFilePath(key);
3540
- try {
3541
- await rm(filePath);
3542
- } catch (error) {
3543
- if (error.code !== "ENOENT") {
3544
- console.error(`Failed to delete key ${key}:`, error);
3540
+ for (const filePath of this.getFilePaths(key)) {
3541
+ try {
3542
+ await rm(filePath);
3543
+ } catch (error) {
3544
+ if (error.code !== "ENOENT") {
3545
+ console.error(`Failed to delete key ${key}:`, error);
3546
+ }
3545
3547
  }
3546
3548
  }
3547
3549
  }
@@ -3558,22 +3560,24 @@ var DiskStore = class {
3558
3560
  * Retrieve a value
3559
3561
  */
3560
3562
  async get(key) {
3561
- const filePath = this.getFilePath(key);
3562
- try {
3563
- const content = await readFile(filePath, "utf-8");
3564
- const entry = JSON.parse(content);
3565
- if (entry.expiresAt < Date.now()) {
3566
- await rm(filePath);
3567
- return null;
3568
- }
3569
- return entry.value;
3570
- } catch (error) {
3571
- if (error.code === "ENOENT") {
3563
+ for (const filePath of this.getFilePaths(key)) {
3564
+ try {
3565
+ const content = await readFile(filePath, "utf-8");
3566
+ const entry = JSON.parse(content);
3567
+ if (entry.expiresAt < Date.now()) {
3568
+ await rm(filePath, { force: true });
3569
+ return null;
3570
+ }
3571
+ return entry.value;
3572
+ } catch (error) {
3573
+ if (error.code === "ENOENT") {
3574
+ continue;
3575
+ }
3576
+ console.error(`Failed to read key ${key}:`, error);
3572
3577
  return null;
3573
3578
  }
3574
- console.error(`Failed to read key ${key}:`, error);
3575
- return null;
3576
3579
  }
3580
+ return null;
3577
3581
  }
3578
3582
  /**
3579
3583
  * Save a value with optional TTL
@@ -3598,6 +3602,10 @@ var DiskStore = class {
3598
3602
  console.error(`Failed to save key ${key}:`, error);
3599
3603
  throw error;
3600
3604
  }
3605
+ const legacyPath = this.getLegacyFilePath(key);
3606
+ if (legacyPath !== void 0) {
3607
+ await rm(legacyPath, { force: true });
3608
+ }
3601
3609
  }
3602
3610
  /**
3603
3611
  * Get the number of stored items
@@ -3620,14 +3628,21 @@ var DiskStore = class {
3620
3628
  * process shares the directory.
3621
3629
  */
3622
3630
  async take(key) {
3623
- const filePath = this.getFilePath(key);
3624
- const claimPath = `${filePath}.${randomUUID()}.claim${this.fileExtension}`;
3625
- try {
3626
- await rename(filePath, claimPath);
3627
- } catch (error) {
3628
- if (error.code !== "ENOENT") {
3629
- console.error(`Failed to take key ${key}:`, error);
3631
+ let claimPath;
3632
+ for (const filePath of this.getFilePaths(key)) {
3633
+ const candidate = `${filePath}.${randomUUID()}.claim${this.fileExtension}`;
3634
+ try {
3635
+ await rename(filePath, candidate);
3636
+ claimPath = candidate;
3637
+ break;
3638
+ } catch (error) {
3639
+ if (error.code !== "ENOENT") {
3640
+ console.error(`Failed to take key ${key}:`, error);
3641
+ return null;
3642
+ }
3630
3643
  }
3644
+ }
3645
+ if (claimPath === void 0) {
3631
3646
  return null;
3632
3647
  }
3633
3648
  try {
@@ -3659,11 +3674,37 @@ var DiskStore = class {
3659
3674
  }
3660
3675
  }
3661
3676
  /**
3662
- * Get file path for a key
3677
+ * Get file path for a key.
3678
+ *
3679
+ * Named after the key's SHA-256 digest, not the key itself. A digest cannot
3680
+ * climb out of the directory, gives distinct keys distinct files (letter
3681
+ * case included, which macOS and Windows fold by default), always fits the
3682
+ * 255-byte file name limit, and keeps a directory listing from giving the
3683
+ * keys away. The `.` sets it apart from every name an earlier version
3684
+ * wrote, none of which has one before the extension.
3663
3685
  */
3664
3686
  getFilePath(key) {
3665
- const sanitizedKey = key.replace(/[^a-zA-Z0-9_-]/g, "_");
3666
- return join(this.directory, `${sanitizedKey}${this.fileExtension}`);
3687
+ const digest = createHash4("sha256").update(key).digest("hex");
3688
+ return join(this.directory, `sha256.${digest}${this.fileExtension}`);
3689
+ }
3690
+ /**
3691
+ * Where a key's entry may be: its own file, then the one an earlier version
3692
+ * would have written, so that entries persisted before an upgrade survive
3693
+ * it.
3694
+ */
3695
+ getFilePaths(key) {
3696
+ const legacyPath = this.getLegacyFilePath(key);
3697
+ return legacyPath === void 0 ? [this.getFilePath(key)] : [this.getFilePath(key), legacyPath];
3698
+ }
3699
+ /**
3700
+ * The file an earlier version stored a key in, or `undefined` when its name
3701
+ * is too long to have ever been written. Every character outside
3702
+ * `[a-zA-Z0-9_-]` became `_`, so `client:a.b` and `client:a_b` shared a
3703
+ * file, and a key over the limit failed with `ENAMETOOLONG`.
3704
+ */
3705
+ getLegacyFilePath(key) {
3706
+ const name = `${key.replace(/[^a-zA-Z0-9_-]/g, "_")}${this.fileExtension}`;
3707
+ return Buffer.byteLength(name) > MAX_FILE_NAME_BYTES ? void 0 : join(this.directory, name);
3667
3708
  }
3668
3709
  /**
3669
3710
  * One directory sweep. Always call through {@link cleanup}, which keeps
@@ -3812,16 +3853,9 @@ var JWKSVerifier = class {
3812
3853
  if (this.joseLoaded) {
3813
3854
  return;
3814
3855
  }
3856
+ let jose;
3815
3857
  try {
3816
- this.jose = await import("jose");
3817
- this.joseLoaded = true;
3818
- this.jwksCache = this.jose.createRemoteJWKSet(
3819
- new URL(this.config.jwksUri),
3820
- {
3821
- cacheMaxAge: this.config.cacheDuration,
3822
- cooldownDuration: this.config.cooldownDuration
3823
- }
3824
- );
3858
+ jose = await import("jose");
3825
3859
  } catch (error) {
3826
3860
  throw new Error(
3827
3861
  `JWKS verification requires the 'jose' package.
@@ -3832,6 +3866,12 @@ If you don't need JWKS support, use HS256 signing instead (default).
3832
3866
  Original error: ${error.message}`
3833
3867
  );
3834
3868
  }
3869
+ this.jwksCache = jose.createRemoteJWKSet(new URL(this.config.jwksUri), {
3870
+ cacheMaxAge: this.config.cacheDuration,
3871
+ cooldownDuration: this.config.cooldownDuration
3872
+ });
3873
+ this.jose = jose;
3874
+ this.joseLoaded = true;
3835
3875
  }
3836
3876
  /**
3837
3877
  * Parse scope from token payload
@@ -3879,4 +3919,4 @@ export {
3879
3919
  DiskStore,
3880
3920
  JWKSVerifier
3881
3921
  };
3882
- //# sourceMappingURL=chunk-AOZIQIXA.js.map
3922
+ //# sourceMappingURL=chunk-NLBRDP5F.js.map