← Blog

Claude MCP skill OAuth 2.0 misconfiguration — GitHub and GitLab integration — SA-SKL-AUTH15

OAuth 2.0 integration with GitHub and GitLab is a core feature of MCP skill registries — it allows skill authors to connect their repositories, trigger CI audits on push, and link their GitHub identity. OAuth flows are deceptively easy to implement incorrectly: missing state parameter validation enables CSRF account linking, missing redirect_uri verification enables authorization code interception, tokens stored in localStorage are readable by any XSS, and webhook secrets not verified with HMAC allow event forgery. SA-SKL-AUTH15 covers all four patterns.

By SkillAudit  |  12 Nov 2026
SA-SKL-AUTH15 findings at a glance
CRITICALAUTH15-001 — State parameter not validated on OAuth callback; attacker crafts a callback URL with a valid authorization code and no state check; victim's browser triggers the callback and links the attacker's GitHub account to the victim's registry account
CRITICALAUTH15-002 — OAuth code exchange does not verify that redirect_uri in the exchange request matches the registered redirect; attacker intercepts the authorization code via an open redirect in the application; exchanges it for an access token
HIGHAUTH15-003 — GitHub/GitLab access token stored in localStorage; any XSS vulnerability in the registry reads the token directly; token grants read access to private repositories the user connected
HIGHAUTH15-004 — GitHub webhook secret not verified on repository event webhooks; attacker forges push and release events to trigger CI audit queue runs or manipulate published skill versions

AUTH15-001 — State parameter not validated on OAuth callback

The OAuth 2.0 state parameter is a CSRF token for the authorization flow. The application generates a random value, stores it in the user's session before redirecting to GitHub, and verifies on callback that the returned state matches the stored value. Without this check, an attacker can trick the victim's browser into completing an OAuth callback using the attacker's authorization code. If the OAuth flow is used for account linking (connecting a GitHub account to an existing registry account), the victim's account gets linked to the attacker's GitHub. The attacker then controls the linked GitHub account and may be able to push malicious code that the registry automatically scans and publishes under the victim's identity.

Vulnerable
// AUTH15-001 — VULNERABLE
// OAuth callback handler does not validate the state parameter — CSRF account linking.

router.get('/auth/github/callback', async (req, res) => {
  const { code } = req.query;
  // VULNERABLE: state parameter from req.query not checked against session
  // Attacker constructs: /auth/github/callback?code=ATTACKER_CODE&state=anything

  const tokenResponse = await exchangeCodeForToken(code);
  const githubUser = await getGitHubUser(tokenResponse.access_token);

  // Links attacker's GitHub account to whoever visits this URL
  await db.linkGitHubAccount(req.session.userId, githubUser.id, tokenResponse.access_token);

  res.redirect('/dashboard');
});
Fixed
// AUTH15-001 — FIXED
// Generate and store state before redirect; verify on callback; delete after use.

import crypto from 'node:crypto';

// When initiating the OAuth flow:
router.get('/auth/github', authenticate, (req, res) => {
  // Fix 1: generate cryptographically random state token
  const state = crypto.randomBytes(32).toString('hex');

  // Fix 2: store in server-side session (not cookie, not localStorage)
  req.session.oauthState = state;
  req.session.oauthInitiatedAt = Date.now();

  const authUrl = new URL('https://github.com/login/oauth/authorize');
  authUrl.searchParams.set('client_id', process.env.GITHUB_CLIENT_ID);
  authUrl.searchParams.set('redirect_uri', process.env.GITHUB_REDIRECT_URI);
  authUrl.searchParams.set('scope', 'read:user,repo');
  authUrl.searchParams.set('state', state); // Include state in redirect

  res.redirect(authUrl.toString());
});

