Claude MCP skill privilege escalation — skill API key and service account management endpoints — SA-SKL-PRIVESC26
SA-SKL-PRIVESC26 documents four privilege escalation vulnerabilities in MCP skill registry API key and service account management endpoints. API key management is a particularly sensitive escalation surface: a successful escalation yields long-lived credentials that persist beyond session expiry, survive password resets, and are frequently embedded in CI/CD systems where they execute with elevated trust. JWT claim forgery turns a user-controlled token field into a full admin access grant. Missing scope boundary enforcement at key creation lets any member minting a new key exceed their own role permissions. Missing ownership checks on service account modification enable cross-organizational privilege escalation. And sequential key ID reuse after rotation bleeds the previous key's cached scope to its successor.
apiKeyScopes[] claim; craft JWT with apiKeyScopes:['admin:all'] grants full admin API access without any database modificationPOST /api/keys missing scope boundary check; any authenticated user creates API keys with scopes exceeding their own role permissions, e.g., member creates key with admin:write scopePATCH /api/service-accounts/:id/permissions missing ownership check; any org member modifies any service account's permissions across all orgs; cross-org service account takeoverapiKeyId without orgId; revoked key's scope cache served to new key holder when sequential ID reused after rotationPRIVESC26-001 — JWT apiKeyScopes claim forgery grants full admin access
The API key authentication middleware reads the key's authorized scope list from the JWT apiKeyScopes claim rather than from the database. When an API request is made with a JWT, the middleware decodes the token, reads jwt.apiKeyScopes, and uses that array to determine what operations the key is authorized to perform. JWT claims can be set to arbitrary values by anyone who can mint a valid JWT — including the API key holder themselves, since the JWT is signed with the key's own HMAC secret.
An attacker who holds any valid API key crafts a new JWT for that key with apiKeyScopes: ['admin:all', 'org:write', 'audit:delete', 'billing:write']. The middleware reads this claim, populates the request's scope set with admin:all, and permits the request to proceed through all subsequent scope checks. The attacker gains full admin access to the registry API without modifying any database record — the attack leaves no trace in the API key table, the audit log, or the permission system, since it exploits the read path rather than the write path.
PRIVESC26-001 fix: Never read authorization data (scopes, roles, permissions) from JWT claims — JWTs are user-controlled. Store scopes in a DB-backed Map cache keyed on apiKeyId with a 60-second TTL. JWT carries only sub (the key ID). Invalidate the cache entry on key rotation or scope change. For high-security operations, skip the cache entirely and query the database directly.
function requireApiKeyScope(requiredScope) {
return (req, res, next) => {
const jwt = verifyJwt(req.headers.authorization);
// apiKeyScopes read from JWT — user-controlled
const scopes = new Set(jwt.apiKeyScopes);
if (!scopes.has(requiredScope) && !scopes.has('admin:all')) {
return res.status(403).json({ error: 'insufficient scope' });
}
next();
};
}
// DB-backed scope cache; JWT carries only sub (apiKeyId)
const scopeCache = new Map(); // apiKeyId → { scopes: Set, expiresAt: number }
async function getKeyScopes(apiKeyId) {
const cached = scopeCache.get(apiKeyId);
if (cached && cached.expiresAt > Date.now()) return cached.scopes;
const key = await db.getApiKey(apiKeyId);
if (!key || key.revokedAt) return null;
const scopes = new Set(key.scopes);
scopeCache.set(apiKeyId, { scopes, expiresAt: Date.now() + 60_000 });
return scopes;
}
function requireApiKeyScope(requiredScope) {
return async (req, res, next) => {
const jwt = verifyJwt(req.headers.authorization);
// JWT carries only apiKeyId — scopes loaded from DB-backed cache
const scopes = await getKeyScopes(jwt.sub);
if (!scopes || (!scopes.has(requiredScope) && !scopes.has('admin:all'))) {
return res.status(403).json({ error: 'insufficient scope' });
}
req.apiKeyId = jwt.sub;
next();
};
}
PRIVESC26-002 — Missing scope boundary check enables member creation of over-privileged keys
The API key creation endpoint POST /api/keys accepts a scopes array in the request body specifying which permissions the new key should hold. The endpoint validates that the user is authenticated but does not validate that the requested scopes are within the bounds of the requesting user's own role permissions. A member with skill:read and audit:run permissions can create an API key with scopes: ['admin:write', 'org:admin', 'billing:write']. The created key holds admin-level permissions despite being created by a non-admin user, and the key persists in the database across the user's session lifecycle — including after the user's role is downgraded or their account is suspended.
This vulnerability is particularly impactful because API keys are the primary integration credential for CI/CD pipelines. A member who anticipates being downgraded (or who has already been notified of a pending role change) can pre-create an over-privileged API key before the demotion takes effect. The key survives the role change and continues to authorize admin-level operations indefinitely until explicitly revoked by an administrator who knows to look for it.
PRIVESC26-002 fix: At key creation time, resolve the requesting user's current role permissions from the database. Validate that every scope in the requested scopes array is a subset of the user's current permissions. Reject the request with 403 Forbidden if any requested scope exceeds the user's permissions. Emit an audit log entry on every key creation including the creating user's role and the granted scopes.
// WRONG — no scope boundary check; any user creates any-scoped key
router.post('/api/keys', requireSession, async (req, res) => {
const key = await db.createApiKey(req.session.userId, req.body.scopes);
res.json(key);
});
// RIGHT — scope boundary check against requesting user's permissions
router.post('/api/keys', requireSession, async (req, res) => {
const userPerms = await db.getUserPermissions(req.session.userId, req.session.orgId);
const userScopeSet = new Set(userPerms.scopes);
const requested = z.array(ScopeSchema).parse(req.body.scopes);
const forbidden = requested.filter(s => !userScopeSet.has(s) && !userScopeSet.has('admin:all'));
if (forbidden.length > 0) {
return res.status(403).json({ error: 'requested scopes exceed your permissions', forbidden });
}
const key = await db.createApiKey(req.session.userId, req.session.orgId, requested);
await audit.log('api_key_created', { keyId: key.id, createdBy: req.session.userId, scopes: requested, creatorRole: userPerms.role });
res.json(key);
});
PRIVESC26-003 — Missing ownership check enables cross-org service account modification
The service account permission update endpoint PATCH /api/service-accounts/:id/permissions modifies a service account's authorized permission set. The endpoint requires an authenticated session but does not verify that the target service account belongs to the requesting user's organization. Any authenticated member of any organization can modify the permissions of any service account in the entire registry system — including service accounts belonging to other organizations, service accounts used by platform administrators, and service accounts embedded in production CI/CD pipelines of unrelated organizations.
An attacker who discovers a high-value service account ID (via enumeration, information disclosure in audit logs, or a separate IDOR vulnerability) can grant that service account new permissions that benefit the attacker — for example, adding audit:export scope to a service account used by a competitor's CI pipeline and then using those credentials to export private audit reports. Alternatively, the attacker can revoke all permissions from a victim organization's CI service account, breaking their automated deployment pipeline.
PRIVESC26-003 fix: Before applying any permission change, verify that the target service account's orgId matches req.session.orgId. Require requireRole('admin') — service account permissions are administrative operations. Emit a full audit log entry including the before and after permission state. Apply the same scope boundary check from PRIVESC26-002 to prevent org admins from granting service accounts more permissions than they themselves hold.
// WRONG — no ownership check; any member modifies any service account
router.patch('/service-accounts/:id/permissions', requireSession, async (req, res) => {
await db.updateServiceAccountPermissions(req.params.id, req.body.permissions);
res.json({ ok: true });
});
// RIGHT — ownership check + admin role + audit log
router.patch('/service-accounts/:id/permissions',
requireSession,
requireRole('admin'),
async (req, res) => {
const sa = await db.getServiceAccount(req.params.id);
if (!sa || sa.orgId !== req.session.orgId) {
return res.status(403).json({ error: 'forbidden' });
}
const before = sa.permissions;
await db.updateServiceAccountPermissions(req.params.id, req.body.permissions);
await audit.log('service_account_permissions_changed', {
saId: req.params.id,
orgId: req.session.orgId,
changedBy: req.session.userId,
before,
after: req.body.permissions,
});
res.json({ ok: true });
}
);
PRIVESC26-004 — Org-less cache key bleeds revoked key scope to rotation successor
The API key last-used tracking cache uses apiKeyId as the cache key without including the orgId. Many registries use sequential integer IDs for API keys, issuing each new key an ID one higher than the previous. When an API key is revoked and the organization immediately creates a replacement key, the new key may receive the same numerical ID as the revoked key (after the ID counter wraps, is reset, or is allocated from a shared pool). The new key holder's first request reads the cache entry left by the revoked key — including the revoked key's scope set — and the authorization middleware uses the cached scopes instead of querying the database. If the revoked key had admin:all scope and the replacement key was intended to have only limited scopes, the new key holder receives unintended elevated access for up to 60 seconds.
PRIVESC26-004 fix: Namespace the cache key with both orgId and apiKeyId: cache key = `${orgId}:${apiKeyId}`. Explicitly invalidate the cache entry on key revocation and on rotation. Use a strict 30-second TTL rather than relying on explicit invalidation alone. Use UUID v4 or ULID for API key IDs to prevent sequential ID reuse.
// WRONG — cache key uses only apiKeyId; bleeds across rotation
const scopeCache = new Map(); // keyed on apiKeyId only
async function getKeyScopes(apiKeyId) {
if (scopeCache.has(apiKeyId)) return scopeCache.get(apiKeyId); // may serve revoked key's scopes
const key = await db.getApiKey(apiKeyId);
scopeCache.set(apiKeyId, { scopes: new Set(key.scopes), expiresAt: Date.now() + 60_000 });
return scopeCache.get(apiKeyId);
}
// RIGHT — cache key includes orgId; invalidated on revocation; 30s TTL; UUID IDs
const scopeCache = new Map(); // keyed on `${orgId}:${apiKeyId}`
async function getKeyScopes(orgId, apiKeyId) {
const cacheKey = `${orgId}:${apiKeyId}`;
const cached = scopeCache.get(cacheKey);
if (cached && cached.expiresAt > Date.now()) return cached.scopes;
const key = await db.getApiKey(apiKeyId, orgId); // orgId in WHERE clause
if (!key || key.revokedAt) { scopeCache.delete(cacheKey); return null; }
scopeCache.set(cacheKey, { scopes: new Set(key.scopes), expiresAt: Date.now() + 30_000 });
return scopeCache.get(cacheKey).scopes;
}
async function revokeApiKey(orgId, apiKeyId) {
await db.revokeApiKey(apiKeyId, orgId);
scopeCache.delete(`${orgId}:${apiKeyId}`); // explicit cache invalidation on revoke
}
SkillAudit scans for JWT-based scope authorization patterns, missing scope boundary enforcement on API key creation, absent ownership checks on service account modification endpoints, and org-unscoped cache keys in authentication middleware — the four patterns that make API key management a privilege escalation surface.
Scan your registry| Finding | Severity | Endpoint | Impact |
|---|---|---|---|
| PRIVESC26-001 | CRITICAL | JWT apiKeyScopes claim | Full admin API access via forged JWT claim; no database modification required; undetectable in audit logs |
| PRIVESC26-002 | CRITICAL | POST /api/keys | Members create over-privileged API keys before role downgrade; long-lived credential persists across session and account changes |
| PRIVESC26-003 | CRITICAL | PATCH /api/service-accounts/:id/permissions | Cross-org service account takeover; CI/CD pipeline disruption for victim organizations |
| PRIVESC26-004 | HIGH | API key scope cache (sequential IDs) | Revoked admin key's scope served to rotation successor for up to 60 seconds; unintended privilege elevation on new key |
See also: SA-SKL-PRIVESC25 (team membership and role assignment privilege escalation patterns) for related authorization vulnerabilities in the skill registry membership system.