← Blog

Multi-Tenant Isolation Failures in Claude Skills

Claude skills that serve multiple organizations from a shared database are only as secure as their weakest tenant boundary. A single missing WHERE clause, a cache key that omits the organization ID, or a raw SQL query that bypasses ORM-level middleware is enough to expose one customer's audit data to another. These are IDOR vulnerabilities at the architecture level — systematic failures that affect every record in a table, not just one endpoint.

By SkillAudit  |  6 Nov 2026

Why multi-tenant isolation is a distinct concern for MCP skills

An MCP skill running in a Claude agent context often handles requests from multiple organizational accounts within the same process. The LLM selects which tool to call and what arguments to pass, but it cannot enforce database-level tenant isolation — that is entirely the skill developer's responsibility. When the isolation fails, the attack surface is unusually large: any authenticated user at any tenant can potentially read any other tenant's data simply by supplying a known or guessable resource identifier. Because UUIDs are sometimes predictable within a time window and audit result IDs may be sequential, enumeration is a realistic threat.

SA-SKL-MULTITENANT in scope: MULTITENANT-001 missing organizationId filter in database queries, MULTITENANT-002 shared in-memory cache without tenant key prefix, MULTITENANT-003 Prisma $queryRaw bypasses ORM tenant middleware, MULTITENANT-004 IP-keyed rate limiter bleeds across tenants behind shared NAT.

MULTITENANT-001 — Missing organizationId filter in database queries

The most common multi-tenancy failure is a query that filters on a resource's primary key but omits the organization ownership check. The developer writes WHERE id = $1 and forgets AND organization_id = $2. Any authenticated user who can invoke the skill — from any tenant — can retrieve any audit result by supplying its UUID. Because the skill accepts the audit ID as a tool argument and the LLM passes it through, an attacker who finds a valid UUID through enumeration or a leaked URL gains full read access to another organization's data.

// VULNERABLE — query filters by audit ID only; no organization ownership check
import { Pool } from 'pg';

const db = new Pool({ connectionString: process.env.DATABASE_URL });

server.tool(
  'get_audit_result',
  { auditId: z.string().uuid() },
  async ({ auditId }, { user }) => {
    // MISSING: AND organization_id = $2
    // Any authenticated user can read any audit result by guessing/enumerating the UUID
    const result = await db.query(
      'SELECT * FROM audit_results WHERE id = $1',
      [auditId]
    );

    if (result.rows.length === 0) {
      throw new Error('AUDIT_NOT_FOUND');
    }

    return result.rows[0];
  }
);
// FIXED — always bind organization_id from the authenticated session, not from tool args
import { Pool } from 'pg';

const db = new Pool({ connectionString: process.env.DATABASE_URL });

// Helper: enforces org filter on every audit query — use this everywhere
async function getAuditForOrg(auditId: string, organizationId: string) {
  const result = await db.query(
    // Both conditions required: resource must exist AND belong to caller's org
    `SELECT id, skill_name, status, score, created_at, summary
     FROM audit_results
     WHERE id = $1 AND organization_id = $2`,
    [auditId, organizationId]
  );
  return result.rows[0] ?? null;
}

server.tool(
  'get_audit_result',
  { auditId: z.string().uuid() },
  async ({ auditId }, { user }) => {
    // organizationId comes from the verified JWT/session — never from tool args
    const audit = await getAuditForOrg(auditId, user.organizationId);

    if (!audit) {
      // Return same error whether record doesn't exist or belongs to another org
      throw new Error('AUDIT_NOT_FOUND');
    }

    return audit;
  }
);
CRITICAL
SA-SKL-MULTITENANT-001 — Database query filters on resource primary key without organization_id ownership check; any authenticated user can read records belonging to other tenants by supplying a known or enumerated UUID as a tool argument.

MULTITENANT-002 — Shared in-memory LRU cache without tenant key prefix

