Claude MCP skill privilege escalation — org switching and cross-tenant data access security — SA-SKL-PRIVESC6
Multi-tenant skill registries expose a unique privilege escalation surface at the organization layer: when org-switching logic trusts client-supplied organization IDs without validating membership, an attacker can join the session context of any organization on the platform. SA-SKL-PRIVESC6 covers four patterns in multi-tenant org management: org switch without membership check, persistent cross-tenant skill access post-switch, invite token email enumeration, and Stripe customerId cross-tenant billing data access.
POST /api/orgs/switch sets req.session.orgId to the attacker-supplied orgId request body field without checking whether the authenticated user is a member of that organization; attacker switches to any org's context and immediately reads that org's private skills, audit reports, API keys, and billing informationorgId is validated only at session switch time, not on every subsequent request; attacker retains access to org-A's resources after switching out of it — persistent cross-tenant data accessGET /api/invite/{token} returns the full recipientEmail in the response body before the invitation is accepted; attacker who obtains or guesses invite tokens can enumerate all invited team members' email addresses — information disclosure enabling targeted phishingGET /api/billing/invoices?customerId={id} where customerId is the Stripe customer ID supplied by the client; attacker modifies the query parameter to another org's Stripe customerId (enumerable from public invoice receipts or guessable as cus_XXXX sequential IDs); reads another org's billing history and credit card metadataPRIVESC6-001 — Org switch without membership validation
Multi-tenant MCP skill registries let users belong to multiple organizations and switch between them via a session-level context switch. The session's orgId controls which organization's data is returned by all subsequent API calls — it's the tenant isolation boundary. When the /api/orgs/switch endpoint accepts an arbitrary orgId from the request body and stores it in the session without first confirming that the requesting user is a member of that organization, the entire tenant isolation model collapses: any authenticated user can switch into any organization's context and read all its data.
// VULNERABLE — PRIVESC6-001
// /api/orgs/switch accepts orgId from request body, sets session.orgId.
// No membership check — any authenticated user can switch to any org.
// Attacker discovers org IDs via /api/orgs/list (their own orgs), notices the IDs
// are sequential UUIDs, or brute-forces the endpoint.
app.post('/api/orgs/switch', requireAuth, async (req, res) => {
const { orgId } = req.body;
// VULNERABLE: sets session.orgId without checking user is a member
req.session.orgId = orgId;
await req.session.save();
// Returns the target org's data — attacker now has full access
const org = await db.orgs.findById(orgId);
res.json({ org, switched: true });
});
// FIXED — PRIVESC6-001
// Fix: Check org membership before updating session.orgId.
// The membership check must use the user's ID from the authenticated session —
// never from the request body.
app.post('/api/orgs/switch', requireAuth, async (req, res) => {
const { orgId } = req.body;
const userId = req.session.userId; // From authenticated session — not request body
// FIX: Verify user is an active member of the target org before switching
const membership = await db.orgMembers.findOne({
where: { orgId, userId, status: 'active' },
});
if (!membership) {
// FIX: Return 403 — do NOT reveal whether the org exists (org enumeration)
return res.status(403).json({ error: 'Forbidden' });
}
// FIX: Only update session after confirming membership
req.session.orgId = orgId;
req.session.orgRole = membership.role; // also update role for the new org context
await req.session.save();
const org = await db.orgs.findById(orgId);
res.json({ org, switched: true });
});
Org IDs are not secrets — membership is the guard: UUIDs are not secret identifiers. Any API that checks "does org X exist?" rather than "is the authenticated user a member of org X?" has the wrong security model. Org IDs appear in browser URLs, API responses, invoice PDFs, and GitHub Actions secrets — they are observable. The access control must be membership-based, not ID-based: the question is never "do you know the org ID?" but "are you a member of this org?"
PRIVESC6-002 — Cross-tenant resource access persisting after org switch
Even after the PRIVESC6-001 switch vulnerability is fixed, a related misconfiguration allows persistent cross-tenant access: when orgId is validated only at switch time and cached in the session, but individual resource-access endpoints check only WHERE resourceId = ? AND orgId = req.session.orgId without re-validating that the session user is still an active member of the session's org, an attacker who exploited PRIVESC6-001 (or who was legitimately invited to org-A and later removed) may retain access to org-A's resources for the lifetime of their session.
// VULNERABLE — PRIVESC6-002
// orgId is set in session and re-used in all resource queries.
// Membership not re-validated on each request — relies on session state alone.
// Attacker exploited PRIVESC6-001 to switch to org-A, now reads org-A's skills
// even after switch is "fixed" because session.orgId is still org-A.
app.get('/api/skills', requireAuth, async (req, res) => {
// VULNERABLE: trusts req.session.orgId without re-validating membership
const skills = await db.skills.findAll({
where: { orgId: req.session.orgId },
});
res.json({ skills });
});
// FIXED — PRIVESC6-002
// Fix: Re-validate org membership on every request that reads org-scoped data.
// Use middleware that checks membership for every route needing org context.
// This also covers the case where a user is removed from an org mid-session.
async function requireOrgMembership(req, res, next) {
const { userId, orgId } = req.session;
if (!orgId) return res.status(400).json({ error: 'No org context in session' });
// FIX: Re-validate membership on every request — not just at switch time
const membership = await db.orgMembers.findOne({
where: { userId, orgId, status: 'active' },
});
if (!membership) {
// FIX: Revoke the stale org context from the session
req.session.orgId = null;
req.session.orgRole = null;
await req.session.save();
return res.status(403).json({ error: 'You are no longer a member of this organization' });
}
req.orgRole = membership.role;
next();
}
// FIX: Apply requireOrgMembership to all org-scoped routes
app.get('/api/skills', requireAuth, requireOrgMembership, async (req, res) => {
// Now safe: orgId is validated on this request
const skills = await db.skills.findAll({
where: { orgId: req.session.orgId },
});
res.json({ skills });
});
Session state is a cache, not a source of truth: Session storage (Redis, database-backed sessions) is a cache of the user's last-known authorization state. It is not authoritative: users get removed from orgs, their roles change, accounts get suspended — all while existing sessions remain valid. For sensitive operations, re-query the authorization state from the database on each request rather than trusting the session's cached state. The performance cost of a single indexed membership lookup is negligible compared to the cost of a cross-tenant data breach.
PRIVESC6-003 — Invite token reveals recipient email before acceptance
MCP skill registry team plans allow org admins to invite users by email. The invitation system generates a unique token and sends a link /invite/{token} to the recipient. When the GET /api/invite/{token} endpoint used to preview the invitation returns the full recipientEmail in the response body — even before the invitation is accepted — it allows anyone who obtains the invite token to learn the email address it was sent to. Invite tokens appear in link-preview bots, email tracking pixels, forwarded messages, and browser history. An attacker who discovers an invite token (even from a different org) can enumerate the email addresses of all employees being onboarded to the registry.
// VULNERABLE — PRIVESC6-003
// GET /api/invite/{token} returns full recipientEmail before acceptance.
// Attacker who guesses or obtains the token learns the recipient's email.
// Combined with org enumeration, enables targeted phishing of invited users.
app.get('/api/invite/:token', async (req, res) => {
const invite = await db.invites.findOne({
where: { token: req.params.token, status: 'pending' },
});
if (!invite) return res.status(404).json({ error: 'Invitation not found' });
// VULNERABLE: returns full email before invitation is accepted
res.json({
orgName: invite.orgName,
inviterName: invite.inviterName,
recipientEmail: invite.recipientEmail, // VULNERABLE: full email disclosed
role: invite.role,
expiresAt: invite.expiresAt,
});
});
// FIXED — PRIVESC6-003
// Fix 1: Return only the masked email before acceptance — first char + '@' + domain.
// e.g. "alice@example.com" → "a***@example.com"
// Fix 2: After acceptance, the authenticated user's own email is confirmed —
// there's no need to return the email at all (they know their own email).
// Fix 3: Rate-limit and log invite token lookups to detect enumeration attempts.
function maskEmail(email) {
const [local, domain] = email.split('@');
// FIX: Return first character + *** + @ + domain
return `${local[0]}***@${domain}`;
}
app.get('/api/invite/:token', async (req, res) => {
const invite = await db.invites.findOne({
where: { token: req.params.token, status: 'pending' },
});
if (!invite) return res.status(404).json({ error: 'Invitation not found' });
// FIX 1: Mask email before acceptance
res.json({
orgName: invite.orgName,
inviterName: invite.inviterName,
recipientEmail: maskEmail(invite.recipientEmail), // FIX: masked
role: invite.role,
expiresAt: invite.expiresAt,
});
});
// Invite acceptance — only proceeds when authenticated user's email matches
app.post('/api/invite/:token/accept', requireAuth, async (req, res) => {
const invite = await db.invites.findOne({
where: { token: req.params.token, status: 'pending' },
});
if (!invite) return res.status(404).json({ error: 'Invitation not found or expired' });
// FIX: Validate that the authenticated user's email matches the invite recipient
if (invite.recipientEmail.toLowerCase() !== req.user.email.toLowerCase()) {
return res.status(403).json({ error: 'This invitation is not for your account' });
}
await db.orgMembers.create({
orgId: invite.orgId,
userId: req.user.id,
role: invite.role,
status: 'active',
});
await invite.update({ status: 'accepted', acceptedAt: new Date() });
res.json({ success: true, orgId: invite.orgId });
});
PRIVESC6-004 — Stripe customerId cross-tenant billing data access
When an org's billing page fetches invoices from Stripe using a customerId query parameter supplied by the browser — rather than resolving the customerId from the server-side org record — an attacker can substitute any Stripe customer ID and access another org's billing history. Stripe customer IDs follow a predictable format (cus_ + 14-character alphanumeric string) and are not secret — they appear in Stripe invoice PDFs, receipt emails, webhook payloads, and can sometimes be found in leaked API logs. The billing data returned includes invoice amounts, subscription tier, card last four digits, and sometimes company name and address.
// VULNERABLE — PRIVESC6-004
// Billing endpoint accepts customerId from query params.
// Attacker modifies the request to use another org's Stripe customerId.
// Receives that org's invoice history, subscription status, and card metadata.
app.get('/api/billing/invoices', requireAuth, requireOrgMembership, async (req, res) => {
const { customerId } = req.query; // VULNERABLE: customerId from client request
// VULNERABLE: fetches Stripe invoices for attacker-supplied customerId
const invoices = await stripe.invoices.list({
customer: customerId, // could be any org's Stripe customer ID
limit: 24,
});
res.json({ invoices: invoices.data });
});
// FIXED — PRIVESC6-004
// Fix: Never accept customerId from the client. Resolve it from the authenticated
// org's server-side record. The session's orgId (validated by requireOrgMembership)
// is the source of truth for which Stripe customer to query.
app.get('/api/billing/invoices', requireAuth, requireOrgMembership, async (req, res) => {
// FIX: Resolve customerId from the authenticated org's database record
const org = await db.orgs.findById(req.session.orgId, {
attributes: ['id', 'stripeCustomerId'],
});
if (!org?.stripeCustomerId) {
return res.status(404).json({ error: 'No billing account found for this organization' });
}
// FIX: Use only the server-side-resolved customerId — never from client input
const invoices = await stripe.invoices.list({
customer: org.stripeCustomerId,
limit: 24,
});
res.json({ invoices: invoices.data });
});
// Similarly for subscription, payment methods, and upcoming invoice endpoints:
app.get('/api/billing/subscription', requireAuth, requireOrgMembership, async (req, res) => {
const org = await db.orgs.findById(req.session.orgId, {
attributes: ['id', 'stripeCustomerId', 'stripeSubscriptionId'],
});
if (!org?.stripeSubscriptionId) {
return res.status(404).json({ error: 'No active subscription' });
}
// FIX: stripeSubscriptionId from server-side org record — never from client
const subscription = await stripe.subscriptions.retrieve(org.stripeSubscriptionId);
res.json({ subscription });
});
Stripe IDs are not authorization tokens: Third-party service identifiers (Stripe customer IDs, Intercom user IDs, Segment anonymous IDs) are routing keys, not authorization credentials. They identify a customer within the third-party service but carry no authorization guarantee in your system. Never use a client-supplied third-party ID as a database or API query key — always resolve it from your own server-side record for the authenticated session's org, then use the server-resolved value to call the third-party API. This applies to any external service: Stripe, Intercom, Mixpanel, Twilio, SendGrid, and similar.
Summary — SA-SKL-PRIVESC6 at a glance
| Pattern | Root cause | Fix | Severity |
|---|---|---|---|
| PRIVESC6-001 | Org switch sets session.orgId without membership check | Verify membership before updating session.orgId | CRITICAL |
| PRIVESC6-002 | Org membership validated only at switch time — not on each request | requireOrgMembership middleware on all org-scoped routes | CRITICAL |
| PRIVESC6-003 | Invite token preview returns full recipient email | Return masked email (first char + *** + domain) | HIGH |
| PRIVESC6-004 | Stripe customerId accepted from client request | Resolve customerId from server-side org record only | HIGH |
SkillAudit's privilege escalation scanner checks all four SA-SKL-PRIVESC6 patterns: it inspects org-switch endpoints for membership validation, resource-access middleware for session-based vs. request-time org validation, invite endpoints for email disclosure before acceptance, and billing endpoints for client-supplied third-party IDs. See also SA-SKL-PRIVESC5 (invite acceptance and role escalation IDOR).