@vitemcp/server 1.9.12 → 1.9.14

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.
@@ -378,6 +378,7 @@ var clientCodeStorageSchema = _zod.z.object({
378
378
  codeChallengeMethod: _zod.z.string(),
379
379
  createdAt: storedDateSchema,
380
380
  expiresAt: storedDateSchema,
381
+ redirectUri: _zod.z.string().optional(),
381
382
  transactionId: _zod.z.string(),
382
383
  upstreamTokens: upstreamTokenSetStorageSchema,
383
384
  used: _zod.z.boolean().optional()
@@ -1460,6 +1461,8 @@ var MemoryTokenStorage = (_class3 = class {
1460
1461
  var withoutTrailingSlash = (url) => url.replace(/\/+$/, "");
1461
1462
 
1462
1463
  // src/auth/OAuthProxy.ts
1464
+ var DEFAULT_REDIRECT_PATH = "/oauth/callback";
1465
+ var GITHUB_TOKEN_ENDPOINT = "https://github.com/login/oauth/access_token";
1463
1466
  var RESERVED_AUTHORIZATION_PARAMS = /* @__PURE__ */ new Set([
1464
1467
  "client_id",
1465
1468
  "code_challenge",
@@ -1504,7 +1507,7 @@ var OAuthProxy = (_class4 = class {
1504
1507
  consentRequired: true,
1505
1508
  enableTokenSwap: true,
1506
1509
  // Enabled by default for security
1507
- redirectPath: "/oauth/callback",
1510
+ redirectPath: DEFAULT_REDIRECT_PATH,
1508
1511
  transactionTtl: DEFAULT_TRANSACTION_TTL,
1509
1512
  upstreamRequestTimeoutMs: DEFAULT_UPSTREAM_REQUEST_TIMEOUT_MS,
1510
1513
  upstreamTokenEndpointAuthMethod: "client_secret_basic",
@@ -1655,6 +1658,12 @@ var OAuthProxy = (_class4 = class {
1655
1658
  "Authorization code was issued to another client"
1656
1659
  );
1657
1660
  }
1661
+ if (request2.redirect_uri && clientCode.redirectUri !== void 0 && request2.redirect_uri !== clientCode.redirectUri) {
1662
+ throw new OAuthProxyError(
1663
+ "invalid_grant",
1664
+ "redirect_uri does not match the authorization request"
1665
+ );
1666
+ }
1658
1667
  if (!authenticated && (!clientCode.codeChallenge || clientCode.codeChallengeMethod !== "S256")) {
1659
1668
  throw new OAuthProxyError(
1660
1669
  "invalid_grant",
@@ -1676,6 +1685,11 @@ var OAuthProxy = (_class4 = class {
1676
1685
  if (!valid) {
1677
1686
  throw new OAuthProxyError("invalid_grant", "Invalid PKCE verifier");
1678
1687
  }
1688
+ } else if (request2.code_verifier) {
1689
+ throw new OAuthProxyError(
1690
+ "invalid_request",
1691
+ "code_verifier provided without a code_challenge"
1692
+ );
1679
1693
  }
1680
1694
  if (this.config.enableTokenSwap && this.jwtIssuer) {
1681
1695
  return await this.issueSwappedTokens(
@@ -1686,7 +1700,7 @@ var OAuthProxy = (_class4 = class {
1686
1700
  } else {
1687
1701
  const response = {
1688
1702
  access_token: clientCode.upstreamTokens.accessToken,
1689
- expires_in: clientCode.upstreamTokens.expiresIn,
1703
+ expires_in: clientCode.upstreamTokens.expiresIn || 3600,
1690
1704
  token_type: clientCode.upstreamTokens.tokenType
1691
1705
  };
1692
1706
  if (clientCode.upstreamTokens.refreshToken) {
@@ -1748,6 +1762,15 @@ var OAuthProxy = (_class4 = class {
1748
1762
  tokenEndpointAuthMethodsSupported: [...TOKEN_ENDPOINT_AUTH_METHODS]
1749
1763
  };
1750
1764
  }
1765
+ /**
1766
+ * The path the upstream provider redirects back to: `redirectPath`, or
1767
+ * `/oauth/callback` when none is set. The router serves the callback here
1768
+ * and the proxy sends `{baseUrl}{path}` upstream as the `redirect_uri`, so
1769
+ * both read it from this one place and cannot disagree.
1770
+ */
1771
+ getRedirectPath() {
1772
+ return _nullishCoalesce(this.config.redirectPath, () => ( DEFAULT_REDIRECT_PATH));
1773
+ }
1751
1774
  /**
1752
1775
  * Handle OAuth callback from upstream provider
1753
1776
  */
@@ -2060,7 +2083,7 @@ var OAuthProxy = (_class4 = class {
2060
2083
  code,
2061
2084
  code_verifier: transaction.proxyCodeVerifier,
2062
2085
  grant_type: "authorization_code",
2063
- redirect_uri: `${this.config.baseUrl}${this.config.redirectPath}`
2086
+ redirect_uri: `${this.config.baseUrl}${this.getRedirectPath()}`
2064
2087
  };
2065
2088
  if (!useBasicAuth) {
2066
2089
  bodyParams.client_id = this.config.upstreamClientId;
@@ -2088,7 +2111,10 @@ var OAuthProxy = (_class4 = class {
2088
2111
  const tokens = await this.parseTokenResponse(tokenResponse);
2089
2112
  return {
2090
2113
  accessToken: tokens.access_token,
2091
- expiresIn: tokens.expires_in || 3600,
2114
+ // 0 when the upstream did not say, so `accessTokenTtl` and the defaults
2115
+ // apply. An hour substituted here made every such token look as though
2116
+ // the upstream had set it, and neither was ever reached.
2117
+ expiresIn: _nullishCoalesce(tokens.expires_in, () => ( 0)),
2092
2118
  idToken: tokens.id_token,
2093
2119
  issuedAt: /* @__PURE__ */ new Date(),
2094
2120
  refreshExpiresIn: tokens.refresh_expires_in,
@@ -2180,6 +2206,7 @@ var OAuthProxy = (_class4 = class {
2180
2206
  expiresAt: new Date(
2181
2207
  Date.now() + (this.config.authorizationCodeTtl || 300) * 1e3
2182
2208
  ),
2209
+ redirectUri: transaction.clientCallbackUrl,
2183
2210
  transactionId: transaction.id,
2184
2211
  upstreamTokens
2185
2212
  };
@@ -2623,7 +2650,13 @@ var OAuthProxy = (_class4 = class {
2623
2650
  id_token: _zod.z.string().optional(),
2624
2651
  refresh_expires_in: _zod.z.coerce.number().int().positive().optional(),
2625
2652
  refresh_token: _zod.z.string().optional(),
2626
- scope: _zod.z.string().optional(),
2653
+ // GitHub lists the scopes it granted with commas, `read:user,user:email`,
2654
+ // which read as one scope that no check matched. RFC 6749 §3.3 separates
2655
+ // scopes with spaces and allows a comma inside one, so only GitHub's are
2656
+ // split.
2657
+ scope: _zod.z.string().transform(
2658
+ (scope) => this.config.upstreamTokenEndpoint === GITHUB_TOKEN_ENDPOINT ? scope.split(/[ ,]+/).filter(Boolean).join(" ") : scope
2659
+ ).optional(),
2627
2660
  token_type: _zod.z.string().optional()
2628
2661
  });
2629
2662
  if (contentType.includes("application/x-www-form-urlencoded")) {
@@ -2674,7 +2707,7 @@ var OAuthProxy = (_class4 = class {
2674
2707
  authUrl.searchParams.set("client_id", this.config.upstreamClientId);
2675
2708
  authUrl.searchParams.set(
2676
2709
  "redirect_uri",
2677
- `${this.config.baseUrl}${this.config.redirectPath}`
2710
+ `${this.config.baseUrl}${this.getRedirectPath()}`
2678
2711
  );
2679
2712
  authUrl.searchParams.set("response_type", "code");
2680
2713
  authUrl.searchParams.set("state", transaction.id);
@@ -2731,7 +2764,8 @@ var OAuthProxy = (_class4 = class {
2731
2764
  const tokens = await this.parseTokenResponse(tokenResponse);
2732
2765
  return {
2733
2766
  accessToken: tokens.access_token,
2734
- expiresIn: tokens.expires_in || 3600,
2767
+ // 0 when the upstream did not say, as on the code exchange.
2768
+ expiresIn: _nullishCoalesce(tokens.expires_in, () => ( 0)),
2735
2769
  idToken: tokens.id_token,
2736
2770
  issuedAt: /* @__PURE__ */ new Date(),
2737
2771
  refreshExpiresIn: tokens.refresh_expires_in,
@@ -3661,4 +3695,4 @@ Original error: ${error.message}`
3661
3695
 
3662
3696
 
3663
3697
  exports.withoutTrailingSlash = withoutTrailingSlash; 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;
3664
- //# sourceMappingURL=chunk-2X4JCSQQ.cjs.map
3698
+ //# sourceMappingURL=chunk-T7EJGNI3.cjs.map