An in-process LRU cache speeds up repeated lookups for the same resource. The bug occurs when the cache key is scoped to the resource identifier alone — for example, the skill name string — without including the requesting organization. When tenant A requests skill info for github-skill, the result is stored under the key github-skill. When tenant B requests the same key a moment later, the cache returns tenant A's cached result. This is a cross-tenant data leak that is difficult to detect in logs because the database is never queried for tenant B's request.

// VULNERABLE — cache key is resource ID only; different tenants share the same cache entry
import LRU from 'lru-cache';

const cache = new LRU<string, SkillRecord>({ max: 500, ttl: 1000 * 60 * 5 });

server.tool(
  'get_skill_details',
  { skillName: z.string() },
  async ({ skillName }, { user }) => {
    // Cache key has no tenant dimension — first org's result served to all orgs
    const cacheKey = skillName;
    const cached = cache.get(cacheKey);
    if (cached) return cached;

    const record = await db.query(
      'SELECT * FROM skills WHERE name = $1 AND organization_id = $2',
      [skillName, user.organizationId]
    );

    const skill = record.rows[0];
    if (!skill) throw new Error('SKILL_NOT_FOUND');

    cache.set(cacheKey, skill);  // Stores org-specific data under shared key
    return skill;
  }
);
// FIXED — prefix every cache key with the organizationId
import LRU from 'lru-cache';

const cache = new LRU<string, SkillRecord>({ max: 500, ttl: 1000 * 60 * 5 });

server.tool(
  'get_skill_details',
  { skillName: z.string() },
  async ({ skillName }, { user }) => {
    // Cache key is scoped to the tenant — no cross-tenant cache hits possible
    const cacheKey = `${user.organizationId}:${skillName}`;
    const cached = cache.get(cacheKey);
    if (cached) return cached;

    const record = await db.query(
      'SELECT id, name, version, status, public_config FROM skills WHERE name = $1 AND organization_id = $2',
      [skillName, user.organizationId]
    );

    const skill = record.rows[0];
    if (!skill) throw new Error('SKILL_NOT_FOUND');

    cache.set(cacheKey, skill);
    return skill;
  }
);

Cache invalidation on update: When a skill record is updated, invalidate by prefix. Store a secondary index of all keys for an org, or use a namespaced cache layer (e.g., Redis with DEL orgId:* pattern) so that updates to org A's data never serve stale results to org A while also ensuring org B cannot observe them.

HIGH
SA-SKL-MULTITENANT-002 — In-memory LRU cache keyed on resource identifier without organization prefix; first tenant's cached response served to subsequent tenants requesting the same resource name, causing cross-tenant data disclosure that is invisible in database query logs.

MULTITENANT-003 — Prisma $queryRaw bypasses ORM-level tenant middleware

Prisma's middleware and extension system makes it straightforward to enforce multi-tenant isolation globally: a single middleware that appends where: { organizationId } to every model find operation means developers cannot accidentally forget the filter. The critical gap is that $queryRaw and $executeRaw bypass all Prisma middleware entirely. If a developer adds a raw SQL query for a performance-sensitive report endpoint and forgets to add the organization_id parameter manually, the automatic protection that every other query relies on simply does not apply.

// VULNERABLE — Prisma middleware enforces org filter on model ops, but $queryRaw bypasses it
import { PrismaClient } from '@prisma/client';

const prisma = new PrismaClient();

// Middleware that auto-applies tenant filter to all model operations
prisma.$use(async (params, next) => {
  if (params.action.startsWith('find') && params.args) {
    params.args.where = { ...params.args.where, organizationId: getCurrentOrgId() };
  }
  return next(params);
});

server.tool(
  'get_usage_report',
  { startDate: z.string(), endDate: z.string() },
  async ({ startDate, endDate }, { user }) => {
    // $queryRaw completely skips the middleware above — no org filter applied
    // Returns usage data for ALL organizations in the database
    const rows = await prisma.$queryRaw`
      SELECT organization_id, skill_name, SUM(invocations) as total
      FROM usage_events
      WHERE event_date BETWEEN ${startDate} AND ${endDate}
      GROUP BY organization_id, skill_name
      ORDER BY total DESC
    `;
    return { rows };
  }
);
// FIXED — explicitly pass organizationId in raw query; ban $queryRaw via ESLint rule
import { PrismaClient, Prisma } from '@prisma/client';

