Claude MCP skill privilege escalation — organisation billing and subscription management endpoints
SA-SKL-PRIVESC17 documents four privilege escalation vulnerabilities in MCP skill registry organisation billing and subscription management endpoints. JWT plan claim trust enables any user to self-assign enterprise tier features by crafting a token; a missing ownership check on billing portal session creation lets any org member redirect billing to their own contact; Stripe webhook event body trust lets an attacker spoof a downgrade event to disrupt victim orgs; and a missing ownership check on invoice PDF download exposes financial documents cross-account.
orgPlan claim; attacker crafts JWT with orgPlan:'enterprise' bypassing all feature gates: unlimited seats, SSO, policy export, CI webhook integrations
POST /api/billing/:orgId/portal missing org-ownership check; any org member creates Stripe billing portal session for any org by guessing orgId UUID; attacker can redirect billing contact email and cancel subscriptions
planId from Stripe event body without validating against Stripe API; attacker crafts POST with customer.subscription.updated and planId:'free' to downgrade any org by guessing customerId
GET /api/billing/:orgId/invoices/:invoiceId missing org-ownership check; any authenticated user downloads any org's invoice by guessing Stripe in_xxxx invoice ID
PRIVESC17-001 (Critical): JWT orgPlan claim trust enables any user to self-assign enterprise tier
MCP skill registry feature gating — controlling access to unlimited concurrent scans, SSO integration, policy export, CI/CD webhook delivery, and organisation-level audit reports — commonly references a plan tier value embedded in the user's JWT. When this value is read directly from the JWT payload claim (req.user.orgPlan or decoded.orgPlan) without verification against the subscription record in the database, any user who can generate a valid JWT with a modified claim (e.g., by using a compromised signing key, exploiting a JWT algorithm confusion vulnerability, or in some implementations directly supplying the claim via a debug endpoint) can self-assign enterprise-tier access at zero cost.
The practical impact is complete feature gate bypass. An attacker on a free-tier account crafts a JWT with orgPlan: 'enterprise' and gains: unlimited scheduled scans consuming server resources, SSO configuration access that can be used to link the org to an attacker-controlled identity provider, policy export that leaks all security findings across the org, and CI webhook integration that receives all future security events. The plan claim should never be trusted from the JWT — it is a client-supplied value that the server should consider advisory at best and discard at worst. CVSS 9.1 (AV:N/AC:L/PR:L/UI:N/S:C/C:H/I:H/A:N).
// VULNERABLE — PRIVESC17-001: org plan tier read directly from JWT claim
// File: middleware/feature-gate.js
// VULNERABILITY: orgPlan claim is part of the JWT payload — attacker-controllable
// A user who can produce a valid JWT (compromised key, alg confusion, debug endpoint)
// can include orgPlan:'enterprise' and bypass all feature gates
function requirePlan(minPlan) {
const PLAN_RANK = { free: 0, starter: 1, pro: 2, enterprise: 3 };
return (req, res, next) => {
const userPlan = req.user.orgPlan; // ← read from JWT claim
if (PLAN_RANK[userPlan] >= PLAN_RANK[minPlan]) {
return next();
}
res.status(403).json({ error: `Requires ${minPlan} plan` });
};
}
// All feature-gated routes trust the JWT claim
router.get('/api/policy/export', authenticate, requirePlan('enterprise'), exportPolicies);
router.post('/api/sso/configure', authenticate, requirePlan('enterprise'), configureSso);
router.post('/api/schedules', authenticate, requirePlan('starter'), createSchedule);
Fix: Fetch the plan tier from the subscription record in the database on each request, keyed by the orgId claim (which cannot grant escalation on its own — it only identifies the org, not the tier). Cache the plan config server-side per orgId with a short TTL (60 seconds) to avoid per-request database round-trips on high-traffic endpoints. The JWT should carry only an opaque orgId identifier; the server resolves plan capabilities from its own authoritative source. Never store plan tier, feature flags, or permissions in the JWT payload.
// FIXED — PRIVESC17-001: plan tier fetched from DB; JWT carries orgId only; 60s cache
// File: middleware/feature-gate.js
const NodeCache = require('node-cache');
const planCache = new NodeCache({ stdTTL: 60 }); // 60-second TTL per orgId
async function getOrgPlan(orgId) {
const cached = planCache.get(orgId);
if (cached) return cached;
const { rows } = await db.query(
`SELECT plan_tier FROM subscriptions
WHERE org_id = $1 AND status = 'active'
ORDER BY created_at DESC LIMIT 1`,
[orgId]
);
const tier = rows[0]?.plan_tier ?? 'free';
planCache.set(orgId, tier);
return tier;
}
function requirePlan(minPlan) {
const PLAN_RANK = { free: 0, starter: 1, pro: 2, enterprise: 3 };
return async (req, res, next) => {
// JWT carries orgId only — plan tier resolved from DB
const orgId = req.user.orgId;
const orgPlan = await getOrgPlan(orgId);
if (PLAN_RANK[orgPlan] >= PLAN_RANK[minPlan]) {
req.orgPlan = orgPlan; // attach resolved plan to request for downstream use
return next();
}
res.status(403).json({ error: `Requires ${minPlan} plan` });
};
}
PRIVESC17-002 (High): Billing portal IDOR — any org member creates Stripe session for arbitrary org
The billing portal session creation endpoint POST /api/billing/:orgId/portal creates a Stripe Customer Portal session, returning a time-limited URL that grants access to subscription management (payment methods, invoice history, cancellation) for the associated Stripe customer. When this endpoint does not verify that the requesting user is either the billing contact or an owner of the specified orgId, any authenticated user who can guess or enumerate a UUID orgId can create a billing portal session for that organisation.
The Stripe Customer Portal session gives full access to the subscription lifecycle: the attacker can update the billing contact email to their own address (redirecting all future invoices and subscription notifications), cancel the subscription (causing service disruption), or change the payment method to a fraudulent card. Because orgId is a UUID assigned sequentially or pseudo-randomly at organisation creation, and because many registries expose orgId values in API responses to org members, an attacker who is a low-privilege member of any organisation can enumerate other org IDs and perform billing manipulation against unrelated organisations. CVSS 8.1 (AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:N).
// VULNERABLE — PRIVESC17-002: billing portal creation missing org-ownership check
// File: routes/billing.js
router.post('/billing/:orgId/portal', authenticate, async (req, res) => {
const { orgId } = req.params;
// VULNERABILITY: no check that req.user belongs to orgId as owner or billing contact
// Any authenticated user with any orgId value gets a valid Stripe portal session
const org = await db.query('SELECT stripe_customer_id FROM orgs WHERE id = $1', [orgId]);
if (!org.rows.length) return res.status(404).json({ error: 'Org not found' });
const session = await stripe.billingPortal.sessions.create({
customer: org.rows[0].stripe_customer_id,
return_url: `https://skillaudit.dev/settings/billing`,
});
res.json({ url: session.url });
});
Fix: Verify that the requesting user is either the billing contact (billing_contact = true) or the org owner (role = 'owner') for the specified orgId before creating the portal session. Additionally, verify that the orgId in the URL matches the orgId in the user's JWT to prevent cross-org access even for owners. These two checks together prevent both horizontal escalation (accessing other orgs) and vertical escalation (non-billing-contact members accessing their own org's billing portal).
// FIXED — PRIVESC17-002: ownership check required before Stripe session creation
// File: routes/billing.js
router.post('/billing/:orgId/portal', authenticate, async (req, res) => {
const { orgId } = req.params;
const userId = req.user.sub;
const userOrgId = req.user.orgId; // from JWT — identifies the user's org
// Check 1: orgId in URL must match user's own org (prevents cross-org access)
if (orgId !== userOrgId) {
return res.status(403).json({ error: 'Forbidden' });
}
// Check 2: user must be org owner or billing contact within their own org
const { rows } = await db.query(
`SELECT stripe_customer_id FROM orgs o
JOIN org_members m ON m.org_id = o.id
WHERE o.id = $1
AND m.user_id = $2
AND (m.role = 'owner' OR m.billing_contact = true)`,
[orgId, userId]
);
if (!rows.length) {
return res.status(403).json({ error: 'Must be org owner or billing contact' });
}
const session = await stripe.billingPortal.sessions.create({
customer: rows[0].stripe_customer_id,
return_url: `https://skillaudit.dev/settings/billing`,
});
res.json({ url: session.url });
});
PRIVESC17-003 (High): Stripe webhook planId spoofing downgrades any org via forged event body
Subscription change events from Stripe are delivered to the registry's webhook endpoint. When the webhook handler processes the planId field from the event body without first validating the event's authenticity against the Stripe API and without verifying the Stripe-Signature header HMAC, any HTTP client can POST a forged event body to the webhook endpoint. The attacker crafts a request with type: 'customer.subscription.updated', a guessable or known customerId (Stripe customer IDs are exposed in billing portal URLs and invoice PDFs), and planId: 'free'. The handler updates the org's subscription tier to free in the database, immediately removing enterprise features and enforcement of plan limits.
The attack can be used to competitively degrade a rival organisation's audit capability, to disrupt a victim org's CI/CD security scanning, or as part of a larger extortion scenario. The customerId can be obtained from the invoice PDF IDOR in PRIVESC17-004. CVSS 7.5 (AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:H/A:H).
// VULNERABLE — PRIVESC17-003: Stripe webhook trusts planId from event body; no HMAC verify
// File: routes/webhooks-stripe.js
router.post('/webhooks/stripe', express.raw({ type: 'application/json' }), async (req, res) => {
// VULNERABILITY 1: No Stripe-Signature HMAC verification
// Any HTTP client can POST a forged event body to this endpoint
const event = JSON.parse(req.body); // attacker controls all fields
if (event.type === 'customer.subscription.updated') {
// VULNERABILITY 2: planId trusted from event body — not fetched from Stripe API
// Attacker sets planId:'free' to downgrade any org by guessing customerId
const { customerId, planId } = event.data.object;
await db.query(
'UPDATE subscriptions SET plan_tier = $1 WHERE stripe_customer_id = $2',
[planId, customerId]
);
}
res.json({ received: true });
});
Fix: Verify the Stripe-Signature header HMAC using stripe.webhooks.constructEvent() with the webhook signing secret before processing any event data. Return 400 immediately on signature failure without performing any database writes. After signature verification, fetch the subscription details from the Stripe API using the event ID (stripe.subscriptions.retrieve(event.data.object.id)) rather than trusting any field from the event body, including planId. The event body should be treated as a notification, not as authoritative data.
// FIXED — PRIVESC17-003: HMAC verification required; plan fetched from Stripe API, not event body
// File: routes/webhooks-stripe.js
const stripe = require('stripe')(process.env.STRIPE_SECRET_KEY);
const WEBHOOK_SECRET = process.env.STRIPE_WEBHOOK_SIGNING_SECRET;
router.post('/webhooks/stripe', express.raw({ type: 'application/json' }), async (req, res) => {
const sig = req.headers['stripe-signature'];
let event;
try {
// constructEvent() verifies HMAC-SHA256 signature — rejects forged events
event = stripe.webhooks.constructEvent(req.body, sig, WEBHOOK_SECRET);
} catch (err) {
// Return 400 before any DB write; never trust unsigned events
return res.status(400).json({ error: `Webhook signature verification failed: ${err.message}` });
}
if (event.type === 'customer.subscription.updated') {
// Fetch authoritative plan details from Stripe API using event ID
// Never trust planId from the event body — always re-fetch from Stripe
const subscription = await stripe.subscriptions.retrieve(event.data.object.id);
const planId = subscription.items.data[0]?.price?.lookup_key ?? 'free';
await db.query(
'UPDATE subscriptions SET plan_tier = $1, stripe_subscription_id = $2 WHERE stripe_customer_id = $3',
[planId, subscription.id, subscription.customer]
);
}
res.json({ received: true });
});
PRIVESC17-004 (High): Invoice PDF IDOR — any authenticated user downloads any org's financial documents
The invoice PDF download endpoint GET /api/billing/:orgId/invoices/:invoiceId proxies the invoice PDF from Stripe for display in the billing UI. When this endpoint does not verify that the specified orgId matches the requesting user's organisation, and does not verify that the invoiceId belongs to the Stripe customer associated with that orgId, any authenticated user can download any organisation's invoices by supplying a valid Stripe invoice ID. Stripe invoice IDs follow the pattern in_ followed by 24 alphanumeric characters — a guessable format with limited entropy that can be enumerated or obtained from other IDOR vectors.
Invoice PDFs contain: the customer's legal name and billing address, the subscription tier and cost, payment method last four digits, and the billing contact email address. This financial intelligence enables targeted phishing, competitive pricing intelligence, and the construction of convincing social engineering pretexts. Combined with the customerId values exposed in invoice documents, this finding directly enables PRIVESC17-003 by providing the customer IDs needed for downgrade spoofing. CVSS 7.1 (AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:N/A:N).
// VULNERABLE — PRIVESC17-004: invoice PDF download missing org-ownership check
// File: routes/billing.js
router.get('/billing/:orgId/invoices/:invoiceId', authenticate, async (req, res) => {
const { orgId, invoiceId } = req.params;
// VULNERABILITY: no check that orgId matches user's org
// No check that invoiceId belongs to the stripe customer for orgId
// Any authenticated user with any orgId + invoiceId can download any invoice
const invoice = await stripe.invoices.retrieve(invoiceId);
res.setHeader('Content-Type', 'application/pdf');
res.setHeader('Content-Disposition', `attachment; filename="invoice-${invoiceId}.pdf"`);
// invoice.invoice_pdf is a Stripe-signed URL — proxy its content to the user
const pdfResponse = await fetch(invoice.invoice_pdf);
pdfResponse.body.pipe(res);
});
Fix: Before retrieving or proxying the invoice PDF, verify that: (1) the orgId in the URL matches the requesting user's orgId from the JWT, and (2) the Stripe customer associated with the retrieved invoice matches the Stripe customer ID stored for the specified orgId. Additionally, rather than proxying the raw PDF through your server, return Stripe's time-limited signed invoice_pdf URL directly to the client and let the browser download it from Stripe — this eliminates the proxy surface and leverages Stripe's own access controls.
// FIXED — PRIVESC17-004: orgId ownership check; customerId cross-check; Stripe signed URL returned
// File: routes/billing.js
router.get('/billing/:orgId/invoices/:invoiceId', authenticate, async (req, res) => {
const { orgId, invoiceId } = req.params;
const userId = req.user.sub;
const userOrgId = req.user.orgId;
// Check 1: orgId in URL must match user's own org
if (orgId !== userOrgId) {
return res.status(403).json({ error: 'Forbidden' });
}
// Check 2: user must be org owner or billing contact
const { rows: memberRows } = await db.query(
`SELECT o.stripe_customer_id FROM orgs o
JOIN org_members m ON m.org_id = o.id
WHERE o.id = $1 AND m.user_id = $2
AND (m.role = 'owner' OR m.billing_contact = true)`,
[orgId, userId]
);
if (!memberRows.length) {
return res.status(403).json({ error: 'Must be org owner or billing contact' });
}
const orgStripeCustomerId = memberRows[0].stripe_customer_id;
// Fetch invoice from Stripe
const invoice = await stripe.invoices.retrieve(invoiceId);
// Check 3: invoice must belong to this org's Stripe customer — prevents cross-org invoice access
if (invoice.customer !== orgStripeCustomerId) {
return res.status(403).json({ error: 'Invoice does not belong to this organisation' });
}
// Return Stripe's time-limited signed URL — no server-side PDF proxying needed
// Stripe's signed URL expires in ~1 hour and is scoped to the invoice
res.json({ invoicePdfUrl: invoice.invoice_pdf });
});
Detection with tree-sitter queries
The highest-value patterns in this advisory are JWT claim reads used for privilege decisions (PRIVESC17-001), route handlers using an :orgId path parameter without a preceding ownership check (PRIVESC17-002, PRIVESC17-004), and Stripe webhook handlers that do not call constructEvent() before processing event data (PRIVESC17-003). The following tree-sitter queries identify these patterns in Node.js codebases.
Query 1 — JWT claim read for plan/role/permission decision. Matches property accesses on req.user where the property name contains common privilege-indicating identifiers (plan, role, tier, admin, permission) — the PRIVESC17-001 structural signature. Each match should be reviewed to confirm it fetches from the database rather than trusting the JWT payload.
; tree-sitter query: JWT claim reads for privilege decisions (PRIVESC17-001)
; Matches: req.user.orgPlan / req.user.role / req.user.tier / req.user.isAdmin
(member_expression
object: (member_expression
object: (identifier) @req (#eq? @req "req")
property: (property_identifier) @user (#eq? @user "user")
)
property: (property_identifier) @claim
(#match? @claim "^(plan|role|tier|isAdmin|admin|permission|feature|access|level).*")
) @jwt-claim-read
; Each @jwt-claim-read: a privilege-relevant field read from the JWT decoded payload.
; Confirm: is this used for a feature gate or permission check?
; If yes: does it fetch from DB instead? Fix: query subscriptions/roles table; cache with TTL.
Query 2 — Route handler using :orgId path param without ownership verification query. Matches route handler functions that reference req.params.orgId but do not contain a database query that includes both the orgId value and req.user-derived values (indicating a missing cross-ownership check).
; tree-sitter query: :orgId route param used without DB ownership check (PRIVESC17-002/004)
; Matches route handlers accessing req.params.orgId without a user-scoped DB query
(call_expression
function: (member_expression
object: (identifier) @router
property: (property_identifier) @verb
(#match? @verb "^(get|post|put|patch|delete)$")
)
arguments: (arguments
(string) @path (#match? @path ":orgId")
(_)*
(arrow_function
body: (statement_block) @body
)
)
) @orgid-route
; Review each @orgid-route: does @body contain a db.query that joins
; req.params.orgId with req.user.sub or req.user.orgId to verify ownership?
; If not: potential IDOR on billing or org management endpoint.
Query 3 — Stripe webhook handler without constructEvent() call. Matches Express route handlers on paths matching /webhooks/stripe or similar that parse the request body as JSON without calling stripe.webhooks.constructEvent() — the PRIVESC17-003 signature indicating unsigned Stripe events are being trusted.
; tree-sitter query: Stripe webhook handler trusting event body without constructEvent() (PRIVESC17-003)
; Matches: JSON.parse(req.body) in a Stripe webhook route without constructEvent call
(call_expression
function: (member_expression
object: (identifier) @router
property: (property_identifier) @verb (#match? @verb "^(post|put)$")
)
arguments: (arguments
(string) @path (#match? @path "stripe|webhook")
(_)*
(arrow_function
body: (statement_block
(variable_declaration
(variable_declarator
value: (call_expression
function: (member_expression
object: (identifier) @json (#eq? @json "JSON")
property: (property_identifier) @parse (#eq? @parse "parse")
)
)
)
) @json-parse-event
)
)
)
) @stripe-webhook-no-verify
; Each @stripe-webhook-no-verify: Stripe webhook parses body directly without HMAC verification.
; Fix: replace JSON.parse(req.body) with stripe.webhooks.constructEvent(req.body, sig, secret).
; Return 400 on signature failure before any DB writes.
Summary
| ID | Severity | Vector | Root cause | Fix |
|---|---|---|---|---|
| PRIVESC17-001 | Critical | JWT orgPlan claim | req.user.orgPlan read from JWT payload; attacker crafts JWT with orgPlan:'enterprise'; all feature gates bypassed |
Fetch plan from subscriptions DB table per orgId; cache 60s server-side; never read plan from JWT |
| PRIVESC17-002 | High | Billing portal session IDOR | No ownership check on POST /api/billing/:orgId/portal; any member creates Stripe portal for any org |
Verify orgId matches req.user.orgId; verify user is role='owner' or billing_contact=true |
| PRIVESC17-003 | High | Stripe webhook planId spoofing | No HMAC verification; planId trusted from event body; attacker forges downgrade event for any customerId |
stripe.webhooks.constructEvent() signature check; fetch plan from Stripe API using event ID |
| PRIVESC17-004 | High | Invoice PDF IDOR | No org-ownership check on GET /api/billing/:orgId/invoices/:invoiceId; any user downloads any org's invoice |
Verify orgId matches user's org; verify invoice customer matches org's Stripe customer; return signed URL |
Billing endpoint security checklist for MCP skill registry operators: (1) Grep all middleware and route files for req.user.plan, req.user.role, req.user.tier, and similar JWT claim reads used in permission checks — replace all with database lookups. (2) Grep for JWT or jsonwebtoken.decode( calls that do not follow up with database authorisation lookups. (3) Review every billing endpoint that accepts an :orgId path parameter — confirm each has an explicit ownership check linking orgId to the requesting user's org. (4) Review every Stripe webhook handler — confirm all call stripe.webhooks.constructEvent() before any DB write and return 400 on signature failure. (5) Confirm Stripe event handlers fetch authoritative plan/subscription data from the Stripe API using the event ID, never from the event body. (6) Review invoice and document download endpoints — confirm customerId cross-checks prevent cross-account invoice access. (7) Confirm billing portal session creation endpoints require role='owner' or billing_contact=true, not just any org membership. (8) Run the three tree-sitter detection queries above in CI to catch JWT claim privilege trust and missing ownership checks before deployment. See also: SA-SKL-CORS34 for CORS misconfigurations on billing webhook endpoints; SA-SKL-INJECTION24 for injection via build endpoints callable from enterprise-tier accounts.
Scan your MCP skills for PRIVESC17 and 2400+ other patterns
SkillAudit continuously audits MCP server and Claude skill codebases for privilege escalation, billing IDOR, injection vulnerabilities, CORS misconfigurations, and deserialization flaws. Get findings in minutes.
Get started at skillaudit.dev