Claude MCP skill broken authentication via API key scope bypass and service account privilege escalation — SA-SKL-AUTH10
MCP skill platforms issue API keys to developers for programmatic access — to submit skills, trigger audits, read audit reports, and manage webhooks. These API keys are often wrapped in short-lived JWTs to reduce database load on every request. When the JWT's scope and permission claims are trusted at face value without re-fetching the authoritative scope from the database, an attacker who obtains a signing key — or whose JWT has been issued with an exploitable validation flaw — can forge elevated scope claims. SA-SKL-AUTH10 covers four API key authentication vulnerabilities: JWT scope claim not re-validated in DB, service account token accepted at user-only endpoints, key rotation that doesn't invalidate active sessions, and multi-tenant key reads that skip organization ID filtering.
scope: ["admin", "billing"]; if JWT signature is valid (attacker obtained signing key) or verification is misconfigured, forged scope grants admin access/api/users/me and receives admin-level user data from an elevated DB contextAUTH10-001 — API key scope in JWT claim, not re-validated in DB
MCP skill platforms issue long-lived API keys that are exchanged for short-lived JWTs at an authentication endpoint. The JWT includes the API key's authorized scopes as a claim — "scope": ["skills:read", "skills:write"] — to avoid a database lookup on every API request. The flaw arises when these scope claims are trusted without verification against the current state in the database. If an attacker obtains the JWT signing key (via a misconfigured secrets manager, a leaked environment variable, or the algorithm confusion attacks described in SA-SKL-PRIVESC4), they can forge a JWT with arbitrary scope claims. Even without the signing key, the absence of scope re-validation means that a scope downgrade — removing permissions from a key — only takes effect after the current JWT expires.
// VULNERABLE — JWT scope used directly without DB check
const authMiddleware = async (req, res, next) => {
const token = req.headers.authorization?.split(' ')[1];
const payload = jwt.verify(token, process.env.JWT_SECRET);
// Scope from JWT claim — never verified against DB
req.auth = {
apiKeyId: payload.sub,
organizationId: payload.org,
scope: payload.scope, // <-- attacker forges ["admin", "billing:write"]
};
next();
};
// Admin route trusts req.auth.scope without DB re-fetch:
app.get('/api/admin/users', requireScope('admin'), async (req, res) => {
const users = await db.users.findAll(); // No org filter — returns all users
res.json(users);
});
Performance vs. security tradeoff: The motivation for caching scope in the JWT is real — a DB lookup on every API request adds latency. The solution is not to remove DB validation entirely, but to cache the DB result at the application level with a short TTL (30–60 seconds). This bounds the propagation delay for scope changes while eliminating the JWT-forgery risk. Use a per-request-scoped cache (or Redis with a short TTL keyed by API key ID) rather than trusting the JWT claim directly.
// FIXED — re-fetch scope from DB; use short-lived cache
const scopeCache = new Map(); // keyId → { scope, expiresAt }
const authMiddleware = async (req, res, next) => {
const token = req.headers.authorization?.split(' ')[1];
const payload = jwt.verify(token, process.env.JWT_SECRET, {
algorithms: ['HS256'],
issuer: 'skillaudit.dev',
audience: 'api'
});
const keyId = payload.sub;
const cached = scopeCache.get(keyId);
let scope;
if (cached && cached.expiresAt > Date.now()) {
scope = cached.scope;
} else {
const apiKey = await db.apiKeys.findOne({ id: keyId, active: true });
if (!apiKey) return res.status(401).json({ error: 'API key revoked' });
scope = apiKey.scope;
scopeCache.set(keyId, { scope, expiresAt: Date.now() + 30_000 });
}
req.auth = { apiKeyId: keyId, organizationId: payload.org, scope };
next();
};
AUTH10-002 — Service account token accepted at user-only endpoints
MCP skill platforms often have two classes of API principals: user API keys (issued to developers via the dashboard) and service account tokens (used by CI/CD pipelines, the platform's own workers, and partner integrations). Service accounts frequently have broader database access than individual user keys — a service account might have a row-level security bypass to read across all organizations, or might be assigned a DBA role for schema migrations. When the authorization middleware treats service account tokens and user API key JWTs identically, service account tokens can be used to call user-scoped endpoints that implicitly trust the caller's organization context from the JWT.
// VULNERABLE — no distinction between user and service account tokens
const authMiddleware = async (req, res, next) => {
const token = req.headers.authorization?.split(' ')[1];
// jwt.verify() succeeds for both user JWTs and service account JWTs
const payload = jwt.verify(token, process.env.JWT_SECRET);
req.auth = { sub: payload.sub, org: payload.org, scope: payload.scope };
next();
};
// User profile endpoint — implicitly assumes caller is a user
app.get('/api/users/me', async (req, res) => {
// Service account token: payload.sub = 'sa_pipeline_prod'
// DB query uses service account's DB role (bypasses RLS) → returns all users
const user = await db.users.findOne({ id: req.auth.sub });
res.json(user);
});
// FIXED — check token type; reject service account tokens at user endpoints
const authMiddleware = async (req, res, next) => {
const token = req.headers.authorization?.split(' ')[1];
const payload = jwt.verify(token, process.env.JWT_SECRET, {
algorithms: ['HS256']
});
req.auth = {
sub: payload.sub,
org: payload.org,
scope: payload.scope,
tokenType: payload.typ // 'user' | 'service_account'
};
next();
};
// Middleware for user-only endpoints
function requireUserToken(req, res, next) {
if (req.auth.tokenType !== 'user') {
return res.status(403).json({ error: 'Service account tokens cannot access user endpoints' });
}
next();
}
app.get('/api/users/me', requireUserToken, async (req, res) => {
const user = await db.users.findOne({ id: req.auth.sub });
res.json(user);
});
AUTH10-003 — API key rotation doesn't invalidate active sessions
When a developer rotates their API key — typically after suspecting a key leak — the rotation endpoint generates a new key value and deactivates the old one in the database. However, any JWTs issued before the rotation remain valid until their exp claim expires. With a 15-minute JWT TTL, an attacker who obtained the old API key can continue making authenticated requests for up to 15 minutes after the rotation. For sensitive operations like billing changes, skill deletion, or webhook configuration updates, this window is long enough to cause significant damage.
// VULNERABLE — rotation deactivates key but doesn't track keyVersion
app.post('/api/keys/:keyId/rotate', async (req, res) => {
const newKey = generateApiKey();
await db.apiKeys.update(
{ id: req.params.keyId },
{ keyValue: newKey, rotatedAt: new Date() }
// Does NOT increment a version counter
);
res.json({ key: newKey });
});
// Auth middleware issues JWTs without keyVersion:
// jwt.sign({ sub: keyId, org: orgId, scope }, secret, { expiresIn: '15m' })
// Old JWT remains valid for 15 minutes after rotation — no way to invalidate
// FIXED — keyVersion counter; validated on each request
app.post('/api/keys/:keyId/rotate', async (req, res) => {
const newKey = generateApiKey();
const updated = await db.apiKeys.findOneAndUpdate(
{ id: req.params.keyId, organizationId: req.auth.organizationId },
{ $set: { keyValue: newKey }, $inc: { keyVersion: 1 } },
{ returnDocument: 'after' }
);
res.json({ key: newKey, version: updated.keyVersion });
});
// Auth middleware includes keyVersion in JWT, re-validates on each request
const authMiddleware = async (req, res, next) => {
const payload = jwt.verify(token, secret, { algorithms: ['HS256'] });
const apiKey = await db.apiKeys.findOne({ id: payload.sub, active: true });
if (apiKey.keyVersion !== payload.kv) {
return res.status(401).json({ error: 'API key has been rotated; please re-authenticate' });
}
next();
};
AUTH10-004 — Multi-tenant key reads cross-org data
Multi-tenant MCP skill platforms issue API keys that are scoped to a specific organization. The key's organization ID is validated when the key is authenticated — the middleware confirms the key exists and belongs to a valid organization. However, when API endpoints query resources by ID without filtering by organization ID, a valid API key for organization A can read organization B's data by guessing resource IDs. This is Broken Object Level Authorization (BOLA/IDOR) where the authorization check happens at key validation time but not at resource access time.
// VULNERABLE — organization ID check missing from resource queries
app.get('/api/audits/:auditId', async (req, res) => {
// req.auth.organizationId is set by middleware, but NOT used in the query
const audit = await db.audits.findOne({ id: req.params.auditId });
if (!audit) return res.status(404).json({ error: 'Audit not found' });
res.json(audit);
// Attacker with org-A API key fetches org-B's audit by guessing auditId
});
BOLA at scale: MCP skill platforms that use sequential integer IDs for audits, skills, and reports are especially vulnerable — an attacker with any valid API key can enumerate all resources across all organizations by iterating IDs. Use UUIDs (v4) for resource IDs to eliminate trivial enumeration, and always include the organization ID filter even with UUIDs — UUIDs reduce the feasibility of enumeration but do not make cross-org access impossible if IDs are exposed in other ways (error messages, audit logs, webhooks).
// FIXED — organization ID filter on every resource query
app.get('/api/audits/:auditId', async (req, res) => {
const audit = await db.audits.findOne({
id: req.params.auditId,
organizationId: req.auth.organizationId // <-- always filter by org
});
if (!audit) return res.status(404).json({ error: 'Audit not found' });
res.json(audit);
});
// For bulk queries, the same filter applies:
app.get('/api/audits', async (req, res) => {
const audits = await db.audits.find({
organizationId: req.auth.organizationId, // never omit this
...buildFilters(req.query)
});
res.json(audits);
});
Detection summary
| Finding | Severity | Root cause | Fix |
|---|---|---|---|
| AUTH10-001 | CRITICAL | JWT scope trusted, not re-fetched | DB scope re-fetch with short TTL cache |
| AUTH10-002 | CRITICAL | Service account at user endpoint | Token type check in requireUserToken |
| AUTH10-003 | HIGH | Rotation doesn't revoke JWT | keyVersion counter + validate per request |
| AUTH10-004 | CRITICAL | Missing org ID filter in queries | organizationId: req.auth.organizationId in every query |
SkillAudit scans MCP skill platform API implementations for all four AUTH10 patterns. Auth middleware that reads scope from JWT payload without a DB re-fetch call triggers AUTH10-001; routes that accept any JWT token without checking tokenType trigger AUTH10-002; rotate endpoints that don't increment a version counter trigger AUTH10-003; resource queries that accept a resource ID without an org ID filter in the WHERE clause trigger AUTH10-004. See also JWT algorithm confusion in MCP skill API authentication for the PRIVESC4 patterns that enable signing key theft, and SA-SKL-AUTH9 for race condition vulnerabilities in OAuth token exchange flows.