SA-SKL-PRIVESC14 — Privilege Escalation
Privilege Escalation in MCP Skill Registry Audit Plan Limits and Feature Gating
Plan limits and feature gating are the commercial boundary of an MCP skill registry audit product: they determine how deep a scan runs, how many concurrent audits are permitted, how long audit history is retained, and how many CI integrations a user can register. SA-SKL-PRIVESC14 covers four privilege escalation vulnerabilities that allow free-tier and starter-plan users to access paid-tier features by supplying depth parameters in request bodies, exploiting in-process counter resets via worker OOM, forging JWT claims for extended retention, and racing webhook registration limit checks.
req.body.depth rather than plan config — free-tier user sets depth:10 receiving deep LLM-assisted scan costing $12 per audit; fix: depth always determined server-side from subscription plan; request body depth parameter rejectedreq.user.planRetentionDays decoded from JWT — attacker crafts JWT with planRetentionDays:365 retaining 1 year of audit history on free tier (free limit: 7 days); fix: fetch retention from plan config not JWTSELECT COUNT(*) without FOR UPDATE — 100 concurrent registration requests all read count=0 and register, bypassing the free-tier 3-webhook limit; fix: SELECT FOR UPDATE in transaction + per-user creation rate limitPRIVESC14-001 — Audit depth from request body bypasses plan limit
The audit submission endpoint accepts a depth parameter that controls how many levels of dependency and behavioral analysis the scan performs. Higher depth values trigger LLM-assisted deep analysis, costing significantly more compute and API tokens per audit. The plan gating logic checks the subscription plan after reading the depth value from req.body.depth. Because the depth check only verifies a maximum allowed depth rather than substituting the plan-defined depth, a free-tier user who sets depth: 10 in the request body receives a full Pro-tier deep scan. The LLM analysis cost of a depth-10 scan (~$12) is charged to the platform, not the user.
// PRIVESC14-001 — VULNERABLE
// Audit depth read from req.body — free-tier user sets depth:10 and gets deep LLM scan.
const PLAN_MAX_DEPTH = { free: 2, pro: 5, team: 10 };
router.post('/audits', requireSession, async (req, res) => {
const depth = req.body.depth ?? 2; // VULNERABLE: depth from client request body
const maxAllowed = PLAN_MAX_DEPTH[req.user.plan] ?? 2;
if (depth > maxAllowed) {
return res.status(402).json({ error: `Depth ${depth} requires ${planForDepth(depth)} plan` });
}
// depth=10 passes check for team plan users, but free-tier users who know to send depth:2 also bypass
// Real issue: depth comes from body — free-tier user sends depth:3 when plan allows depth:2
const audit = await runAudit(req.body.skillId, { depth });
res.json(audit);
});
Fix: Never read plan-limited parameters from the request body. Determine the scan depth server-side from the user's current plan configuration fetched from the database. Ignore any depth field in the request body entirely. If users need to request a shallower scan for speed, allow only values less than or equal to the plan-defined maximum — never values that exceed the plan limit.
// PRIVESC14-001 — FIXED
const PLAN_DEPTH = { free: 2, pro: 5, team: 10 };
router.post('/audits', requireSession, async (req, res) => {
// Depth determined server-side from subscription plan — never from request body
const subscription = await db.subscriptions.findByUserId(req.user.sub);
const planSlug = subscription?.status === 'active' ? subscription.planSlug : 'free';
const depth = PLAN_DEPTH[planSlug] ?? PLAN_DEPTH.free; // server-side only
// User may request shallower scan (useful for quick checks) but not deeper
const requestedDepth = Number.isInteger(req.body.depth) ? req.body.depth : depth;
const effectiveDepth = Math.min(requestedDepth, depth); // cap at plan limit
const audit = await runAudit(req.body.skillId, { depth: effectiveDepth });
res.json(audit);
});
PRIVESC14-002 — In-process concurrent audit counter resets on worker restart
The free tier is limited to one concurrent audit per user. The concurrent audit limit is enforced using an in-process JavaScript counter: runningAudits.get(userId). This counter is stored in a Map in the worker process's heap. When the worker process is killed and restarted — which occurs naturally under memory pressure, OOM kill events, or when the Node.js process crashes — the in-memory counter resets to zero. A free-tier user can trigger an OOM kill (by submitting a large archive designed to exhaust the worker's memory) and then immediately submit ten audit requests in parallel. All ten requests read a counter of zero from the fresh process and proceed, allowing the user to run ten concurrent LLM-assisted scans on the free tier.
// PRIVESC14-002 — VULNERABLE
// In-process Map counter resets to 0 on worker restart — OOM bypasses concurrent limit.
const runningAudits = new Map(); // userId -> count — IN PROCESS MEMORY — resets on crash/restart
const PLAN_CONCURRENT_LIMIT = { free: 1, pro: 3, team: 10 };
async function startAudit(userId, planSlug, skillId) {
const current = runningAudits.get(userId) ?? 0; // VULNERABLE: 0 after any worker restart
const limit = PLAN_CONCURRENT_LIMIT[planSlug] ?? 1;
if (current >= limit) {
throw new Error(`Concurrent audit limit reached (${limit} for ${planSlug} plan)`);
}
runningAudits.set(userId, current + 1);
try {
return await runAudit(skillId);
} finally {
runningAudits.set(userId, (runningAudits.get(userId) ?? 1) - 1);
}
}
Fix: Use Redis atomic INCR/DECR with a TTL to track concurrent audits across all worker instances. The TTL ensures the counter expires if a worker crashes without decrementing (preventing permanent lock-out). Set the TTL to the maximum expected audit duration plus a safety margin. Use INCR and check the returned value atomically — if it exceeds the plan limit, immediately DECR and reject the request.
// PRIVESC14-002 — FIXED
const PLAN_CONCURRENT_LIMIT = { free: 1, pro: 3, team: 10 };
const AUDIT_MAX_DURATION_S = 300; // 5 minutes max audit duration
async function startAudit(userId, planSlug, skillId) {
const limit = PLAN_CONCURRENT_LIMIT[planSlug] ?? 1;
const redisKey = `audit:concurrent:${userId}`;
// Atomic INCR — survives worker crashes, shared across all worker instances
const current = await redis.incr(redisKey);
await redis.expire(redisKey, AUDIT_MAX_DURATION_S + 60); // TTL prevents permanent lockout on crash
if (current > limit) {
await redis.decr(redisKey); // undo the increment
throw new Error(`Concurrent audit limit reached (${limit} for ${planSlug} plan)`);
}
try {
return await runAudit(skillId);
} finally {
// Decrement counter when audit completes or fails
const remaining = await redis.decr(redisKey);
if (remaining < 0) await redis.set(redisKey, 0); // safety: never go negative
}
}
PRIVESC14-003 — JWT planRetentionDays claim bypasses history retention limit
The audit history cleanup job determines how far back to retain audit records for each user by reading req.user.planRetentionDays from the decoded JWT. The JWT is signed by the server, so its claims cannot be tampered with by passive observers. However, an attacker who obtains the JWT signing secret (via any credential exposure in this catalog) can craft a JWT with planRetentionDays: 365. When the cleanup job runs, it reads this value from the JWT and retains 365 days of audit history for the attacker's account rather than the 7-day free-tier limit. This keeps historical vulnerability data available to the attacker indefinitely without paying for a Pro plan.
// PRIVESC14-003 — VULNERABLE
// planRetentionDays read from JWT — attacker crafts JWT with planRetentionDays:365.
async function cleanupAuditHistory(userId, retentionDays) {
// VULNERABLE: retentionDays from JWT claim — not from plan config
const cutoff = new Date(Date.now() - retentionDays * 24 * 60 * 60 * 1000);
await db.audits.deleteOlderThan(userId, cutoff);
}
router.post('/audits/cleanup', requireSession, async (req, res) => {
// req.user.planRetentionDays decoded from JWT — attacker sets to 365 in crafted JWT
await cleanupAuditHistory(req.user.sub, req.user.planRetentionDays ?? 7);
res.json({ ok: true });
});
Fix: Never read plan parameters from the JWT. The JWT should contain only identity claims (sub, iat, exp). Fetch the user's plan and all associated plan limits server-side from the subscription database on every request that depends on them. Store the plan configuration in a central plan registry object so all plan parameters are consistent across the codebase.
// PRIVESC14-003 — FIXED
const PLAN_RETENTION_DAYS = { free: 7, pro: 90, team: 365 };
async function getUserRetentionDays(userId) {
// Always fetch from DB — never from JWT
const subscription = await db.subscriptions.findByUserId(userId);
const planSlug = subscription?.status === 'active' ? subscription.planSlug : 'free';
return PLAN_RETENTION_DAYS[planSlug] ?? PLAN_RETENTION_DAYS.free;
}
router.post('/audits/cleanup', requireSession, async (req, res) => {
// retentionDays from plan config (via DB), not from JWT
const retentionDays = await getUserRetentionDays(req.user.sub);
const cutoff = new Date(Date.now() - retentionDays * 24 * 60 * 60 * 1000);
await db.audits.deleteOlderThan(req.user.sub, cutoff);
res.json({ ok: true });
});
PRIVESC14-004 — CI webhook registration race condition bypasses free-tier limit
Free-tier users are limited to registering three CI webhook integrations. The registration limit is enforced with a SELECT COUNT(*) query that counts existing webhooks for the user before inserting a new one. This check is not performed inside a transaction with SELECT ... FOR UPDATE, creating a classic TOCTOU (time-of-check to time-of-use) race condition. An attacker can send 100 concurrent POST /api/webhooks requests simultaneously. All 100 requests execute the SELECT COUNT(*) check at approximately the same time, all read a count of zero (before any insert has committed), all proceed past the limit check, and all insert webhook records. The attacker ends up with 100 registered CI webhooks on the free tier instead of the allowed three.
// PRIVESC14-004 — VULNERABLE
// SELECT COUNT(*) without FOR UPDATE — concurrent requests all read 0 and bypass limit.
const PLAN_WEBHOOK_LIMIT = { free: 3, pro: 20, team: 100 };
router.post('/webhooks', requireSession, async (req, res) => {
const limit = PLAN_WEBHOOK_LIMIT[req.user.plan] ?? 3;
// VULNERABLE: COUNT without FOR UPDATE — 100 concurrent requests all read count=0
const existing = await db.webhooks.countByUserId(req.user.sub);
if (existing >= limit) {
return res.status(402).json({ error: `Webhook limit reached (${limit} for ${req.user.plan} plan)` });
}
// All 100 concurrent requests reach here — 100 webhooks registered instead of 3
const webhook = await db.webhooks.create({ userId: req.user.sub, url: req.body.url });
res.json(webhook);
});
Fix: Wrap the count check and insert in a database transaction using SELECT ... FOR UPDATE (or the ORM equivalent) to serialize concurrent registrations for the same user. Additionally, apply a per-user rate limit on the webhook creation endpoint (e.g., max 10 requests per minute per user) to prevent burst races. For databases that do not support FOR UPDATE, use a unique constraint on (userId, webhookIndex) where webhookIndex is a sequence number capped at the plan limit.
// PRIVESC14-004 — FIXED
const PLAN_WEBHOOK_LIMIT = { free: 3, pro: 20, team: 100 };
router.post('/webhooks',
requireSession,
rateLimit({ windowMs: 60_000, max: 10, keyGenerator: req => req.user.sub }), // per-user rate limit
async (req, res) => {
const limit = PLAN_WEBHOOK_LIMIT[req.user.plan] ?? 3;
// Transaction with SELECT FOR UPDATE — serializes concurrent registrations for this user
const webhook = await db.transaction(async (trx) => {
const existing = await trx.raw(
'SELECT COUNT(*) AS cnt FROM webhooks WHERE user_id = ? FOR UPDATE',
[req.user.sub]
);
const count = Number(existing[0].cnt);
if (count >= limit) {
const err = new Error('Webhook limit reached');
err.status = 402;
throw err;
}
return trx('webhooks').insert({
id: crypto.randomUUID(),
userId: req.user.sub,
url: req.body.url,
createdAt: new Date()
}).returning('*').then(rows => rows[0]);
});
res.json(webhook);
}
);
Summary
| Finding | Pattern | Severity | Fix |
|---|---|---|---|
| PRIVESC14-001 | Audit depth read from req.body.depth — free-tier gets paid scan depth | HIGH | Depth determined server-side from plan config; request body depth parameter ignored |
| PRIVESC14-002 | In-process concurrent counter resets to 0 on worker OOM/restart | HIGH | Redis INCR/DECR with TTL — atomic, distributed, crash-safe |
| PRIVESC14-003 | JWT planRetentionDays claim bypasses history retention limit | HIGH | Fetch retention from plan config DB; JWT contains identity claims only |
| PRIVESC14-004 | Webhook limit race condition via SELECT COUNT(*) without FOR UPDATE | CRITICAL | SELECT FOR UPDATE in transaction + per-user creation rate limit |
Related: SA-SKL-PRIVESC13 (organization billing and subscription management privilege escalation), SA-SKL-PRIVESC12 (team management and permission inheritance privilege escalation). Run SkillAudit to detect all PRIVESC14 patterns in your MCP skill registry.