← Blog

Claude MCP skill privilege escalation via JWT algorithm confusion in MCP skill authentication — SA-SKL-PRIVESC4

JSON Web Tokens are the dominant authentication mechanism in MCP skill APIs: they are issued at login, carried in every request, and validated in middleware to establish the caller's identity and permissions. JWT's design has two widely-exploited classes of implementation flaws: algorithm confusion (the server accepts a weaker or different algorithm than it intended, letting an attacker forge tokens) and claim validation gaps (the server validates the signature but skips expiry, issuer, or audience checks, letting expired or misrouted tokens grant access). SA-SKL-PRIVESC4 covers four JWT privilege escalation patterns found in MCP skill authentication middleware: algorithm downgrade to alg:none, RS256-to-HS256 key confusion, kid header SQL injection, and missing exp claim validation.

By SkillAudit  |  9 Nov 2026
SA-SKL-PRIVESC4 findings at a glance
CRITICALPRIVESC4-001 — jwt.verify(token, secret) called without the algorithms option; attacker modifies token header to {"alg":"none"} and strips the signature; jsonwebtoken accepts the unsigned token as valid; attacker forges any payload including role: "admin" without knowing the signing key
CRITICALPRIVESC4-002 — Server issues RS256 tokens using an RSA key pair; the public key is exposed at /.well-known/jwks.json; the same jwt.verify() call also accepts HS256-signed tokens; attacker downloads the public key, signs a forged token with it as the HS256 HMAC secret, and the server verifies it successfully against its own public key
HIGHPRIVESC4-003 — JWT kid (key ID) header value used directly in an SQL query to look up the signing key from the database; attacker crafts a JWT with kid: "' OR '1'='1"; SQL injection returns the first key in the table; attacker then signs a forged token with any key they control and the injection causes the server to verify against the wrong key
HIGHPRIVESC4-004 — Custom JWT verification path validates signature but does not check the exp claim; JWTs issued to free-tier users with 1-hour expiry remain valid indefinitely; attacker saves a free-tier JWT from before their account was downgraded and continues to access Pro endpoints with an expired token

PRIVESC4-001 — jwt.verify() without algorithms option allows alg:none

The jsonwebtoken npm package's jwt.verify(token, secret, options) function accepts an optional algorithms array that restricts which signing algorithms are accepted. When this option is omitted, older versions of jsonwebtoken (before the 9.x series added stricter defaults) would accept tokens with alg: "none" — the unsigned JWT format defined in RFC 7519. An attacker intercepts a valid JWT, decodes the header, sets alg to "none", modifies the payload (e.g., elevating role to "admin"), removes the signature portion, and sends the modified token. The server calls jwt.verify() without an algorithms constraint and accepts the unsigned token as valid.

// VULNERABLE — PRIVESC4-001
// jwt.verify() called without algorithms option — accepts alg:none tokens.
// Attacker takes a valid token, changes header.alg to "none", elevates payload.role to "admin",
// strips the signature portion (keeps trailing dot), and sends modified token.
// jwt.verify() accepts it as valid if jsonwebtoken version is permissive.

import jwt from 'jsonwebtoken';

const JWT_SECRET = process.env.JWT_SECRET;

function requireAuth(req, res, next) {
  const token = req.headers.authorization?.split(' ')[1];
  if (!token) return res.status(401).json({ error: 'No token' });

  try {
    // VULNERABLE: no algorithms option — vulnerable to alg:none on older jsonwebtoken
    const payload = jwt.verify(token, JWT_SECRET);
    req.user = payload;
    next();
  } catch (err) {
    return res.status(401).json({ error: 'Invalid token' });
  }
}
// FIXED — PRIVESC4-001
// Fix 1: Always pass algorithms option — jwt.verify() will reject tokens with any other algorithm.
// Fix 2: Upgrade jsonwebtoken to >=9.0.0 — rejects alg:none by default even without option.
// Fix 3: Set issuer and audience options to prevent cross-service token reuse.

import jwt from 'jsonwebtoken';  // must be >=9.0.0

