← Blog

Claude MCP skill privilege escalation — skill access control policy and permission grant management endpoints (SA-SKL-PRIVESC58)

SA-SKL-PRIVESC58 identifies four privilege escalation vulnerabilities in MCP skill registry skill access control policy and permission grant management endpoints. The access policy enforcement middleware reads the user's access policy identifier from the JWT accessPolicyId claim rather than from the database, allowing an attacker who can forge or modify a JWT to reference any policy ID in the system including admin-level policies that grant cross-skill read access across the entire registry, permission override capability for any skill's access control rules, and read access to the registry's full audit log; the policy assignment endpoint is missing a policy boundary check that prevents users from assigning policies with higher privilege than their current policy, allowing any authenticated user to assign an admin-level access policy to themselves via a direct POST request; the policy configuration endpoint is missing an ownership check requiring registry admin role, allowing any authenticated user to modify the global access policy definitions including permission grant thresholds and audit log retention settings that govern all users in the registry; and the access policy cache key uses only the user identifier without incorporating the access policy version identifier, causing revoked or downgraded access policies to remain cached and enforced at the previously-cached privilege level until the cache TTL expires.

SA-SKL-PRIVESC58 findings at a glance
CRITICALPRIVESC58-001 — Access policy read from JWT accessPolicyId claim — craft JWT with accessPolicyId referencing admin-level policy grants cross-skill read access, permission override capability, and audit log access
CRITICALPRIVESC58-002 — POST /api/registry/access/policy/assign missing policy boundary check — any authenticated user assigns admin-level access policy to themselves
HIGHPRIVESC58-003 — PATCH /api/registry/access/policy/config missing ownership check — any authenticated user modifies global access policy definitions, permission grant thresholds, and audit log retention settings
MEDIUMPRIVESC58-004 — Access policy cache key uses userId without accessPolicyVersionId — cache entries bleed across policy upgrades; revoked access policies retained until TTL expiry

PRIVESC58-001 — JWT accessPolicyId claim enables arbitrary policy escalation

The access control policy middleware resolves the user's current access policy by reading the accessPolicyId field from the JWT payload and looking up the corresponding policy document from a cache layer. The JWT is signed with the registry's signing key and the signature is verified before the payload is trusted, but the payload content itself is fully attacker-controlled — a user who obtains or crafts a valid JWT can set accessPolicyId to any policy identifier in the system. The admin-level access policy in the registry grants three capabilities not available to standard users: cross-skill read access that bypasses the per-skill ownership check, permission override capability that allows modifying any skill's access control rules regardless of ownership, and read access to the registry's full audit log including security events, policy changes, and authentication failures across all users.

An attacker who discovers the UUID of an admin-level policy — through the registry's public policy documentation, by enumerating the policy assignment history API, or by reading policy IDs from other public registry responses — can craft a JWT with accessPolicyId set to that UUID. If the attacker has a valid session token, many JWT-based systems allow the user to control the JWT claims by calling the token refresh endpoint with a modified claims set. The access policy middleware trusts the claim, looks up the admin policy, and grants the attacker admin-level access for the lifetime of the token.

Vulnerable
// PRIVESC58-001 — VULNERABLE
function accessPolicyMiddleware(req, res, next) {
  const token = req.headers.authorization?.slice(7);
  const payload = jwt.verify(token, process.env.JWT_SECRET);
  // VULNERABLE: accessPolicyId is taken from the JWT payload (attacker-controlled)
  const policyId = payload.accessPolicyId;
  req.context.accessPolicy = policyCache.get(`policy:${policyId}`)
    ?? db.accessPolicies.findById(policyId);
  next();
}

Attack PoC — PRIVESC58-001: Attacker crafts a JWT with accessPolicyId referencing the admin policy UUID. The middleware trusts the claim, loads the admin policy, and grants cross-skill read access, permission override capability, and full audit log access for the token's lifetime.

// PRIVESC58-001 — ATTACK PoC
// Attacker discovers admin policy UUID from public policy docs or enumeration
const ADMIN_POLICY_ID = 'f47ac10b-58cc-4372-a567-0e02b2c3d479';

