Claude MCP skill business logic privilege escalation in plan enforcement — SA-SKL-PRIVESC3
Business logic privilege escalation exploits the gap between what a plan is supposed to restrict and how that restriction is actually implemented in code. Unlike authentication bypass or SQL injection, these vulnerabilities look correct at a glance — the check is there, the comparison makes sense, the flag is queried. The problem is the edge case: a timezone offset that extends a trial, a microsecond window between the plan check and the quota write, an orphaned row that re-elevates a downgraded account, a cache miss that defaults to allow instead of deny. Four SA-SKL-PRIVESC3 patterns cover the most common business logic escalation paths in MCP skill plan enforcement code.
new Date() to user.trialEnd without UTC normalization; setting TZ=America/Los_Angeles before process start shifts the local midnight boundary by up to 14 hours, extending the trial window without touching the databaseusers.plan = 'free' but does not delete the row in team_memberships; next login reads team membership first, finds a valid row, and re-grants Team plan silentlyPRIVESC3-001 — Trial period timezone offset abuse
When a trial expiry is stored as an ISO date string or a date-only value and compared using new Date(), the result depends on the system timezone of the process. new Date('2026-11-09') in UTC is midnight UTC; in America/Los_Angeles (UTC-8) the same string is interpreted as midnight Pacific, which is 08:00 UTC — giving the user an extra 8 hours of trial access. An attacker who controls or can predict the server timezone (e.g. via a startup script that sets TZ before the Node process, or by deploying on a region with a known non-UTC timezone) can extend their trial period by up to 14 hours without touching the database.
// VULNERABLE — PRIVESC3-001 (HIGH)
// trialEnd stored as 'YYYY-MM-DD' string. new Date() respects process timezone.
// TZ=America/Los_Angeles shifts the boundary by 8h, extending the trial.
function isTrialActive(user: User): boolean {
const trialEnd = new Date(user.trialEnd); // e.g. '2026-11-09' → TZ-dependent
const now = new Date(); // local time
// VULNERABLE: comparison is TZ-dependent when trialEnd is a date-only string
return now <= trialEnd;
}
// FIXED — PRIVESC3-001
// Store trialEnd as a UTC Unix timestamp (seconds since epoch) in the DB.
// Compare with Math.floor(Date.now() / 1000) — TZ-independent.
function isTrialActive(user: User): boolean {
// FIX: trialEnd is a Unix timestamp (UTC seconds). No timezone involved.
const nowSec = Math.floor(Date.now() / 1000);
return nowSec <= user.trialEndUnix;
}
// When creating a trial:
const TRIAL_DAYS = 14;
const trialEndUnix = Math.floor(Date.now() / 1000) + TRIAL_DAYS * 86400;
await db.run('UPDATE users SET trial_end_unix = ? WHERE id = ?', trialEndUnix, userId);
PRIVESC3-002 — Race condition on plan quota check
A common pattern for quota enforcement is: read the current usage count, check it against the plan limit, and if it passes, increment the counter and proceed. When this read-check-increment sequence is not atomic, two simultaneous requests will both read the same usage count (e.g. 99 against a limit of 100), both pass the check independently, and both increment to 100 and 101 respectively — allowing the user to consume 2× the quota in a single burst. The window is narrow but reliably exploitable by sending two requests simultaneously, which any HTTP client can do with Promise.all.
// VULNERABLE — PRIVESC3-002 (HIGH)
// Read current usage, check limit, then increment. Not atomic.
// Two concurrent requests both read usageCount=99, both pass limit=100.
async function consumeQuota(userId: string): Promise<boolean> {
const { usageCount } = await db.get(
'SELECT usage_count FROM quotas WHERE user_id = ?', userId
);
const plan = await getUserPlan(userId);
if (usageCount >= plan.limit) return false; // BOTH requests pass this check
// RACE: both requests increment from 99 → 100; second makes it 101
await db.run(
'UPDATE quotas SET usage_count = usage_count + 1 WHERE user_id = ?', userId
);
return true;
}
// FIXED — PRIVESC3-002
// Use an atomic Redis INCR: increment first, then check if the new value exceeds
// the limit. If it does, decrement (undo) and reject. The check-then-act is now
// a single atomic operation from Redis's perspective.
async function consumeQuota(userId: string): Promise<boolean> {
const plan = await getUserPlan(userId);
const key = `quota:${userId}:${getCurrentMonth()}`;
// FIX: INCR is atomic — no two requests can read the same value
const newCount = await redis.incr(key);
await redis.expire(key, 32 * 86400); // 32 days TTL, resets monthly
if (newCount > plan.limit) {
// Over limit: undo the increment and reject
await redis.decr(key);
return false;
}
return true;
}
PRIVESC3-003 — Dangling team_memberships row on plan downgrade
When a user downgrades from Team to Free, the typical code path updates the plan column in the users table. If the application also maintains a team_memberships table to track which users belong to which team (for SSO, seat management, or policy export), and the downgrade flow does not cascade-delete the membership row, the user retains a live membership record. On next login, the session-building code reads team membership first — because team membership implicitly implies Team plan — and silently re-elevates the account to Team without any explicit plan field being set.
// VULNERABLE — PRIVESC3-003 (HIGH)
// Downgrade only updates users.plan. Does not delete from team_memberships.
// Next login: getEffectivePlan reads team_memberships first and re-grants Team.
async function downgradeTofree(userId: string): Promise<void> {
await db.run(
"UPDATE users SET plan = 'free', plan_expires_at = NULL WHERE id = ?",
userId
);
// MISSING: DELETE FROM team_memberships WHERE user_id = ?
// The row survives; getEffectivePlan will re-read it on next login.
}
async function getEffectivePlan(userId: string): Promise<string> {
// Checks team membership first — membership implies Team plan
const membership = await db.get(
'SELECT team_id FROM team_memberships WHERE user_id = ?', userId
);
if (membership) return 'team'; // VULNERABLE: returns 'team' for downgraded users
const user = await db.get('SELECT plan FROM users WHERE id = ?', userId);
return user.plan;
}
// FIXED — PRIVESC3-003
// Downgrade cascades: delete team_memberships row in the same transaction.
async function downgradeToFree(userId: string): Promise<void> {
await db.run('BEGIN');
try {
await db.run(
"UPDATE users SET plan = 'free', plan_expires_at = NULL WHERE id = ?",
userId
);
// FIX: remove team membership in the same transaction
await db.run(
'DELETE FROM team_memberships WHERE user_id = ?',
userId
);
await db.run('COMMIT');
} catch (err) {
await db.run('ROLLBACK');
throw err;
}
}
// Alternative: enforce via DB foreign key with ON DELETE CASCADE on users.id
PRIVESC3-004 — Default-allow fallback on Redis feature flag eviction
Feature flags that gate paid features are often cached in Redis with a TTL to avoid per-request database reads. A common implementation stores featureEnabled=1 (or true) in Redis with a TTL matching the plan expiry. When the key expires, Redis evicts it. If the application code that reads the flag treats key absence as null (or falsy) and applies a default-allow fallback — either explicitly with if (flag === null) return true or implicitly via a loose if (!flag) check that never reaches the database — the user retains access to the paid feature indefinitely after their plan expires, until the cache is manually purged or the key is explicitly written as false.
// VULNERABLE — PRIVESC3-004 (MEDIUM)
// Feature flag cached in Redis with TTL = plan expiry.
// When key expires, Redis returns null. Null is treated as "no restriction found"
// → feature silently re-enabled.
async function canUseFeature(userId: string, feature: string): Promise<boolean> {
const cached = await redis.get(`feature:${userId}:${feature}`);
if (cached === null) {
// VULNERABLE: absence of key means "not restricted" — default allow
// Should be: re-fetch from DB and explicitly cache the result
return true;
}
return cached === '1';
}
// FIXED — PRIVESC3-004
// Cache miss triggers a DB re-fetch. Write an explicit 0/1 back to Redis.
// Absence never defaults to allow — it defaults to a synchronous DB check.
async function canUseFeature(userId: string, feature: string): Promise<boolean> {
const cached = await redis.get(`feature:${userId}:${feature}`);
if (cached !== null) {
return cached === '1';
}
// FIX: cache miss → re-read from DB, write explicit result back to Redis
const user = await db.get('SELECT plan, plan_expires_at FROM users WHERE id = ?', userId);
const enabled = isPlanFeatureEnabled(user.plan, feature) &&
(user.plan_expires_at === null || user.plan_expires_at > Date.now() / 1000);
// Write explicit 0 or 1; TTL = remaining plan time, not feature-specific
const ttl = user.plan_expires_at
? Math.max(0, user.plan_expires_at - Math.floor(Date.now() / 1000))
: 3600;
await redis.set(`feature:${userId}:${feature}`, enabled ? '1' : '0', 'EX', ttl);
return enabled;
}
SkillAudit detection: SA-SKL-PRIVESC3 flags new Date() comparisons against date-only strings in plan enforcement functions, non-atomic read-then-increment quota patterns without Redis INCR or DB row-level locking, downgrade functions that UPDATE users.plan without a matching DELETE on membership or entitlement tables, and Redis GET calls with null-is-allow fallbacks on feature flags. Run a free audit at skillaudit.dev.
| Pattern | CVSS | Impact | Fix |
|---|---|---|---|
| PRIVESC3-001 Trial TZ offset | 7.1 High | Free trial extended up to 14 hours without DB change | Store expiry as UTC Unix timestamp; compare with Date.now()/1000 |
| PRIVESC3-002 Quota race condition | 7.5 High | Double quota consumption per concurrent burst | Atomic Redis INCR before check; decrement on over-limit |
| PRIVESC3-003 Dangling membership | 8.1 High | Downgraded users re-elevated to Team plan on next login | Cascade-delete membership rows in same transaction as plan downgrade |
| PRIVESC3-004 Default-allow eviction | 5.4 Medium | Paid features remain accessible after plan expiry | Cache miss triggers DB re-fetch; write explicit 0/1 back to Redis |