@zereight/mcp-gitlab 2.3.15-next.175 → 2.3.15-next.176

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.
@@ -44,7 +44,7 @@
44
44
  *
45
45
  * Activated when GITLAB_MCP_OAUTH=true. All other auth modes are unaffected.
46
46
  */
47
- import { CustomOAuthError, InsufficientScopeError, InvalidGrantError, InvalidTokenError, ServerError, } from "@modelcontextprotocol/sdk/server/auth/errors.js";
47
+ import { CustomOAuthError, InsufficientScopeError, InvalidGrantError, InvalidRequestError, InvalidTokenError, ServerError, } from "@modelcontextprotocol/sdk/server/auth/errors.js";
48
48
  import { OAuthTokensSchema } from "@modelcontextprotocol/sdk/shared/auth.js";
49
49
  import { randomUUID, randomBytes, createHash } from "node:crypto";
50
50
  import { looksLikeStatelessClientId, mintClientId, openClientId, } from "./stateless/client-id.js";
@@ -433,6 +433,11 @@ class GitLabOAuthServerProvider {
433
433
  // The authorizationCode is a proxy code we generated in handleCallback().
434
434
  // It is either a sealed token (stateless mode) or a random UUID that
435
435
  // keys into the _storedTokens LRU (legacy mode).
436
+ // A code that is unknown, expired, already used, or fails the client,
437
+ // redirect_uri or PKCE binding is invalid_grant, and a missing
438
+ // code_verifier is invalid_request (RFC 6749 §5.2, RFC 7636 §4.6), so
439
+ // the client restarts authorization. Only transient conditions
440
+ // (exchange in progress, replay cache full) are ServerError.
436
441
  const stateless = this._stateless;
437
442
  let entry = null;
438
443
  if (stateless && looksLikeStatelessStoredTokensCode(authorizationCode)) {
@@ -444,7 +449,7 @@ class GitLabOAuthServerProvider {
444
449
  if (reserved.reason === "pending") {
445
450
  throw new ServerError("Authorization code exchange in progress — please retry");
446
451
  }
447
- throw new ServerError("Authorization code already used");
452
+ throw new InvalidGrantError("Authorization code already used");
448
453
  }
449
454
  }
450
455
  catch (err) {
@@ -460,7 +465,7 @@ class GitLabOAuthServerProvider {
460
465
  reservedProxyCode = { hash: codeHash, id: reserved.reservationId };
461
466
  const payload = openStoredTokensCode(stateless.material, authorizationCode, stateless.storedTtlSeconds);
462
467
  if (!payload) {
463
- throw new ServerError("Invalid or expired authorization code");
468
+ throw new InvalidGrantError("Invalid or expired authorization code");
464
469
  }
465
470
  entry = {
466
471
  tokens: payload.t,
@@ -477,10 +482,10 @@ class GitLabOAuthServerProvider {
477
482
  // client/redirect/PKCE binding checks fail (DoS prevention).
478
483
  const lru = this._storedTokens.getAndDelete(authorizationCode);
479
484
  if (!lru) {
480
- throw new ServerError("Invalid or expired authorization code");
485
+ throw new InvalidGrantError("Invalid or expired authorization code");
481
486
  }
482
487
  if (Date.now() - lru.createdAt > PENDING_AUTH_TTL_MS) {
483
- throw new ServerError("Authorization code expired — please restart the OAuth flow");
488
+ throw new InvalidGrantError("Authorization code expired — please restart the OAuth flow");
484
489
  }
485
490
  legacyRestorable = { code: authorizationCode, entry: lru };
486
491
  entry = {
@@ -495,20 +500,20 @@ class GitLabOAuthServerProvider {
495
500
  // Binding + PKCE run while consumption is only *reserved* (pending /
496
501
  // restorable); failed checks release so the legitimate client can retry.
497
502
  if (client.client_id !== entry.clientId) {
498
- throw new ServerError("Invalid client for authorization code");
503
+ throw new InvalidGrantError("Invalid client for authorization code");
499
504
  }
500
505
  if (redirectUri !== entry.clientRedirectUri) {
501
- throw new ServerError("Invalid redirect_uri for authorization code");
506
+ throw new InvalidGrantError("Invalid redirect_uri for authorization code");
502
507
  }
503
508
  // Verify client PKCE: the client's code_verifier must match the
504
509
  // code_challenge stored during /authorize.
505
510
  if (entry.clientCodeChallenge) {
506
511
  if (!codeVerifier) {
507
- throw new ServerError("PKCE code_verifier is required");
512
+ throw new InvalidRequestError("PKCE code_verifier is required");
508
513
  }
509
514
  const computed = createHash("sha256").update(codeVerifier).digest("base64url");
510
515
  if (computed !== entry.clientCodeChallenge) {
511
- throw new ServerError("PKCE verification failed");
516
+ throw new InvalidGrantError("PKCE verification failed");
512
517
  }
513
518
  }
514
519
  tokens = entry.tokens;
@@ -541,7 +546,7 @@ class GitLabOAuthServerProvider {
541
546
  }
542
547
  if (!(await this.isAllowedGroupMember(tokens.access_token))) {
543
548
  logger.warn({ allowedGroups: this._allowedGroups }, "Token issuance denied: user is not a member of any allowed group");
544
- throw new ServerError(GROUP_ACCESS_DENIED_MESSAGE);
549
+ throw new InvalidGrantError(GROUP_ACCESS_DENIED_MESSAGE);
545
550
  }
546
551
  // All checks passed — permanently consume the proxy code.
547
552
  legacyRestorable = null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zereight/mcp-gitlab",
3
- "version": "2.3.15-next.175",
3
+ "version": "2.3.15-next.176",
4
4
  "mcpName": "io.github.zereight/gitlab-mcp",
5
5
  "description": "GitLab MCP server for projects, merge requests, issues, pipelines, wiki, releases, and more",
6
6
  "keywords": [