const JWT_SECRET  = process.env.JWT_SECRET;
const JWT_ISSUER  = 'skillaudit.dev';
const JWT_AUDIENCE = 'skillaudit-api';

function requireAuth(req, res, next) {
  const token = req.headers.authorization?.split(' ')[1];
  if (!token) return res.status(401).json({ error: 'No token' });

  try {
    // FIX 1: Explicit algorithms allowlist — rejects alg:none and any unexpected algorithm
    const payload = jwt.verify(token, JWT_SECRET, {
      algorithms: ['HS256'],    // only accept HS256 — reject RS256, none, ES256, etc.
      issuer:    JWT_ISSUER,    // FIX 3: reject tokens from other issuers
      audience:  JWT_AUDIENCE,  // FIX 3: reject tokens for other services
    });
    req.user = payload;
    next();
  } catch (err) {
    return res.status(401).json({ error: 'Invalid token' });
  }
}

Detection: SkillAudit scans for jwt.verify() calls that do not include an algorithms option in the options object. It also checks the installed version of jsonwebtoken and flags versions below 9.0.0 that do not block alg:none by default.

PRIVESC4-002 — RS256-to-HS256 algorithm confusion using public key as HMAC secret

When a server uses RSA keys for JWT signing (RS256), it issues tokens signed with the RSA private key and verifies them with the RSA public key. The public key is intentionally public — often served at /.well-known/jwks.json. The attack arises when the same jwt.verify() call accepts both RS256 and HS256 tokens: an attacker downloads the public key, creates a new JWT with alg: "HS256", signs it using the RSA public key as the HMAC-SHA256 secret, and sends it. The server's jwt.verify(publicKey, ...) call now treats the public key as the HMAC secret and verifies the HS256 token successfully — the attacker's forged token passes verification.

// VULNERABLE — PRIVESC4-002
// Server uses RS256 (asymmetric) but jwt.verify() accepts both RS256 and HS256.
// Public key is available at /.well-known/jwks.json.
// Attacker signs forged JWT with alg:HS256 using the public key as the HMAC secret.
// jwt.verify(token, publicKey) verifies HS256 against the public key — attack succeeds.

import jwt from 'jsonwebtoken';
import fs from 'fs';

const PUBLIC_KEY = fs.readFileSync('./keys/public.pem');

function requireAuth(req, res, next) {
  const token = req.headers.authorization?.split(' ')[1];

  try {
    // VULNERABLE: algorithms not specified — accepts both RS256 and HS256.
    // When attacker sends HS256 token signed with the public key as HMAC secret,
    // jwt.verify(token, PUBLIC_KEY) interprets PUBLIC_KEY as HMAC secret and verifies it.
    const payload = jwt.verify(token, PUBLIC_KEY);
    req.user = payload;
    next();
  } catch {
    res.status(401).json({ error: 'Unauthorized' });
  }
}
// FIXED — PRIVESC4-002
// Fix 1: Specify algorithms: ['RS256'] — jwt.verify() rejects HS256-signed tokens outright.
// Fix 2: Never use the same key material for both asymmetric and HMAC algorithms.
// Fix 3: Separate key registries — RS256 public key for verification, separate HMAC secret.

import jwt from 'jsonwebtoken';
import fs from 'fs';

const PUBLIC_KEY  = fs.readFileSync('./keys/public.pem');
const HMAC_SECRET = process.env.JWT_HMAC_SECRET;  // separate secret for HS256, never the RSA public key

function requireAuth(req, res, next) {
  const token = req.headers.authorization?.split(' ')[1];
  if (!token) return res.status(401).json({ error: 'No token' });

  try {
    // FIX 1: Explicit RS256 — rejects any HS256 token, including the key-confusion attack
    const payload = jwt.verify(token, PUBLIC_KEY, {
      algorithms: ['RS256'],  // FIX 1: reject HS256, none, ES256, and all other algorithms
      issuer:     'skillaudit.dev',
      audience:   'skillaudit-api',
    });
    req.user = payload;
    next();
  } catch {
    res.status(401).json({ error: 'Unauthorized' });
  }
}