// Attacker modifies JWT claims at token refresh endpoint:
const refreshResp = await fetch('/api/auth/token/refresh', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    refreshToken: validRefreshToken,
    claims: { accessPolicyId: ADMIN_POLICY_ID },
  }),
});
const { accessToken } = await refreshResp.json();
// accessToken now carries admin-level cross-skill read and audit log access
Fixed
// PRIVESC58-001 — FIXED
async function accessPolicyMiddleware(req, res, next) {
  const token = req.headers.authorization?.slice(7);
  const payload = jwt.verify(token, process.env.JWT_SECRET);
  // FIXED: JWT carries only sub (userId); policy ID looked up from DB, never from JWT
  const userId = payload.sub;
  const cacheKey = `policy:${userId}`;
  let policyAssignment = policyCache.get(cacheKey);
  if (!policyAssignment) {
    policyAssignment = await db.policyAssignments.findOne({
      where: { userId },
      select: { accessPolicyId: true, accessPolicyVersionId: true },
    });
    policyCache.set(cacheKey, policyAssignment, { ttl: 300 });
  }
  req.context.accessPolicy = await db.accessPolicies.findById(
    policyAssignment.accessPolicyId
  );
  next();
}

PRIVESC58-002 — Missing policy boundary check enables self-assignment of admin access policy

The policy assignment endpoint at POST /api/registry/access/policy/assign allows users to assign an access policy to themselves or to users they manage. The endpoint validates that the requesting user is authenticated and that the target user identifier is valid, but it does not check whether the policy being assigned has a higher privilege level than the requesting user's current policy. The registry defines a strict hierarchy of access policy tiers: viewer can read public skills, contributor can publish skills, reviewer can review and approve skill submissions, policy_admin can assign policies up to their own level, and registry_admin can assign any policy including registry_admin itself. The boundary check that prevents a contributor from assigning a registry_admin policy is simply absent.

Any authenticated user — including a free-tier contributor who has never been granted elevated access — can call the policy assignment endpoint with their own userId as the target and registry_admin as the target policy. The endpoint processes the assignment without restriction and returns a success response. The user's subsequent requests are evaluated against the registry_admin policy, granting full administrative access to the registry including the ability to approve skill submissions, modify global access policies, and read the full audit log.

Vulnerable
// PRIVESC58-002 — VULNERABLE
router.post('/api/registry/access/policy/assign', requireSession, async (req, res) => {
  const { targetUserId, accessPolicyId } = req.body;
  // VULNERABLE: no check that the target policy's privilege level is ≤ caller's current level
  await db.policyAssignments.upsert({
    where:  { userId: targetUserId },
    update: { accessPolicyId },
    create: { userId: targetUserId, accessPolicyId },
  });
  policyCache.del(`policy:${targetUserId}`);
  res.json({ assigned: true });
});

Attack PoC — PRIVESC58-002: Attacker with contributor-level access assigns the registry_admin policy to themselves. The endpoint processes the assignment without a privilege boundary check. Attacker's next request is evaluated at registry_admin level, granting full administrative access.

// PRIVESC58-002 — ATTACK PoC
const REGISTRY_ADMIN_POLICY_ID = 'a1b2c3d4-e5f6-7890-abcd-ef1234567890';
await fetch('/api/registry/access/policy/assign', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    targetUserId: attackerUserId,
    accessPolicyId: REGISTRY_ADMIN_POLICY_ID,
  }),
});
// Attacker now has registry_admin access — full control of skill registry
Fixed
// PRIVESC58-002 — FIXED
const ACCESS_POLICY_ORDER = {
  viewer: 0, contributor: 1, reviewer: 2, policy_admin: 3, registry_admin: 4,
};

const AccessPolicyAssignSchema = z.object({
  targetUserId:   z.string().uuid(),
  // FIXED: exclude registry_admin from assignable enum for non-registry_admin callers
  accessPolicyId: z.string().uuid(),
});

