Claude MCP skill privilege escalation — skill API key scope and permission management endpoints — SA-SKL-PRIVESC30
SA-SKL-PRIVESC30 documents four privilege escalation vulnerabilities in MCP skill registry API key scope and permission management endpoints. API key scope management is a critical trust boundary: it determines which operations each API key is authorized to perform across the registry's API surface. PRIVESC30-001 exploits trust in JWT-embedded scope claims to forge a token that grants admin:all scope without possessing an actual admin API key. PRIVESC30-002 exploits a missing scope boundary check that allows any key holder to expand their key's scopes beyond what their account role permits. PRIVESC30-003 exploits a missing ownership check on the API key permissions endpoint that allows any authenticated user to modify any other account's API key permissions. PRIVESC30-004 exploits a cache key design flaw that causes elevated scope entries to bleed across key rotation — when a key is rotated and the new key receives the same sequential integer ID, the previous key's elevated cached scopes are served to the new key during the 60-second cache window.
apiKeyScopes claim; craft JWT with apiKeyScopes:['admin:all'] grants full admin API access without a real admin API key; fix: DB-backed 60s Map cache keyed on apiKeyId; JWT carries only subPOST /api/api-keys/:id/scopes missing scope boundary check; any key holder expands their own key's scopes beyond account role permits, escalating a read-only key to admin:all scopePATCH /api/api-keys/:id/permissions missing ownership check; any authenticated user modifies any other account's API key permissions without owning the target keykeyId without userId; scope cache entries bleed across key rotation: rotated key's elevated scopes served to new key with same sequential integer ID during 60s cache windowPRIVESC30-001 — JWT apiKeyScopes claim forgery escalates to admin:all without a real admin key
When the registry reads API key scopes directly from a JWT claim rather than from the authoritative database record, any user who can craft or obtain a JWT containing elevated scope claims gains the corresponding privileges — without possessing an API key that was actually granted those scopes by an administrator. JWT claims are only as trustworthy as the signing key: if the JWT is signed with a secret that has been compromised, rotated incorrectly, or is weak enough to brute-force, an attacker can forge a JWT containing apiKeyScopes: ["admin:all"]. This grants full administrative access to all API key management endpoints, skill publishing, permission delegation, and registry configuration.
The claim forgery attack is particularly accessible because JWT libraries frequently have algorithm confusion vulnerabilities (HS256/RS256 confusion, alg: none acceptance) that allow token forgery without knowledge of the signing secret. An attacker who can observe a legitimate JWT — from a browser's local storage, a network capture, or an application log — can attempt algorithm confusion to forge elevated-scope tokens. The attack is silent: the registry's access logs show the forged JWT's subject identifier making admin-level API calls with no anomalous credential activity visible at the key management layer.
PRIVESC30-001 fix: Never read authorization-relevant claims from JWTs. The JWT carries only sub (the authenticated user identifier) and an apiKeyId. All scope information is fetched from the database on each request, with a 60-second in-memory Map cache keyed on apiKeyId. Invalidate the cache entry immediately when scopes change. This ensures that scope grants require an actual database write authorized by an administrator — not a crafted token.
async function getApiKeyScopes(req) {
const decoded = jwt.verify(req.headers.authorization.split(' ')[1], JWT_SECRET);
return decoded.apiKeyScopes; // trusts JWT claim — forgeable
}
const scopeCache = new Map(); // keyId → { scopes, expiresAt }
async function getApiKeyScopes(req) {
const decoded = jwt.verify(req.headers.authorization.split(' ')[1], JWT_SECRET);
const { apiKeyId } = decoded; // JWT carries only identity, not scopes
const cached = scopeCache.get(apiKeyId);
if (cached && cached.expiresAt > Date.now()) return cached.scopes;
const { scopes } = await db.getApiKey(apiKeyId); // DB is authoritative
scopeCache.set(apiKeyId, { scopes, expiresAt: Date.now() + 60_000 });
return scopes;
}
function invalidateScopeCache(apiKeyId) {
scopeCache.delete(apiKeyId); // call on every scope change event
}
PRIVESC30-002 — Missing scope boundary check allows any key to escalate to admin:all
The scope expansion endpoint at POST /api/api-keys/:id/scopes allows API key owners to modify the scopes assigned to their own keys. Without a boundary check that validates whether the requested new scopes fall within the set of scopes permitted by the key owner's account role, any key holder can add arbitrary scopes to their key — including admin:all, billing:write, and org:delete — regardless of their actual role in the organization. A free-tier user with a read-only API key created for personal use can escalate it to full admin scope by submitting a scope expansion request that requests ["admin:all"].
The escalation is particularly hard to detect because the expanded scope appears as a legitimate configuration update in the registry's key management audit log. The key still belongs to the legitimate key owner — no account takeover occurred. The key's expanded scope is reflected in the database's authoritative scope record, so the PRIVESC30-001 fix (DB-backed scope lookup) does not prevent this escalation; the boundary check must be implemented independently at the scope expansion write path.
PRIVESC30-002 fix: At the scope expansion endpoint, fetch the key owner's account role and the set of scopes that role is permitted to grant. Validate that every scope in the requested expansion is a subset of the permitted scope set. Reject any request that includes a scope exceeding the requesting role's permission boundary. Apply a Zod ScopeSchema that enumerates all valid scope strings. Write an audit log entry on every scope change. Invalidate the scope cache for the modified key.
PRIVESC30-003 — Missing ownership check on API key permissions patch allows cross-account modification
The API key permissions endpoint at PATCH /api/api-keys/:id/permissions modifies the permission set for the specified API key. Without an ownership check verifying that the API key identified by :id belongs to the authenticated user's account, any authenticated registry user can modify any other user's API key permissions by enumerating :id values. This allows an attacker to expand the scopes of an admin user's API key (granting it additional permissions for the attacker's benefit), restrict the scopes of a competitor's API key (denying them access to their own registry operations), or disable API keys belonging to legitimate administrators ahead of a primary attack.
The lack of ownership check is particularly dangerous when combined with the scope expansion vulnerability in PRIVESC30-002. An attacker who first expands their own key to admin:all can then use that escalated key to modify permissions on any other account's keys without restriction. The compound attack — PRIVESC30-002 for initial escalation, PRIVESC30-003 for lateral movement — achieves registry-wide administrative control from an initial free-tier account.
PRIVESC30-003 fix: At the permissions patch endpoint, fetch the target API key record and verify that apiKey.userId === req.session.userId before applying any modifications. Add requireSession to ensure a valid session exists. Write an audit log entry on every permissions change. Invalidate the scope cache for the modified key.
router.patch('/api-keys/:id/permissions',
requireSession,
async (req, res) => {
// no ownership check — any user can patch any key
await db.updateApiKeyPermissions(req.params.id, req.body.permissions);
res.json({ updated: true });
}
);
router.patch('/api-keys/:id/permissions',
requireSession,
async (req, res) => {
const apiKey = await db.getApiKey(req.params.id);
if (!apiKey || apiKey.userId !== req.session.userId) {
return res.status(403).json({ error: 'forbidden' });
}
const permittedScopes = await db.getRolePermittedScopes(req.session.userId);
const requestedScopes = ScopeSchema.parse(req.body.permissions);
if (!requestedScopes.every(s => permittedScopes.includes(s))) {
return res.status(403).json({ error: 'scope_exceeds_role' });
}
await db.updateApiKeyPermissions(req.params.id, requestedScopes);
invalidateScopeCache(req.params.id);
await auditLog.write({ event: 'key_permissions_updated', keyId: req.params.id, actor: req.session.userId });
res.json({ updated: true });
}
);
PRIVESC30-004 — Scope cache key collision across key rotation serves elevated scopes to new keys
When API key IDs are assigned as sequential integers, key rotation — which creates a new key and immediately deletes the old one — produces a situation where the new key's integer ID eventually collides with a previously-deleted key's ID, particularly in registries that reuse integer sequences after key deletion. The scope cache is keyed only on keyId without including userId. During the 60-second cache window after the old key's elevated scopes were cached, a new key that receives the same integer ID will be served the previous key's elevated scope set from the cache — granting the new key privileges that were never explicitly assigned to it.
The collision scenario is most reliably exploitable in a targeted attack where the attacker knows a high-privilege key's ID, can cause that key to be rotated (through social engineering or by exploiting PRIVESC30-003), and immediately creates a new key hoping to receive the vacated ID before the cache entry expires. In registries with active key churn — teams that frequently rotate CI keys — the collision probability is non-negligible within a 60-second window. The fix requires both a compound cache key (userId:keyId) and an explicit cache invalidation on key rotation events, ensuring that no scope entry from the deleted key's history is ever served to a new key.
PRIVESC30-004 fix: Change the cache key from keyId to userId:keyId. On key rotation (delete old key, create new key), explicitly invalidate all cache entries for the old key's ID across all userIds by deleting keys matching the pattern *:oldKeyId. Use UUID v4 for API key IDs instead of sequential integers to eliminate ID reuse entirely. Apply a strict 60s TTL and always verify that the cached entry's userId matches the requesting session's userId before serving cached scopes.
// cache key = keyId only → bleeds across users who get same sequential ID const cached = scopeCache.get(apiKeyId); if (cached && cached.expiresAt > Date.now()) return cached.scopes;
// cache key = userId:keyId → no cross-user bleed
const cacheKey = `${req.session.userId}:${apiKeyId}`;
const cached = scopeCache.get(cacheKey);
if (cached && cached.expiresAt > Date.now()) {
// secondary check: ensure cached entry belongs to this user
if (cached.userId !== req.session.userId) {
scopeCache.delete(cacheKey);
} else {
return cached.scopes;
}
}
const { scopes, userId } = await db.getApiKey(apiKeyId);
if (userId !== req.session.userId) throw new Error('key ownership mismatch');
scopeCache.set(cacheKey, { scopes, userId, expiresAt: Date.now() + 60_000 });
return scopes;
SkillAudit scans your registry's API key scope and permission management endpoints for all four PRIVESC30 patterns, plus the full SA-SKL-PRIVESC series covering privilege escalation across every registry subsystem. Get started free — 3 audits/month on public repos, results in 60 seconds.