@vitemcp/server 1.0.4 → 1.2.0

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.
@@ -1133,7 +1133,7 @@ var JWTIssuer = class {
1133
1133
  };
1134
1134
 
1135
1135
  // src/auth/utils/pkce.ts
1136
- import { createHash as createHash2, randomBytes as randomBytes2 } from "crypto";
1136
+ import { createHash as createHash2, randomBytes as randomBytes2, timingSafeEqual as timingSafeEqual3 } from "crypto";
1137
1137
  var PKCEUtils = class _PKCEUtils {
1138
1138
  /**
1139
1139
  * Generate a code challenge from a verifier
@@ -1190,11 +1190,11 @@ var PKCEUtils = class _PKCEUtils {
1190
1190
  return false;
1191
1191
  }
1192
1192
  if (method === "plain") {
1193
- return verifier === challenge;
1193
+ return equalsConstantTime(verifier, challenge);
1194
1194
  }
1195
1195
  if (method === "S256") {
1196
1196
  const computedChallenge = _PKCEUtils.generateChallenge(verifier, "S256");
1197
- return computedChallenge === challenge;
1197
+ return equalsConstantTime(computedChallenge, challenge);
1198
1198
  }
1199
1199
  return false;
1200
1200
  }
@@ -1207,6 +1207,11 @@ var PKCEUtils = class _PKCEUtils {
1207
1207
  return buffer.toString("base64").replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
1208
1208
  }
1209
1209
  };
1210
+ function equalsConstantTime(a, b) {
1211
+ const bufA = Buffer.from(a, "utf8");
1212
+ const bufB = Buffer.from(b, "utf8");
1213
+ return bufA.length === bufB.length && timingSafeEqual3(bufA, bufB);
1214
+ }
1210
1215
 
1211
1216
  // src/auth/utils/tokenStore.ts
1212
1217
  import {
@@ -1474,6 +1479,14 @@ var OAuthProxy = class {
1474
1479
  "code_challenge_method required when code_challenge is present"
1475
1480
  );
1476
1481
  }
1482
+ if (params.code_challenge && params.code_challenge_method && !this.supportedCodeChallengeMethods().includes(
1483
+ params.code_challenge_method
1484
+ )) {
1485
+ throw new OAuthProxyError(
1486
+ "invalid_request",
1487
+ `Unsupported code_challenge_method: ${params.code_challenge_method}`
1488
+ );
1489
+ }
1477
1490
  const transaction = await this.createTransaction(params);
1478
1491
  if (this.config.consentRequired && !transaction.consentGiven) {
1479
1492
  return this.consentManager.createConsentResponse(
@@ -1590,7 +1603,7 @@ var OAuthProxy = class {
1590
1603
  authorizationResponseIssParameterSupported: true,
1591
1604
  // Clients prefer CIMD over DCR when both are offered.
1592
1605
  clientIdMetadataDocumentSupported: this.clientIdMetadata.enabled,
1593
- codeChallengeMethodsSupported: ["S256", "plain"],
1606
+ codeChallengeMethodsSupported: this.supportedCodeChallengeMethods(),
1594
1607
  grantTypesSupported: ["authorization_code", "refresh_token"],
1595
1608
  issuer: this.config.baseUrl,
1596
1609
  registrationEndpoint: `${this.config.baseUrl}/oauth/register`,
@@ -2475,6 +2488,19 @@ var OAuthProxy = class {
2475
2488
  this.cleanup();
2476
2489
  }, 6e4);
2477
2490
  }
2491
+ /**
2492
+ * PKCE challenge methods this proxy accepts, advertised in the authorization
2493
+ * server metadata and enforced at /oauth/authorize.
2494
+ *
2495
+ * S256 only by default. `plain` makes the challenge and the verifier the same
2496
+ * value, so the secret needed to redeem an authorization code is exposed
2497
+ * everywhere the authorization request is: browser history, referrer headers,
2498
+ * proxy logs. RFC 7636 §4.2 requires S256 of any client that can hash, and
2499
+ * OAuth 2.1 removes `plain` entirely.
2500
+ */
2501
+ supportedCodeChallengeMethods() {
2502
+ return this.config.allowPlainPkce ? ["S256", "plain"] : ["S256"];
2503
+ }
2478
2504
  /**
2479
2505
  * Atomically claim a token mapping, mirroring `OAuthProxyStateStore`: at most
2480
2506
  * one caller — across all processes sharing the storage — can receive a given
@@ -3121,4 +3147,4 @@ export {
3121
3147
  DiskStore,
3122
3148
  JWKSVerifier
3123
3149
  };
3124
- //# sourceMappingURL=chunk-GJCCOGWU.js.map
3150
+ //# sourceMappingURL=chunk-GBQHIIQM.js.map