const prisma = new PrismaClient();

// In .eslintrc.json add:
// "no-restricted-syntax": ["error", {
//   "selector": "MemberExpression[property.name='$queryRaw']",
//   "message": "Use Prisma model operations instead of $queryRaw to preserve tenant middleware."
// }]

server.tool(
  'get_usage_report',
  { startDate: z.string(), endDate: z.string() },
  async ({ startDate, endDate }, { user }) => {
    // organizationId must be passed explicitly — middleware does NOT apply here
    const organizationId = user.organizationId;

    // Use Prisma.sql tagged template to prevent SQL injection while adding org filter
    const rows = await prisma.$queryRaw(Prisma.sql`
      SELECT skill_name, SUM(invocations) as total
      FROM usage_events
      WHERE organization_id = ${organizationId}
        AND event_date BETWEEN ${startDate}::date AND ${endDate}::date
      GROUP BY skill_name
      ORDER BY total DESC
      LIMIT 100
    `);

    return { rows };
  }
);
HIGH
SA-SKL-MULTITENANT-003 — Prisma $queryRaw call bypasses ORM middleware that enforces organization_id filter on all model operations; raw report query returns usage data for every tenant in the database to any authenticated caller.

MULTITENANT-004 — Per-tenant rate limits not enforced

IP-address-based rate limiting breaks down in multi-tenant environments where organizations connect from behind a corporate NAT gateway or a cloud egress IP. All users from that IP share a single counter, so a high-volume tenant's API calls consume rate limit budget for every other organization on the same IP range. Conversely, a tenant that cycles through many IP addresses (e.g., using rotating proxies) faces no meaningful per-tenant limit. The correct key for a multi-tenant rate limiter is a composite of the organization identifier and the IP address, ensuring each tenant has its own independent counter while still providing per-IP protection.

// VULNERABLE — rate limiter keyed on IP only; tenants share budget and can starve each other
import rateLimit from 'express-rate-limit';

const limiter = rateLimit({
  windowMs: 60 * 1000,  // 1 minute window
  max: 200,             // 200 requests per window per IP
  keyGenerator: (req) => req.ip,  // IP-only key — tenant-unaware
  standardHeaders: true,
  legacyHeaders: false,
});

app.use('/api/skill/', limiter);

// Org A (100 req/min) and Org B (100 req/min) both behind 203.0.113.5
// Combined they hit 200/min limit — each gets 429 at 101 reqs despite being within their fair share
// Meanwhile Org C rotating proxies faces no effective limit at all
// FIXED — composite key: organizationId + IP; each tenant has an independent counter
import rateLimit from 'express-rate-limit';
import RedisStore from 'rate-limit-redis';
import { createClient } from 'redis';

const redisClient = createClient({ url: process.env.REDIS_URL });
await redisClient.connect();

const limiter = rateLimit({
  windowMs: 60 * 1000,
  max: 200,              // 200 requests per org per minute (regardless of their IP)
  // Composite key: organizationId isolates tenants; IP provides per-proxy protection
  keyGenerator: (req) => {
    const orgId = (req as AuthedRequest).user?.organizationId ?? 'anonymous';
    return `${orgId}:${req.ip}`;
  },
  store: new RedisStore({
    // Redis store ensures limits survive server restarts and work across instances
    sendCommand: (...args: string[]) => redisClient.sendCommand(args),
  }),
  handler: (req, res) => {
    res.status(429).json({
      error: 'RATE_LIMITED',
      message: 'Too many requests. Your organization limit resets in 1 minute.',
    });
  },
  standardHeaders: true,
  legacyHeaders: false,
});

app.use('/api/skill/', limiter);
HIGH
SA-SKL-MULTITENANT-004 — Rate limiter uses IP address as the sole key; organizations sharing a NAT gateway compete for a single counter, allowing one high-volume tenant to exhaust the IP-level budget and trigger 429 responses for other tenants on the same egress IP.