router.post('/api/registry/access/policy/assign', requireSession, async (req, res) => {
  const { targetUserId, accessPolicyId } = AccessPolicyAssignSchema.parse(req.body);
  // FIXED: prevent self-assignment
  if (targetUserId === req.session.userId) {
    return res.status(403).json({ error: 'Self-assignment of access policy is not allowed' });
  }
  const [callerPolicy, targetPolicy] = await Promise.all([
    db.accessPolicies.findById(req.context.accessPolicy.id),
    db.accessPolicies.findById(accessPolicyId),
  ]);
  // FIXED: policy boundary check — caller cannot assign higher privilege than their own
  const callerLevel = ACCESS_POLICY_ORDER[callerPolicy.tier] ?? -1;
  const targetLevel = ACCESS_POLICY_ORDER[targetPolicy.tier] ?? 999;
  if (targetLevel > callerLevel) {
    return res.status(403).json({ error: 'Cannot assign policy with higher privilege than your own' });
  }
  await db.policyAssignments.upsert({
    where:  { userId: targetUserId },
    update: { accessPolicyId },
    create: { userId: targetUserId, accessPolicyId },
  });
  policyCache.del(`policy:${targetUserId}`);
  await auditLog.record({ action: 'policy.assign', by: req.session.userId, to: targetUserId, policyId: accessPolicyId });
  res.json({ assigned: true });
});

PRIVESC58-003 — Missing ownership check on policy config endpoint allows global policy modification

The policy configuration endpoint at PATCH /api/registry/access/policy/config allows modifying the global access policy definitions, including the permission grant thresholds that determine what actions each policy tier is authorized to perform and the audit log retention settings that determine how long security events are retained. This endpoint is intended to be accessible only to users with the registry_admin policy, but the ownership check validating that the requesting user holds that policy tier is absent. Any authenticated user can call this endpoint and modify global policy configuration.

The most immediately exploitable modification is lowering the autoGrantThreshold for a target policy tier — the minimum contributor reputation score required for automatic policy promotion — to zero, combined with self-assigning the target policy tier via PRIVESC58-002. An attacker can also modify the audit log retention period to zero days, causing the audit log retention job to delete all existing security events, eliminating evidence of prior unauthorized access. Changes to global permission grant thresholds affect all users in the registry simultaneously and take effect immediately after the policy version is incremented.

Vulnerable
// PRIVESC58-003 — VULNERABLE
router.patch('/api/registry/access/policy/config', requireSession, async (req, res) => {
  // VULNERABLE: missing requireRole('registry_admin') — any authenticated user reaches here
  const { policyTier, updates } = req.body;
  await db.accessPolicies.update({
    where: { tier: policyTier },
    data:  updates, // VULNERABLE: no field allowlist — attacker can modify any policy field
  });
  res.json({ updated: true });
});

Attack PoC — PRIVESC58-003: Attacker sets autoGrantThreshold for registry_admin tier to 0, enabling automatic promotion of any contributor to registry_admin. Also sets auditLogRetentionDays to 0, triggering deletion of all existing audit log entries to erase evidence.

// PRIVESC58-003 — ATTACK PoC
// Modify registry_admin auto-grant threshold to 0 (self-promote any contributor)
await fetch('/api/registry/access/policy/config', {
  method: 'PATCH',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    policyTier: 'registry_admin',
    updates: { autoGrantThreshold: 0, auditLogRetentionDays: 0 },
  }),
});
// All future contributors with reputation ≥ 0 are automatically promoted to registry_admin
// All audit log entries are deleted by the next retention job
Fixed
// PRIVESC58-003 — FIXED
const { z } = require('zod');

const PolicyConfigUpdateSchema = z.object({
  policyTier:               z.enum(['viewer', 'contributor', 'reviewer', 'policy_admin']),
  // FIXED: registry_admin tier excluded — cannot be modified except by out-of-band process
  autoGrantThreshold:       z.number().int().min(1).max(1000).optional(),
  auditLogRetentionDays:    z.number().int().min(30).max(3650).optional(),
  maxSkillsPerUser:         z.number().int().min(1).max(500).optional(),
});

