Claude MCP skill privilege escalation — skill team membership and role assignment endpoints — SA-SKL-PRIVESC25
SA-SKL-PRIVESC25 documents four privilege escalation vulnerabilities in MCP skill registry team membership and role assignment endpoints. Team role management is a high-value target for privilege escalation because team owners typically inherit admin access to all skills the team manages. The four findings cover the full escalation surface: JWT claim forgery that grants owner access to any team, missing authorization checks on member addition that enable self-escalation, a multi-step orphan-then-promote attack that exploits missing owner count guards, and a permission cache key design flaw that bleeds access across org rename events.
teamRoles[] array claim; craft JWT with teamRoles:[{teamId:'any',role:'owner'}] grants team owner access to any team without DB verificationPOST /api/teams/:id/members missing admin role check; any team member adds themselves or any user to any team with any role, achieving self-escalation to team ownerPATCH /api/teams/:id/members/:userId/role missing final owner count check; admin demotes last owner to member, then promotes themselves; team owner orphaned with no recovery pathteamId without orgId; cache entries bleed across org rename — org A renames to org B's former slug and inherits org B's cached team permissionsPRIVESC25-001 — JWT teamRoles claim forgery grants team owner access
The team role authorization middleware reads the requesting user's team roles from the JWT payload's teamRoles array claim. Each entry in the array is an object with a teamId and a role field. When the middleware checks whether the requesting user is a team owner for the target team, it performs a simple array lookup: jwt.teamRoles.find(r => r.teamId === req.params.id && r.role === 'owner'). Because JWTs are signed but their payload is client-readable and forgeable without the signing secret, an attacker who obtains a valid JWT for any account can forge a new JWT payload containing teamRoles: [{teamId: <target>, role: 'owner'}] and sign it with a compromised or weak secret, gaining owner access to any team.
Even without forging the JWT signature, this pattern is dangerous: if the JWT signing secret is weak or reused across environments, the attack requires only a single jwt.sign() call with a crafted payload. And if the registry issues long-lived JWTs with static teamRoles claims, a user whose team role changes in the database continues to hold the old team role in their JWT until it expires — either retaining escalated access after a demotion or losing valid access after a promotion, depending on the direction of the change.
PRIVESC25-001 fix: Never read authorization-relevant claims from JWT payload fields. Store team roles in the database and look them up on each request using a short-TTL server-side Map cache keyed on userId+teamId. The JWT carries only sub and orgId. Invalidate the cache entry on any membership change event (member add, role change, member remove).
// Team role check reads from JWT claim — forgeable without DB verification
function requireTeamRole(role) {
return (req, res, next) => {
const teamId = req.params.id;
const hasRole = req.jwt.teamRoles?.some(r => r.teamId === teamId && r.role === role);
if (!hasRole) return res.status(403).json({ error: 'forbidden' });
next();
};
}
// DB-backed team role cache: key = userId:teamId, TTL = 60s
const teamRoleCache = new Map(); // { 'userId:teamId': { role, expiresAt } }
async function requireTeamRole(role) {
return async (req, res, next) => {
const teamId = req.params.id;
const userId = req.session.userId; // from verified session, not JWT claim
const cacheKey = `${userId}:${teamId}`;
let entry = teamRoleCache.get(cacheKey);
if (!entry || entry.expiresAt < Date.now()) {
const row = await db.query(
'SELECT role FROM team_members WHERE team_id = ? AND user_id = ?',
[teamId, userId]
);
entry = { role: row[0]?.role ?? null, expiresAt: Date.now() + 60_000 };
teamRoleCache.set(cacheKey, entry);
}
const ROLE_HIERARCHY = { member: 1, admin: 2, owner: 3 };
if (!entry.role || ROLE_HIERARCHY[entry.role] < ROLE_HIERARCHY[role]) {
return res.status(403).json({ error: 'forbidden' });
}
next();
};
}
PRIVESC25-002 — Missing admin check on member add enables self-escalation
The team member add endpoint POST /api/teams/:id/members is missing a role verification check on the requesting user. Any authenticated user who is a member of a team — even with the lowest-privilege member role — can POST to this endpoint and add themselves with role: 'owner' or add any other user with any role. The escalation requires only a single API call and is immediately effective: the team member can then use their new owner role to invite additional attacker-controlled accounts, modify team skill permissions, or demote the legitimate team owners.
The absence of a team membership check on the requesting user is an additional issue: a user who is not a member of the target team at all can add themselves to the team, gaining access to skills the team manages. This is a cross-team privilege escalation that bypasses the team isolation model entirely.
PRIVESC25-002 fix: Require requireTeamRole('admin') or requireTeamRole('owner') on the member add endpoint. Verify that the requesting user is a current member of the target team. Only allow an owner to add new owners; admins can add members and admins but not owners. Emit an audit log entry and notification to existing owners on every member add.
// WRONG — no role check; any user can add themselves as owner
router.post('/teams/:id/members', requireSession, async (req, res) => {
await db.addTeamMember(req.params.id, req.body.userId, req.body.role);
res.json({ ok: true });
});
// RIGHT — requireTeamRole('admin'); ownership check; audit log
router.post('/teams/:id/members',
requireSession,
await requireTeamRole('admin'), // requesting user must be team admin or owner
async (req, res) => {
const { userId, role } = req.body;
// Only owners can assign the owner role
if (role === 'owner') {
const isOwner = await checkTeamRole(req.session.userId, req.params.id, 'owner');
if (!isOwner) return res.status(403).json({ error: 'only owners can assign owner role' });
}
await db.addTeamMember(req.params.id, userId, role);
await audit.log('team_member_added', { teamId: req.params.id, addedUserId: userId, role, addedBy: req.session.userId });
res.json({ ok: true });
}
);
PRIVESC25-003 — Missing owner count check enables orphan-then-promote attack
The role assignment endpoint PATCH /api/teams/:id/members/:userId/role allows an admin to change any member's role. It does not verify whether the role change would leave the team without any owners. An attacker with admin role executes a two-step escalation: first, they demote the last team owner (the original founder) from owner to member; second, they promote themselves from admin to owner. After the first step, the team has no owner — the original founder can no longer demote the attacker or recover control. After the second step, the attacker is the sole team owner with full control over all skills the team manages.
This attack chain is particularly dangerous because each individual step appears authorized: an admin can legitimately change member roles, and the check that is missing (minimum owner count) is a constraint that only applies at the moment of demotion. Without that check, the two-step sequence is undetectable until after the original owner has already lost control.
PRIVESC25-003 fix: Before applying any role change that demotes an owner, count the remaining owners after the change. If the count would reach zero, reject the request. Require requireTeamRole('owner') specifically to demote another owner. Emit an audit log entry for every role change. Notify the affected user via email when their role changes.
// WRONG — no owner count check; two-step orphan-and-promote works
router.patch('/teams/:id/members/:userId/role', requireSession, async (req, res) => {
await db.setTeamMemberRole(req.params.id, req.params.userId, req.body.role);
res.json({ ok: true });
});
// RIGHT — owner count guard; owner-only for owner demotion; audit log
router.patch('/teams/:id/members/:userId/role',
requireSession,
await requireTeamRole('admin'),
async (req, res) => {
const { role } = req.body;
const targetUserId = req.params.userId;
const teamId = req.params.id;
const currentRole = await db.getTeamMemberRole(teamId, targetUserId);
if (currentRole === 'owner') {
// Only another owner can demote an owner
const isOwner = await checkTeamRole(req.session.userId, teamId, 'owner');
if (!isOwner) return res.status(403).json({ error: 'only owners can demote other owners' });
// Ensure at least one owner remains
const ownerCount = await db.countTeamOwners(teamId);
if (ownerCount <= 1) return res.status(400).json({ error: 'cannot demote last team owner' });
}
await db.setTeamMemberRole(teamId, targetUserId, role);
await audit.log('team_role_changed', { teamId, targetUserId, newRole: role, changedBy: req.session.userId });
res.json({ ok: true });
}
);
PRIVESC25-004 — Cache key without orgId bleeds permissions across org rename
The team permission cache uses teamId as the sole cache key: permCache.get(teamId). When an organization renames its URL slug, the team IDs within that org remain the same, but the org identity changes. If another organization subsequently adopts the former slug of the renamed org, the team permission cache entries from the previous org — which are keyed only on teamId — may not have expired yet. If the new org happens to have a team with the same teamId (possible in systems that derive team IDs from slugs rather than UUIDs), the new org's team inherits the cached permissions of the previous org's team.
Even in systems with UUID-based team IDs where the collision is unlikely, the design flaw is an indicator of a broader authorization model problem: permission decisions are being made from cached state that does not include the full isolation key (orgId), creating a class of potential permission bleed whenever cache invalidation is imperfect during org restructuring operations.
PRIVESC25-004 fix: Include orgId in every permission cache key: permCache.get(`${orgId}:${teamId}`). Invalidate all cache entries for an org's teams on any org rename, merge, or deletion event. Apply a strict TTL of 60 seconds regardless of event-based invalidation, as a defense-in-depth backstop.
// WRONG — cache key is teamId only; bleeds across org rename
const teamPerm = permCache.get(teamId);
// RIGHT — cache key includes orgId; invalidate on org rename; strict TTL
const cacheKey = `${req.session.orgId}:${teamId}`;
let teamPerm = permCache.get(cacheKey);
if (!teamPerm || teamPerm.expiresAt < Date.now()) {
teamPerm = {
permissions: await db.getTeamPermissions(req.session.orgId, teamId),
expiresAt: Date.now() + 60_000 // 60s TTL regardless of event invalidation
};
permCache.set(cacheKey, teamPerm);
}
// In org rename handler: invalidate all team cache entries for the org
async function onOrgRename(orgId) {
for (const [key] of permCache) {
if (key.startsWith(`${orgId}:`)) permCache.delete(key);
}
}
SkillAudit scans for JWT claim-based role checks, missing role guards on team mutation endpoints, absent owner-count constraints on role demotion paths, and cache key patterns missing the org isolation dimension across all team membership and role assignment handlers in your MCP skill registry codebase.
Scan your registry| Finding | Severity | Endpoint | Impact |
|---|---|---|---|
| PRIVESC25-001 | CRITICAL | JWT teamRoles[] claim | Owner access to any team via forged JWT payload; role changes not reflected until token expiry |
| PRIVESC25-002 | CRITICAL | POST /api/teams/:id/members | Self-escalation to team owner; cross-team member addition by non-members |
| PRIVESC25-003 | HIGH | PATCH /api/teams/:id/members/:userId/role | Orphan-then-promote: last owner demoted, attacker becomes sole team owner |
| PRIVESC25-004 | HIGH | Team permission cache | Permission bleed across org rename; stale access grants persist beyond intended scope |
See also: SA-SKL-PRIVESC24 (org ownership transfer privilege escalation patterns) and SA-SKL-CORS42 for the companion CORS vulnerabilities in permission and ACL endpoints that can be chained with team role escalation to gain persistent access to private skills.