// OAuth callback handler:
router.get('/auth/github/callback', authenticate, async (req, res) => {
  const { code, state } = req.query;

  // Fix 3: validate state matches session — timing-safe comparison
  const expectedState = req.session.oauthState;
  if (!expectedState || !state ||
      !crypto.timingSafeEqual(Buffer.from(state), Buffer.from(expectedState))) {
    return res.status(400).json({ error: 'Invalid OAuth state — CSRF detected' });
  }

  // Fix 4: delete state immediately after validation — prevent replay
  delete req.session.oauthState;

  // Fix 5: reject flows older than 10 minutes
  if (Date.now() - req.session.oauthInitiatedAt > 10 * 60 * 1000) {
    return res.status(400).json({ error: 'OAuth flow expired — please try again' });
  }

  const tokenResponse = await exchangeCodeForToken(code, process.env.GITHUB_REDIRECT_URI);
  const githubUser = await getGitHubUser(tokenResponse.access_token);
  await db.linkGitHubAccount(req.session.userId, githubUser.id, tokenResponse.access_token);

  res.redirect('/dashboard');
});

CSRF account linking is a high-impact attack: When OAuth is used for account linking (not initial login), the CSRF payload is a valid authorization code the attacker obtained by going through the OAuth flow themselves. The attacker initiates the flow, gets redirected to GitHub, authorizes, and receives a callback with their own code. They then craft a URL to the victim's registry callback endpoint using their code. When the victim visits this URL (via phishing or iframe), the registry links the attacker's GitHub identity to the victim's account. The attacker can then use their GitHub credentials to access registry features under the victim's identity. For JWT-based session security patterns, see SA-SKL-AUTH13.

AUTH15-002 — OAuth code exchange redirect_uri mismatch not verified

OAuth 2.0 (RFC 6749) requires that the redirect_uri provided at authorization must match the redirect_uri provided at token exchange. This prevents authorization code interception via open redirects: if the attacker finds an open redirect at https://skillaudit.dev/redirect?to=https://evil.com, they can send the victim to GitHub authorization with redirect_uri=https://skillaudit.dev/redirect?to=https://evil.com. GitHub redirects the authorization code to that URL, which bounces to https://evil.com. The attacker now has the authorization code. If the registry's token exchange endpoint does not verify that the redirect_uri in the exchange call matches the registered redirect, the attacker exchanges the intercepted code for a valid token.

Vulnerable
// AUTH15-002 — VULNERABLE
// Token exchange does not verify redirect_uri matches registered redirect.
// Attacker intercepted code via open redirect and exchanges without matching URI.

async function exchangeCodeForToken(code) {
  // VULNERABLE: redirect_uri omitted from exchange — GitHub may accept without it,
  // or accept any URI that was used during authorization (including the open redirect)
  const response = await fetch('https://github.com/login/oauth/access_token', {
    method: 'POST',
    headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' },
    body: JSON.stringify({
      client_id: process.env.GITHUB_CLIENT_ID,
      client_secret: process.env.GITHUB_CLIENT_SECRET,
      code,
      // redirect_uri intentionally omitted — attacker exploits this
    }),
  });
  return response.json();
}
Fixed
// AUTH15-002 — FIXED
// Always include the EXACT registered redirect_uri in the token exchange.
// Also: audit application for open redirects — eliminate GITHUB_REDIRECT_URI
// pointing at any URL that could be manipulated by an attacker parameter.

async function exchangeCodeForToken(code, redirectUri) {
  // Fix: always include redirect_uri matching the one used during authorization
  // GitHub verifies they match — prevents intercepted code exchange
  const response = await fetch('https://github.com/login/oauth/access_token', {
    method: 'POST',
    headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' },
    body: JSON.stringify({
      client_id: process.env.GITHUB_CLIENT_ID,
      client_secret: process.env.GITHUB_CLIENT_SECRET,
      code,
      redirect_uri: redirectUri, // Must match exactly what was sent during authorization
    }),
  });

  const tokenData = await response.json();
  if (tokenData.error) throw new Error(`GitHub OAuth error: ${tokenData.error_description}`);
  return tokenData;
}

// Eliminate open redirects — validate redirect destination against allowlist:
router.get('/redirect', (req, res) => {
  const ALLOWED_REDIRECTS = new Set(['/dashboard', '/skills', '/account/settings']);
  const dest = req.query.to ?? '/dashboard';
  // Never redirect to arbitrary external URLs
  if (!ALLOWED_REDIRECTS.has(dest)) return res.redirect('/dashboard');
  res.redirect(dest);
});