router.patch(
  '/api/registry/access/policy/config',
  requireSession,
  requireRole('registry_admin'), // FIXED: ownership check added
  async (req, res) => {
    const updates = PolicyConfigUpdateSchema.parse(req.body);
    const before = await db.accessPolicies.findOne({ where: { tier: updates.policyTier } });
    await db.accessPolicies.update({
      where: { tier: updates.policyTier },
      data:  updates,
    });
    // FIXED: bump policy version to invalidate all cached policy entries
    await db.policyVersion.increment();
    await auditLog.record({
      action: 'policy.config.update',
      by:     req.session.userId,
      before, after: updates,
    });
    res.json({ updated: true });
  }
);

PRIVESC58-004 — Access policy cache key without policyVersionId causes privilege bleed across upgrades

The access policy cache keys policy documents using only the user identifier — policy:<userId> — without incorporating the access policy version identifier. When the registry performs a policy upgrade that modifies the capabilities of an existing policy tier or revokes a user's elevated access by assigning them to a lower-tier policy, the cache continues to serve the old policy document for all users whose entries remain in cache until their individual TTL expires. The standard cache TTL is 15 minutes, meaning revoked users retain their elevated access for up to 15 minutes after the revocation event.

The most dangerous scenario is a security incident response: when a user account is compromised and the registry admin immediately downgrades the account's access policy to viewer to limit the attacker's access, the attacker continues to operate with the original elevated policy for the full remaining cache TTL. If the original policy was registry_admin and the TTL has 14 minutes remaining, the attacker retains full administrative access for another 14 minutes during which they can perform additional damage, extract data, or create backdoor accounts before the cache expires and the revocation takes effect.

Vulnerable
// PRIVESC58-004 — VULNERABLE
async function getAccessPolicy(userId) {
  // VULNERABLE: cache key uses only userId — policy version changes are not reflected
  const cacheKey = `policy:${userId}`;
  const cached = await policyCache.get(cacheKey);
  if (cached) return cached;
  const assignment = await db.policyAssignments.findOne({ where: { userId } });
  const policy = await db.accessPolicies.findById(assignment.accessPolicyId);
  await policyCache.set(cacheKey, policy, { ttl: 900 }); // 15 minute TTL
  return policy;
}

Attack PoC — PRIVESC58-004: Admin revokes attacker's registry_admin access after detecting compromise. Due to the userId-only cache key, the attacker continues using the cached registry_admin policy for up to 15 minutes — enough time to create backdoor accounts or extract sensitive data before revocation takes effect.

// PRIVESC58-004 — ATTACK PoC (bleed window exploitation)
// 1. Admin revokes attacker's registry_admin access (assigns 'viewer' policy)
// 2. Attacker's cache entry still holds registry_admin policy for up to 15 minutes
// 3. Attacker continues using admin endpoints during bleed window:
const compD = await fetch('/api/registry/users?role=registry_admin', {
  headers: { Authorization: `Bearer ${attackerToken}` },
});
// Returns admin user list — bleed window still active despite revocation
Fixed
// PRIVESC58-004 — FIXED
async function getAccessPolicy(userId) {
  // FIXED: load current policyVersionId first; include in cache key
  const assignment = await db.policyAssignments.findOne({
    where:  { userId },
    select: { accessPolicyId: true, accessPolicyVersionId: true },
  });
  // FIXED: cache key = policyVersionId:userId — policy upgrades increment version,
  //        instantly invalidating all entries from the previous version
  const cacheKey = `policy:${assignment.accessPolicyVersionId}:${userId}`;
  const cached = await policyCache.get(cacheKey);
  if (cached) return cached;
  const policy = await db.accessPolicies.findById(assignment.accessPolicyId);
  await policyCache.set(cacheKey, policy, { ttl: 900 });
  return policy;
}

// On policy revocation — called by policy assignment endpoint:
async function onAccessPolicyRevoked(userId) {
  // FIXED: increment user's policyVersionId — all existing cache entries become orphans
  await db.policyAssignments.update({
    where: { userId },
    data:  { accessPolicyVersionId: { increment: 1 } },
  });
  // Old cache entries under old policyVersionId:userId key are never read again
  // Zero bleed — revocation is instantaneous from the perspective of the policy lookup
}

SkillAudit tip: Run a free audit on your MCP skill at skillaudit.dev to detect JWT claim-based privilege escalation, missing policy boundary checks, and cache-key versioning issues in your skill's access control policy management endpoints in under 60 seconds.