SA-SKL-PRIVESC13 — Privilege Escalation
Privilege Escalation in MCP Skill Registry Organization Billing and Subscription Management
Billing and subscription management is the revenue boundary of an MCP skill registry: it determines which features each user can access, how long they can access them, and which payment records they can view. SA-SKL-PRIVESC13 covers four privilege escalation vulnerabilities that allow attackers to claim paid plan features without paying, extend trial periods indefinitely, read other organizations' invoice data, and forge Stripe payment events to grant themselves arbitrary plan upgrades.
plan from req.user.subscription.plan decoded from JWT; attacker crafts JWT with subscription.plan:team bypassing Stripe validation entirely and accessing all Team-tier features without paymentPATCH /api/subscription/trial missing admin role check; any authenticated user can extend their own trial period indefinitely by calling the endpoint repeatedly; fix: admin role required or Stripe-only trial extensionGET /api/billing/invoice/:invoiceId missing userId ownership check; attacker reads any organization's invoice by guessing sequential integer ID; fix: UUID invoice IDs + findByIdAndOrgId() + 404 for not-ownedstripe.webhooks.constructEvent(); attacker forges invoice.payment_succeeded event with arbitrary plan slug and customer ID, granting themselves a free Team plan upgradePRIVESC13-001 — JWT subscription.plan claim bypass grants Team tier without payment
The plan gating middleware reads the user's subscription tier from req.user.subscription.plan, which is decoded from the session JWT. The JWT is signed with a server-side secret, so its contents cannot be tampered with in transit — but the JWT is issued during login from whatever plan value is in the database at the time. An attacker who obtains a signing secret (via any of the DESER or INJECTION vulnerabilities in this catalog) can craft a JWT with subscription: { plan: "team" } and bypass Stripe plan validation entirely for the duration of that JWT's validity window.
// PRIVESC13-001 — VULNERABLE
// Plan check reads from JWT claims — not from Stripe or DB at request time.
function requirePlan(minPlan) {
return (req, res, next) => {
const userPlan = req.user.subscription?.plan; // VULNERABLE: from JWT, not DB/Stripe
if (!planSatisfies(userPlan, minPlan)) {
return res.status(402).json({ error: 'Upgrade required' });
}
next();
};
}
// Attacker crafts JWT with { subscription: { plan: "team" } }
// All Team-gated features become accessible without any Stripe payment
Fix: Never read subscription plan from the JWT. Fetch the current plan from the Stripe Subscription object (or a subscription DB table that is updated only via verified Stripe webhooks) on every request that gates a paid feature. Use the JWT for identity only (sub claim). Cache the plan lookup for a short TTL (5–60 seconds) per user to avoid per-request Stripe API calls.
// PRIVESC13-001 — FIXED
const planCache = new Map(); // userId -> { plan, expiresAt }
async function getCurrentPlan(userId) {
const cached = planCache.get(userId);
if (cached && cached.expiresAt > Date.now()) return cached.plan;
// Always fetch from DB (which is updated only by verified Stripe webhook events)
const subscription = await db.subscriptions.findByUserId(userId);
const plan = subscription?.status === 'active' ? subscription.planSlug : 'free';
planCache.set(userId, { plan, expiresAt: Date.now() + 30000 }); // 30s cache
return plan;
}
function requirePlan(minPlan) {
return async (req, res, next) => {
const currentPlan = await getCurrentPlan(req.user.sub); // from DB, not JWT
if (!planSatisfies(currentPlan, minPlan)) {
return res.status(402).json({ error: 'Upgrade required' });
}
next();
};
}
PRIVESC13-002 — Trial extension endpoint missing admin check — indefinite trial
The trial extension endpoint PATCH /api/subscription/trial was added to allow support staff to manually extend a user's trial period on request. The endpoint requires authentication but not an admin role, meaning any authenticated user who discovers the endpoint can call it repeatedly to extend their own trial period indefinitely, maintaining access to Pro-tier features without converting to a paid subscription.
// PRIVESC13-002 — VULNERABLE
// PATCH /api/subscription/trial missing admin check — any user extends own trial.
router.patch('/trial', requireSession, async (req, res) => {
// VULNERABLE: no admin check — any authenticated user can call this
const { extensionDays } = req.body;
await db.subscriptions.extendTrial(req.user.sub, extensionDays || 7);
res.json({ ok: true });
});
// Any user: PATCH /api/subscription/trial { "extensionDays": 365 }
// Grants 365 days of Pro-tier trial access, repeated as needed
Fix: Require admin role for direct trial extension. For customer-facing trial extensions, use the Stripe API (stripe.subscriptions.update(subId, { trial_end: newTimestamp })) rather than a direct database write, so Stripe remains the authoritative source of trial state. Log all trial extensions to an admin audit trail with actor ID, target user ID, extension duration, and reason.
// PRIVESC13-002 — FIXED
router.patch('/trial', requireSession, requireAdminRole, async (req, res) => {
const { targetUserId, extensionDays, reason } = req.body;
if (!Number.isInteger(extensionDays) || extensionDays < 1 || extensionDays > 30) {
return res.status(422).json({ error: 'extensionDays must be 1–30' });
}
const subscription = await stripe.subscriptions.update(
await getStripeSubId(targetUserId),
{ trial_end: Math.floor(Date.now() / 1000) + extensionDays * 86400 }
);
await db.adminAudit.create({
action: 'trial_extended', targetUserId,
extensionDays, reason, actorId: req.user.sub,
newTrialEnd: new Date(subscription.trial_end * 1000), at: new Date()
});
res.json({ ok: true, newTrialEnd: subscription.trial_end });
});
PRIVESC13-003 — Invoice IDOR via sequential integer IDs
The invoice retrieval endpoint GET /api/billing/invoice/:invoiceId returns a full invoice document including the organization name, billing contact email, charge amount, plan slug, and payment method last four digits. The invoiceId parameter is a sequential integer, and the endpoint performs no ownership check — any authenticated user can read any other organization's invoice by guessing or iterating integer IDs.
// PRIVESC13-003 — VULNERABLE
// Sequential integer invoiceId with no ownership check — IDOR reads any org's invoice.
router.get('/invoice/:invoiceId', requireSession, async (req, res) => {
const invoiceId = parseInt(req.params.invoiceId, 10); // sequential integer
const invoice = await db.invoices.findById(invoiceId); // VULNERABLE: no userId/orgId check
if (!invoice) return res.status(404).json({ error: 'Not found' });
res.json(invoice); // returns billing email, charge amount, plan, card last4 of any org
});
Fix: Use UUID invoice IDs. Add an ownership check to the query: findByIdAndOrgId(invoiceId, req.user.orgId). Return 404 (not 403) for invoices that exist but belong to other organizations, to prevent cross-org invoice existence probing. Strip the payment method last four digits from the API response — these are only needed in the billing settings UI, not in invoice downloads.
// PRIVESC13-003 — FIXED
router.get('/invoice/:invoiceId', requireSession, async (req, res) => {
// UUID invoiceId — not sequential integer
// Ownership check: invoice must belong to the authenticated user's organization
const invoice = await db.invoices.findByIdAndOrgId(req.params.invoiceId, req.user.orgId);
if (!invoice) return res.status(404).json({ error: 'Invoice not found' }); // 404 for not-owned too
res.json({
id: invoice.id, orgName: invoice.orgName, planSlug: invoice.planSlug,
amountUsd: invoice.amountUsd, periodStart: invoice.periodStart, periodEnd: invoice.periodEnd,
// billingEmail and cardLast4 NOT included in this response
});
});
PRIVESC13-004 — Stripe webhook without signature verification accepts forged payment events
The Stripe webhook handler receives POST requests at /api/webhooks/stripe and processes events by parsing the JSON body directly with JSON.parse(req.body), without verifying the Stripe-Signature header using the webhook secret. Any attacker who can POST to this endpoint — which is publicly accessible by design for Stripe to reach — can forge an invoice.payment_succeeded event with an arbitrary customer field and metadata.planSlug: "team", causing the registry to upgrade any customer's subscription to the Team plan without actual payment.
// PRIVESC13-004 — VULNERABLE
// Stripe webhook processes events without signature verification — forged events accepted.
router.post('/webhooks/stripe', express.raw({ type: 'application/json' }), async (req, res) => {
// VULNERABLE: JSON.parse without stripe.webhooks.constructEvent() verification
const event = JSON.parse(req.body);
if (event.type === 'invoice.payment_succeeded') {
const customerId = event.data.object.customer;
const planSlug = event.data.object.metadata?.planSlug || 'pro';
await db.subscriptions.activate(customerId, planSlug); // grants plan based on forged event
}
res.json({ received: true });
});
// Attacker: curl -X POST /api/webhooks/stripe -H "Content-Type: application/json" \
// -d '{"type":"invoice.payment_succeeded","data":{"object":{"customer":"cus_victim","metadata":{"planSlug":"team"}}}}'
// Grants Team plan to any Stripe customer ID
Fix: Always verify the Stripe webhook signature using stripe.webhooks.constructEvent(payload, sigHeader, STRIPE_WEBHOOK_SECRET). This throws if the signature is invalid, preventing any forged event from being processed. The STRIPE_WEBHOOK_SECRET is a webhook-specific signing secret from the Stripe dashboard — it is different from the Stripe API key. Store it in an environment variable and never log it.
// PRIVESC13-004 — FIXED
const stripe = require('stripe')(process.env.STRIPE_SECRET_KEY);
router.post('/webhooks/stripe',
express.raw({ type: 'application/json' }), // raw body needed for signature verification
async (req, res) => {
const sig = req.headers['stripe-signature'];
let event;
try {
// constructEvent verifies HMAC-SHA256 signature — throws on mismatch or replay
event = stripe.webhooks.constructEvent(req.body, sig, process.env.STRIPE_WEBHOOK_SECRET);
} catch (err) {
logger.warn('Stripe webhook signature verification failed', { error: err.message });
return res.status(400).json({ error: 'Webhook signature invalid' });
}
if (event.type === 'invoice.payment_succeeded') {
const invoice = event.data.object;
// Fetch subscription details from Stripe — do not trust event.data.object.metadata
const subscription = await stripe.subscriptions.retrieve(invoice.subscription);
const planSlug = subscription.metadata.planSlug;
if (!['free', 'pro', 'team'].includes(planSlug)) {
logger.error('Unknown planSlug in Stripe subscription metadata', { planSlug });
return res.status(200).json({ received: true }); // ack to Stripe but don't process
}
await db.subscriptions.activate(invoice.customer, planSlug);
}
res.json({ received: true });
});
Summary
| Finding | Pattern | Severity | Fix |
|---|---|---|---|
| PRIVESC13-001 | JWT subscription.plan claim gates plan access | CRITICAL | Fetch plan from DB (Stripe-webhook-updated) on every request; JWT for identity only |
| PRIVESC13-002 | Trial extension endpoint missing admin role check | HIGH | Admin role required; use Stripe API for trial extension; audit log all extensions |
| PRIVESC13-003 | Invoice IDOR via sequential integer IDs | HIGH | UUID invoice IDs + findByIdAndOrgId() + 404 for not-owned |
| PRIVESC13-004 | Stripe webhook without signature verification | CRITICAL | stripe.webhooks.constructEvent() with STRIPE_WEBHOOK_SECRET; fetch plan from Stripe, never from event metadata |
Related: SA-SKL-PRIVESC12 (team management and permission inheritance privilege escalation), SA-SKL-PRIVESC11 (admin panel and support ticket access control). Run SkillAudit to detect all PRIVESC13 patterns in your MCP skill registry.