AUTH15-003 — Access token stored in localStorage

localStorage is accessible to any JavaScript executing in the page's origin — including JavaScript injected via XSS. When a MCP skill registry stores GitHub or GitLab OAuth access tokens in localStorage, any XSS vulnerability in the registry — in the skill README renderer, in user profile display, in the search results page — allows an attacker to read all tokens with Object.entries(localStorage) and exfiltrate them. GitHub access tokens typically grant read access to the user's repositories, including private ones. GitLab tokens may grant write access depending on the scope requested. The correct storage for sensitive tokens is an httpOnly cookie with SameSite=Strict and Secure, which JavaScript cannot access.

Vulnerable
// AUTH15-003 — VULNERABLE
// GitHub access token stored in localStorage — readable by any XSS.

// After successful OAuth callback:
router.get('/auth/github/callback', authenticate, async (req, res) => {
  const tokenResponse = await exchangeCodeForToken(req.query.code, REDIRECT_URI);
  const githubUser = await getGitHubUser(tokenResponse.access_token);

  await db.linkGitHubAccount(req.session.userId, githubUser.id, tokenResponse.access_token);

  // VULNERABLE: token passed to frontend via URL fragment or response body,
  // then stored in localStorage by the client-side app
  res.redirect(`/dashboard#github_token=${tokenResponse.access_token}`);
  // Frontend JS: localStorage.setItem('github_token', token);
});
Fixed
// AUTH15-003 — FIXED
// GitHub access token stored server-side only — never sent to frontend.
// Frontend uses a session-scoped reference (never the raw token).

router.get('/auth/github/callback', authenticate, async (req, res) => {
  // Validate state first (see AUTH15-001)
  validateOAuthState(req);

  const tokenResponse = await exchangeCodeForToken(req.query.code, REDIRECT_URI);
  const githubUser = await getGitHubUser(tokenResponse.access_token);

  // Fix 1: store token encrypted in the database — never expose to frontend
  await db.linkGitHubAccount(req.session.userId, githubUser.id, {
    encryptedToken: encrypt(tokenResponse.access_token), // AES-256-GCM
    scope: tokenResponse.scope,
    linkedAt: new Date(),
  });

  // Fix 2: set a flag in the server-side session — not the token itself
  req.session.githubLinked = true;

  // Fix 3: redirect to dashboard without token in URL fragment
  res.redirect('/dashboard');

  // Frontend uses: GET /api/github/status → { linked: true, login: 'username' }
  // Raw token is never accessible to frontend JavaScript
});

// When the registry needs to call the GitHub API on behalf of the user:
async function callGitHubApi(userId, endpoint) {
  const { encryptedToken } = await db.getGitHubCredential(userId);
  const token = decrypt(encryptedToken); // Decrypted server-side only
  return fetch(`https://api.github.com${endpoint}`, {
    headers: { Authorization: `Bearer ${token}`, 'User-Agent': 'SkillAudit/1.0' },
  });
}

Encrypting tokens at rest in the database is defence in depth: Even if an attacker obtains a database dump (via SQL injection or backup exfiltration), encrypted tokens cannot be used without the encryption key. Use AES-256-GCM with a key stored in a secrets manager (AWS Secrets Manager, HashiCorp Vault, or at minimum an environment variable never committed to source control). The encryption key must be rotated periodically and the ciphertext re-encrypted on rotation. For brute-force protection and account enumeration patterns, see SA-SKL-AUTH14.

AUTH15-004 — GitHub webhook secret HMAC not verified

When a MCP skill registry registers GitHub webhooks to receive repository push and release events, GitHub signs each webhook payload with an HMAC-SHA256 signature using a shared secret, delivered in the X-Hub-Signature-256 header. The signature is sha256=HMAC_SHA256(secret, rawBody). If the registry does not verify this signature, any party on the internet can POST to the webhook endpoint and forge events: a fake push event that triggers a CI audit run with arbitrary repository metadata, a fake release event that updates the published skill version. For registries that auto-approve audits on push or update skill metadata from release events, forged webhooks allow an attacker to manipulate the registry's data about any skill.