PRIVESC4-003 — JWT kid header SQL injection in key lookup

The JWT standard allows a kid (key ID) header field that hints which key to use for verification — useful when a server rotates keys and needs to look up which public key corresponds to a given token. When the server uses kid to query a database for the signing key, and the query is built by string concatenation, an attacker can inject SQL through the kid header. The JWT header is base64url-encoded by the attacker and not validated before the database query. The SQL injection can return an arbitrary key (the attacker's public key), after which the attacker signs a forged JWT with the corresponding private key and the server verifies it successfully.

// VULNERABLE — PRIVESC4-003
// JWT kid header value used in SQL query without validation or parameterization.
// Attacker crafts JWT with kid: "' UNION SELECT attacker_public_key-- "
// SQL injection returns attacker's public key — server verifies attacker-signed token.

import jwt from 'jsonwebtoken';
import db from './db.js';

async function verifyToken(token) {
  // Decode header without verification to get kid
  const decoded = jwt.decode(token, { complete: true });
  const kid = decoded?.header?.kid;

  // VULNERABLE: kid is from token header — not validated, used in string-concatenated SQL
  const row = db.prepare(`SELECT public_key FROM signing_keys WHERE id = '${kid}'`).get();
  if (!row) throw new Error('Unknown key ID');

  // jwt.verify with SQL-injected key — attacker controls which key is used
  return jwt.verify(token, row.public_key, { algorithms: ['RS256'] });
}
// FIXED — PRIVESC4-003
// Fix 1: Validate kid format (UUID v4) before any database query — reject unexpected formats.
// Fix 2: Use parameterized query — prevents SQL injection regardless of kid content.
// Fix 3: Allowlist kid values against a known set rather than accepting any DB-stored value.

import jwt from 'jsonwebtoken';
import db from './db.js';

const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;

async function verifyToken(token) {
  const decoded = jwt.decode(token, { complete: true });
  const kid = decoded?.header?.kid;

  // FIX 1: Validate kid is a UUID before touching the database
  if (!kid || !UUID_RE.test(kid)) {
    throw new Error('Invalid or missing kid header');
  }

  // FIX 2: Parameterized query — kid value never interpolated into SQL string
  const row = db.prepare('SELECT public_key FROM signing_keys WHERE id = ? AND active = 1').get(kid);
  if (!row) throw new Error('Unknown or inactive key ID');

  return jwt.verify(token, row.public_key, {
    algorithms: ['RS256'],
    issuer:     'skillaudit.dev',
    audience:   'skillaudit-api',
  });
}

Detection: SkillAudit scans for JWT decode calls that extract header fields (kid, alg, jku, x5u) followed by those values being used in database queries or HTTP fetches. It flags cases where the kid value is not validated against a format constraint before use.

PRIVESC4-004 — exp claim not validated in custom JWT verification path

The standard jwt.verify() function validates the exp (expiry) claim automatically and throws TokenExpiredError if the token is expired. However, some MCP skill codebases implement custom JWT verification for performance (caching decoded tokens) or for multi-issuer support. These custom paths often call jwt.verify() with ignoreExpiration: true and then manually check expiry — but the manual check is sometimes omitted, left as a TODO, or removed in a refactor. Users whose accounts are downgraded from Pro to Free retain valid JWT signatures; without expiry validation, their old Pro tokens continue to authorize Pro-tier API calls indefinitely.

// VULNERABLE — PRIVESC4-004
// Custom JWT verification path uses ignoreExpiration:true but never checks exp manually.
// User's Pro token expires, but the custom middleware doesn't validate exp claim.
// Expired Pro token continues to grant access to Pro-only endpoints.

import jwt from 'jsonwebtoken';
import NodeCache from 'node-cache';

const tokenCache = new NodeCache({ stdTTL: 300 });

function verifyTokenCached(token) {
  const cached = tokenCache.get(token);
  if (cached) return cached;

  // VULNERABLE: ignoreExpiration:true was added when cache was introduced.
  // The comment says "we check exp below" but the check was never implemented.
  const payload = jwt.verify(token, process.env.JWT_SECRET, {
    algorithms: ['HS256'],
    ignoreExpiration: true,  // VULNERABLE: expiry not enforced anywhere in this path
  });

  // TODO: check payload.exp — this was never implemented
  tokenCache.set(token, payload);
  return payload;
}
// FIXED — PRIVESC4-004
// Fix 1: Remove ignoreExpiration:true — let jwt.verify() enforce expiry.
// Fix 2: If caching is needed, cache with TTL = min(remaining token lifetime, cache TTL).
// Fix 3: If custom exp check is needed, always compare payload.exp * 1000 > Date.now().

import jwt from 'jsonwebtoken';
import NodeCache from 'node-cache';

const tokenCache = new NodeCache({ stdTTL: 60 });

function verifyTokenCached(token) {
  const cached = tokenCache.get(token);
  if (cached) return cached;

  // FIX 1: No ignoreExpiration — jwt.verify() throws TokenExpiredError for expired tokens
  const payload = jwt.verify(token, process.env.JWT_SECRET, {
    algorithms: ['HS256'],
    issuer:     'skillaudit.dev',
    audience:   'skillaudit-api',
    // ignoreExpiration removed — expiry enforced by default
  });

  // FIX 2: Cache with TTL = remaining token lifetime, capped at 60s
  const remainingMs = (payload.exp * 1000) - Date.now();
  if (remainingMs > 0) {
    const cacheTtl = Math.min(Math.floor(remainingMs / 1000), 60);
    tokenCache.set(token, payload, cacheTtl);
  }

  return payload;
}

// FIX 3: Defensive exp check as a belt-and-suspenders measure in middleware
function requireAuth(req, res, next) {
  const token = req.headers.authorization?.split(' ')[1];
  if (!token) return res.status(401).json({ error: 'No token' });

  try {
    const payload = verifyTokenCached(token);

    // FIX 3: Explicit exp check as defense-in-depth — catches edge cases in caching
    if (!payload.exp || payload.exp * 1000 < Date.now()) {
      return res.status(401).json({ error: 'Token expired' });
    }

    req.user = payload;
    next();
  } catch (err) {
    return res.status(401).json({ error: 'Invalid or expired token' });
  }
}

Summary — SA-SKL-PRIVESC4 at a glance

PatternRoot causeFixSeverity
PRIVESC4-001jwt.verify() without algorithms option; attacker forges token with alg:none, strips signature; server accepts unsigned token; arbitrary payload including role:adminAlways pass algorithms: ['HS256'] or ['RS256']; upgrade jsonwebtoken to >=9.0.0; set issuer and audience optionsCritical
PRIVESC4-002Server accepts both RS256 and HS256; public RSA key is public; attacker signs HS256 token with public key as HMAC secret; jwt.verify(publicKey) treats it as HMAC secret and accepts the forged tokenSpecify algorithms: ['RS256'] exclusively; never use same key material for both asymmetric and HMAC algorithmsCritical
PRIVESC4-003kid header value from JWT used in string-concatenated SQL query; SQL injection returns attacker-controlled key; server verifies attacker-signed token against their injected keyValidate kid as UUID format before DB query; use parameterized query for key lookup; limit to active keys onlyHigh
PRIVESC4-004ignoreExpiration: true set for caching path; manual exp check never implemented; expired Pro tokens continue to grant Pro-tier access after account downgrade or token theftRemove ignoreExpiration; cache with TTL capped at remaining token lifetime; add explicit exp * 1000 > Date.now() check as defense-in-depthHigh
SkillAudit

Does your MCP skill's JWT authentication protect against algorithm confusion attacks?

SkillAudit scans for jwt.verify() calls without an explicit algorithms option, RS256/HS256 key confusion risks, SQL-injectable kid header lookups, and missing exp validation in custom verification paths — before an attacker forges a token and escalates to admin.

Audit your MCP skill →