Vulnerable
// AUTH15-004 — VULNERABLE
// GitHub webhook endpoint does not verify X-Hub-Signature-256 — anyone can forge events.

router.post('/webhooks/github', express.json(), async (req, res) => {
  const event = req.headers['x-github-event'];
  const payload = req.body;

  // VULNERABLE: no signature check — attacker forges push/release events
  if (event === 'push') {
    await triggerAudit(payload.repository.full_name, payload.after);
  } else if (event === 'release') {
    await updateSkillVersion(payload.repository.full_name, payload.release.tag_name);
  }

  res.json({ ok: true });
});
Fixed
// AUTH15-004 — FIXED
// Verify X-Hub-Signature-256 HMAC-SHA256 before processing any webhook event.
// Use raw body for signature verification — JSON parsing changes byte representation.

import crypto from 'node:crypto';

function verifyGitHubWebhookSignature(req, res, next) {
  const signature = req.headers['x-hub-signature-256'];
  if (!signature) {
    return res.status(401).json({ error: 'Missing webhook signature' });
  }

  const rawBody = req.rawBody; // Must be collected BEFORE JSON parsing
  const secret = process.env.GITHUB_WEBHOOK_SECRET;

  // Fix 1: compute expected signature
  const expectedSig = `sha256=${crypto
    .createHmac('sha256', secret)
    .update(rawBody)
    .digest('hex')}`;

  // Fix 2: timing-safe comparison — prevents timing oracle attacks
  const sigBuffer = Buffer.from(signature);
  const expectedBuffer = Buffer.from(expectedSig);
  if (sigBuffer.length !== expectedBuffer.length ||
      !crypto.timingSafeEqual(sigBuffer, expectedBuffer)) {
    return res.status(401).json({ error: 'Invalid webhook signature' });
  }

  next();
}

// Collect raw body before any JSON parsing middleware
app.use('/webhooks/github', (req, res, next) => {
  let data = '';
  req.on('data', chunk => { data += chunk; });
  req.on('end', () => { req.rawBody = data; next(); });
});

router.post('/webhooks/github',
  verifyGitHubWebhookSignature,
  express.json(),
  async (req, res) => {
    const event = req.headers['x-github-event'];
    const payload = req.body;

    if (event === 'push') {
      await triggerAudit(payload.repository.full_name, payload.after);
    } else if (event === 'release') {
      await updateSkillVersion(payload.repository.full_name, payload.release.tag_name);
    }

    res.json({ ok: true });
  }
);

Register a unique webhook secret per repository, not one shared secret: GitHub allows setting a unique secret per webhook registration. Using a single shared secret for all repositories means that if one repository's webhook secret leaks (via repository settings exposure), all webhooks across all users are compromised. Store per-repository webhook secrets encrypted in the database, keyed to the skillId. When verifying, look up the skillId from the payload's repository.full_name field first, then retrieve and use that repository's specific secret. For privilege escalation patterns in org-level access control, see SA-SKL-PRIVESC6.

How SkillAudit detects SA-SKL-AUTH15

SkillAudit's authentication scanner applies four checks for the SA-SKL-AUTH15 family:

PatternRoot causeFixSeverity
AUTH15-001State parameter not validated on callback — CSRF account linking via attacker codeGenerate random state; store in server-side session; timing-safe verify on callback; delete after useCRITICAL
AUTH15-002redirect_uri omitted from token exchange — intercepted code redeemed at attacker originAlways include exact registered redirect_uri in exchange; eliminate open redirects in appCRITICAL
AUTH15-003Access token in localStorage — readable by any XSS on the registry originStore token server-side encrypted; never send raw token to frontend; use httpOnly session cookieHIGH
AUTH15-004GitHub webhook HMAC not verified — attacker forges push/release eventsVerify X-Hub-Signature-256 with timing-safe HMAC on raw body; per-repository secretsHIGH