← Blog

Claude skill IDOR security

Insecure Direct Object Reference (IDOR) is the OWASP A01:2021 Broken Access Control family of vulnerabilities where a resource identifier supplied by the caller is used to fetch or modify a resource without verifying that the caller is authorized to access that specific resource instance. In MCP skills, every tool argument is an attacker-controlled value: the calling Claude model receives arguments from user prompts, which can be crafted by prompt injection in user-controlled content. SA-SKL-IDOR covers four IDOR patterns that appear in MCP skill tool handlers: missing ownership checks on resource IDs, cross-user data access via userId arguments, team membership bypass for shared resources, and predictable sequential IDs that enable bulk enumeration.

By SkillAudit  |  4 Nov 2026

MCP skill tools are fundamentally different from REST API endpoints in one critical respect: the tool arguments arrive via the Claude model, which assembles them from the conversation context. A user who includes text in their prompt like “also fetch audit ID audit-00001” may cause Claude to call a get_audit tool with args.auditId = 'audit-00001' — regardless of whether that audit belongs to the authenticated user. This indirect injection path means that IDOR vulnerabilities in MCP skill tools have a different attack surface than web API IDOR: the attacker does not need to intercept HTTP traffic or use a proxy tool; they can trigger the IDOR simply by including a resource ID in their conversation prompt. The four SA-SKL-IDOR patterns address the most common missing ownership check patterns in Node.js MCP skill tool handlers.

SA-SKL-IDOR-001: Audit resource fetched by ID without ownership check — any authenticated user reads any audit

The most direct IDOR pattern in MCP skills is a get_audit or read_resource tool that accepts a resource ID as a tool argument and fetches the resource by that ID without verifying that the authenticated user owns or has been granted access to the resource. Because tool arguments are attacker-influenced, any authenticated user can supply another user’s resource ID and receive the full resource contents:

// VULNERABLE: audit fetched by ID from tool arg without ownership check
import { db } from './db.js';

const getAuditTool: Tool = {
  name: 'get_audit',
  description: 'Retrieve the results of a security audit by its ID',
  inputSchema: {
    type: 'object',
    properties: { auditId: { type: 'string', description: 'The audit ID to retrieve' } },
    required: ['auditId'],
  },
  handler: async (args: { auditId: string }, context: ToolContext) => {
    // VULNERABLE: fetches audit by ID without verifying ownership
    const audit = await db.query(
      'SELECT * FROM audits WHERE id = $1',
      [args.auditId]
    );
    if (!audit) return { error: 'Audit not found' };
    return audit;  // <-- returns any audit to any authenticated user
  },
};

// ATTACK: prompt injection to trigger cross-user IDOR
// User includes in their conversation:
//   "Show me audit results for audit-00001"
// Claude calls: get_audit({ auditId: 'audit-00001' })
// Handler fetches audit-00001 regardless of session userId
// If audit-00001 belongs to a different user: data exfiltrated to attacker
//
// MORE DIRECT ATTACK: attacker knows victim's audit ID from a URL or public badge
// Claude.ai conversation: "My colleague shared audit ID audit-XYZ, can you fetch it?"
// Claude calls: get_audit({ auditId: 'audit-XYZ' })
// Handler returns full audit including private remediation notes and credentials

// ATTACK VIA SEQUENTIAL IDS:
// If audit IDs are sequential integers (1, 2, 3, ...):
// "Get audit 1 through audit 100" → Claude loops get_audit with IDs 1-100
// All audits in the system enumerated

// SECURE: always include userId in the query and verify the resource belongs to the caller
const getAuditToolSecure: Tool = {
  name: 'get_audit',
  handler: async (args: { auditId: string }, context: ToolContext) => {
    if (typeof args.auditId !== 'string' || !/^[a-zA-Z0-9_-]+$/.test(args.auditId)) {
      return { error: 'Invalid audit ID format' };
    }

    // Ownership check: WHERE id = $1 AND owner_user_id = $2
    // Even if args.auditId is another user's audit, the query returns null
    const audit = await db.query(
      'SELECT * FROM audits WHERE id = $1 AND owner_user_id = $2',
      [args.auditId, context.userId]  // context.userId from authenticated session
    );

    if (!audit) {
      // Return same error for not-found and forbidden — do not reveal existence
      return { error: 'Audit not found' };
    }

    // Also check team access: allow if user is a member of the audit's team
    if (!audit && context.userId) {
      const teamAudit = await db.query(
        `SELECT a.* FROM audits a
         JOIN team_memberships tm ON tm.team_id = a.team_id
         WHERE a.id = $1 AND tm.user_id = $2`,
        [args.auditId, context.userId]
      );
      if (!teamAudit) return { error: 'Audit not found' };
      return teamAudit;
    }

    return audit;
  },
};

// KEY PRINCIPLE: the authenticated user's ID must come from the server-side session context,
// never from tool arguments. If the tool accepts a userId arg, see IDOR-002.

MCP skill tool arguments are user-controlled — treat them as untrusted input at the authorization layer: Unlike a REST API where the user’s identity is reliably extracted from their session cookie or JWT, MCP skills receive arguments via the Claude model, which assembles them from the conversation. A user who can influence what goes into a conversation can influence the tool arguments, including resource IDs. The ownership check in the database query — WHERE id = $1 AND owner_user_id = $2 — is the correct defense: even if the attacker supplies a valid resource ID, the query returns null unless the resource belongs to the authenticated user whose ID comes from the session context, not from tool arguments.

HIGH
SA-SKL-IDOR-001 — Tool handler fetches resource with WHERE id = $1 using args.auditId without AND owner_user_id = $2 ownership check: any authenticated user reads any resource by supplying its ID in a tool argument; prompt injection allows the attacker to fetch resources they do not own by including target IDs in conversation prompts. Fix: add ownership constraint to all resource-fetching queries: WHERE id = $1 AND owner_user_id = $2 where the user ID comes from the session context. Detection: db.query('SELECT ... WHERE id = $1', [args. without second user-constraining condition → HIGH.

SA-SKL-IDOR-002: Cross-user data access via userId tool argument — any user reads any user’s profile

Some MCP skill tools accept a userId or targetUserId argument to fetch data about a specific user — for example, a get_user_audit_history tool that shows a user’s past audits for team management purposes. The IDOR occurs when the tool uses the caller-supplied userId directly in the database query without verifying that the caller is either (a) requesting their own data or (b) an admin or team lead authorized to view other users’ data. Any authenticated user can supply any userId value and receive that user’s private data:

// VULNERABLE: userId from tool args used directly — no self-check or admin check
const getUserHistoryTool: Tool = {
  name: 'get_user_audit_history',
  description: 'Retrieve audit history for a user',
  inputSchema: {
    type: 'object',
    properties: { userId: { type: 'string', description: 'User ID to look up' } },
    required: ['userId'],
  },
  handler: async (args: { userId: string }, context: ToolContext) => {
    // VULNERABLE: uses args.userId directly — no check that caller owns this userId
    const history = await db.query(
      'SELECT * FROM audits WHERE owner_user_id = $1 ORDER BY created_at DESC',
      [args.userId]  // attacker supplies any userId
    );
    return { history };
  },
};

// ATTACK: attacker supplies victim's userId
// If attacker knows victim's userId (from public profile, URL, or enumerating IDs):
// "Get audit history for user 'victim-user-uuid'"
// Claude calls: get_user_audit_history({ userId: 'victim-user-uuid' })
// Returns victim's complete audit history: repository URLs, security findings,
// private remediation notes, payment plan details

// ALSO VULNERABLE: admin-only operations performed by any authenticated user
const promoteUserTool: Tool = {
  name: 'update_user_role',
  handler: async (args: { userId: string; newRole: string }, context: ToolContext) => {
    // VULNERABLE: no admin check on caller; any user can update any other user's role
    await db.query(
      'UPDATE users SET role = $1 WHERE id = $2',
      [args.newRole, args.userId]
    );
    return { updated: true };
  },
};

// SECURE: enforce access control based on session context
const getUserHistoryToolSecure: Tool = {
  name: 'get_user_audit_history',
  handler: async (args: { userId?: string }, context: ToolContext) => {
    // Determine target userId: default to session user if not specified
    let targetUserId: string;

    if (!args.userId || args.userId === context.userId) {
      // User is requesting their own history — always allowed
      targetUserId = context.userId;
    } else {
      // User is requesting another user's history — check if caller is an admin
      // or team lead with explicit access to the target user
      const caller = await db.query(
        'SELECT role FROM users WHERE id = $1',
        [context.userId]
      );
      if (caller?.role !== 'admin' && caller?.role !== 'team_lead') {
        return { error: 'Access denied: cannot view other users\' audit history' };
      }
      // Additional team-scoped check: team_lead can only see members of their team
      if (caller?.role === 'team_lead') {
        const isMember = await db.query(
          `SELECT 1 FROM team_memberships tm1
           JOIN team_memberships tm2 ON tm1.team_id = tm2.team_id
           WHERE tm1.user_id = $1 AND tm2.user_id = $2`,
          [context.userId, args.userId]
        );
        if (!isMember) return { error: 'Target user is not in your team' };
      }
      targetUserId = args.userId;
    }

    const history = await db.query(
      'SELECT id, repo_url, severity, status, created_at FROM audits WHERE owner_user_id = $1 ORDER BY created_at DESC LIMIT 50',
      [targetUserId]
    );
    return { history };
  },
};

Tool arguments that accept a userId create a horizontal privilege escalation risk: A tool that accepts a userId argument and uses it to fetch user-specific data must enforce one of two invariants: (1) the userId must equal the session user’s ID (self-access only), or (2) the caller must hold an explicit permission (admin, team lead) to access data for the specified user. The session user’s ID must come from the authenticated session context, never from a tool argument. A tool that lets a caller specify an arbitrary userId and receives that user’s data without any of these checks is an IDOR regardless of how well other parts of the skill are secured.

HIGH
SA-SKL-IDOR-002 — Tool handler uses args.userId directly in query without checking args.userId === context.userId or admin role: attacker supplies victim’s userId in tool argument; receives victim’s complete data; horizontal privilege escalation across all users in the system. Fix: compare args.userId to context.userId; default to session user if unspecified; check admin/team_lead role before granting cross-user access. Detection: WHERE owner_user_id = $1 ... [args.userId] without self-check or role guard → HIGH.

SA-SKL-IDOR-003: Team resource access without membership verification — non-member reads shared team audit

MCP skills that implement team-based resource sharing — where multiple team members can access a shared audit or configuration — must verify that the requesting user is an active member of the team that owns the resource. IDOR occurs when the team membership check is omitted: the skill verifies that the team exists and owns the resource, but does not verify that the requesting user belongs to that team. Any authenticated user who can discover a team’s ID or a team-owned resource’s ID gains access to all resources shared within that team:

// VULNERABLE: team resource access — team ownership checked but not user membership
const getTeamAuditTool: Tool = {
  name: 'get_team_audit',
  handler: async (args: { auditId: string; teamId: string }, context: ToolContext) => {
    // Checks that audit belongs to the team — but NOT that the caller is a team member
    const audit = await db.query(
      'SELECT * FROM audits WHERE id = $1 AND team_id = $2',
      [args.auditId, args.teamId]  // <-- caller supplies both auditId and teamId
    );
    if (!audit) return { error: 'Audit not found' };
    return audit;  // <-- returns team audit to any authenticated user
  },
};

// ATTACK: attacker guesses or discovers a team ID
// args.teamId = 'team-known-from-public-audit-badge'
// args.auditId = 'audit-found-from-badge-URL'
// Handler finds audit in team, returns it — no membership check for the caller
//
// In practice: team IDs may be visible in webhook URLs, badge embed codes,
// or public audit pages. Once an attacker has a team ID, they can enumerate
// all audits for that team by trying different auditId values.

// ALSO VULNERABLE: team-scoped write without membership check
const addTeamMemberTool: Tool = {
  name: 'add_team_member',
  handler: async (args: { teamId: string; newUserId: string }, context: ToolContext) => {
    // No check that context.userId is a team admin or even a team member
    await db.query(
      'INSERT INTO team_memberships (team_id, user_id) VALUES ($1, $2)',
      [args.teamId, args.newUserId]
    );
    return { added: true };
  },
};

// SECURE: always verify membership in the resource query
const getTeamAuditToolSecure: Tool = {
  name: 'get_team_audit',
  handler: async (args: { auditId: string }, context: ToolContext) => {
    // Single query: audit must belong to a team that the authenticated user is a member of
    // No teamId from tool args — team is derived from the audit's ownership + user's membership
    const audit = await db.query(
      `SELECT a.*
       FROM audits a
       JOIN team_memberships tm ON tm.team_id = a.team_id
       WHERE a.id = $1
         AND (
           a.owner_user_id = $2       -- user is the direct owner
           OR tm.user_id = $2         -- user is a team member
         )`,
      [args.auditId, context.userId]
    );

    if (!audit) {
      // Same error for not-found and access-denied — do not reveal existence
      return { error: 'Audit not found' };
    }
    return audit;
  },
};

// SECURE: team write operations require team membership check on the caller
const addTeamMemberToolSecure: Tool = {
  name: 'add_team_member',
  handler: async (args: { teamId: string; newUserId: string }, context: ToolContext) => {
    // Verify caller is an admin of this team
    const membership = await db.query(
      'SELECT role FROM team_memberships WHERE team_id = $1 AND user_id = $2',
      [args.teamId, context.userId]
    );
    if (!membership || membership.role !== 'admin') {
      return { error: 'Only team admins can add members' };
    }
    await db.query(
      'INSERT INTO team_memberships (team_id, user_id, role) VALUES ($1, $2, $3) ON CONFLICT DO NOTHING',
      [args.teamId, args.newUserId, 'member']
    );
    return { added: true };
  },
};

Team ownership and user membership are two separate checks — both are required: Verifying that a resource belongs to a team prevents one IDOR (attacker accesses resources from a different team). But it does not verify that the requesting user is a member of that team, which is a second IDOR at the team membership level. The correct pattern is a single JOIN query that simultaneously checks resource ownership (the resource belongs to a specific team) and user membership (the authenticated user is a member of that team). This two-condition check ensures that only team members reach team resources, without requiring separate round-trips.

HIGH
SA-SKL-IDOR-003 — Team resource query verifies team_id = $2 from tool args but does not join team_memberships to verify context.userId is a member: any authenticated user who discovers a valid teamId can access all shared resources of that team; non-members read confidential team audits and security findings. Fix: derive team access via JOIN on team_memberships WHERE user_id = context.userId; never accept teamId from tool args as the authorization anchor. Detection: WHERE ... team_id = [args.teamId] without JOIN team_memberships check on context.userId → HIGH.

SA-SKL-IDOR-004: Sequential integer audit IDs enable bulk enumeration — attacker iterates 1 through N

When resource identifiers are sequential integers (1, 2, 3...) or otherwise predictable (sequential ULIDs, timestamp-prefixed IDs with low entropy suffixes), an attacker who can access one resource can enumerate all other resources by incrementing the ID. In MCP skills, an authenticated attacker can iterate over sequential IDs in a conversation loop — “get audit 1, get audit 2, get audit 3” — to harvest all resources in the system. Even with ownership checks in place, sequential IDs reveal the existence of resources the attacker does not own (through consistent timing or error messages), enabling targeted social engineering or resource existence mapping:

// VULNERABLE: sequential integer primary keys as external resource IDs
// Database schema:
// CREATE TABLE audits (
//   id SERIAL PRIMARY KEY,  -- <-- sequential integer: 1, 2, 3, ...
//   owner_user_id UUID NOT NULL,
//   repo_url TEXT NOT NULL,
//   ...
// )

// Tool that uses integer ID in args
const getAuditTool: Tool = {
  name: 'get_audit',
  handler: async (args: { auditId: number }, context: ToolContext) => {
    const audit = await db.query(
      'SELECT * FROM audits WHERE id = $1 AND owner_user_id = $2',
      [args.auditId, context.userId]
    );

    // Even with ownership check, the error message leaks existence:
    if (!audit) {
      // 'Not found' vs 'Access denied' reveals whether audit #42 exists
      // even if the caller doesn't own it — timing may also differ
      return { error: 'Audit not found or access denied' };
    }
    return audit;
  },
};

// ENUMERATION ATTACK:
// User: "Check audit IDs 1 through 500 and tell me which ones exist"
// Claude loops get_audit with args.auditId = 1, 2, 3, ..., 500
// For each ID: "not found" = doesn't exist; response within N ms = exists (even if forbidden)
// Attacker maps the existence of all 500 audits
// IDs with responses indicate: total audit volume, submission rate (time gaps between IDs),
// active customers (bunched IDs from same period = one customer's bulk submission)

// INFORMATION LEAK VIA ID SEQUENCE:
// Attacker submits their first audit: receives ID 7823
// Now knows: ~7823 audits were submitted before theirs
// Can estimate total customer count, revenue, growth rate

// SECURE: use UUID (v4) or other high-entropy opaque identifiers as external IDs
// Keep sequential integer as internal primary key for performance; expose UUID to clients

// Database schema:
// CREATE TABLE audits (
//   id SERIAL PRIMARY KEY,          -- internal, never exposed externally
//   external_id UUID NOT NULL UNIQUE DEFAULT gen_random_uuid(),  -- external reference
//   owner_user_id UUID NOT NULL,
//   ...
// )

// Tool uses external_id — a UUID — not the sequential integer id
const getAuditToolSecure: Tool = {
  name: 'get_audit',
  handler: async (args: { auditId: string }, context: ToolContext) => {
    // Validate UUID format — rejects sequential integers and other non-UUID strings
    if (!/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(args.auditId)) {
      return { error: 'Invalid audit ID format' };
    }

    const audit = await db.query(
      'SELECT * FROM audits WHERE external_id = $1 AND owner_user_id = $2',
      [args.auditId, context.userId]
    );

    if (!audit) return { error: 'Audit not found' };
    return { ...audit, id: undefined };  // never expose internal integer id
  },
};

// UUID benefits for IDOR prevention:
// 1. 2^122 possible values — brute force enumeration is infeasible
// 2. No ordering information leaks: UUID v4 is random, reveals no creation sequence
// 3. No count information: attacker cannot infer total resource count from observed IDs
// 4. Same error timing for 'not yours' and 'doesn't exist' — no existence oracle
//
// Use gen_random_uuid() (PostgreSQL) or crypto.randomUUID() (Node.js 15+) for generation
// Always store both: internal_id (SERIAL, for FK performance) + external_id (UUID, for API)

Use UUIDs (v4) for all externally exposed resource identifiers, regardless of ownership checks: Even with correct ownership checks, sequential integer IDs leak information: the total number of resources in the system, the submission rate, and the existence of resources the caller does not own. UUID v4 identifiers have 122 bits of randomness, making brute-force enumeration infeasible (2¹²² possible values). They also eliminate the information leakage inherent in sequential IDs. The standard pattern is to store a sequential internal primary key for database join performance and a separate UUID column as the externally exposed identifier. All tool arguments and API responses use the UUID; the internal integer is never exposed.

MEDIUM
SA-SKL-IDOR-004 — Resource identifiers in tool arguments are sequential integers or otherwise predictable: attacker iterates over ID range to map resource existence; total count of system resources inferred from first assigned ID; creation timing inferred from ID sequence gaps. Fix: use UUID (v4) as external resource identifier; validate UUID format in tool handler; never expose sequential integer primary keys in tool arguments or responses. Detection: tool argument typed as number or validated against numeric pattern for a resource ID; or SERIAL primary key used as the external identifier in tool schemas → MEDIUM.

Remediation summary

FindingSeverityVulnerable patternFixDetection signal
IDOR-001: Audit ID without ownership check HIGH WHERE id = args.auditId without AND owner_user_id = session.userId Add AND owner_user_id = $2 constraint; derive userId from session context SELECT ... WHERE id = $1 ... [args. without second user-constraining condition
IDOR-002: Cross-user data via userId arg HIGH Tool accepts userId arg and uses it in query without self-check or admin role check Default to session userId; check args.userId === context.userId; require admin role for cross-user access WHERE owner_user_id = [args.userId] without args.userId === context.userId guard
IDOR-003: Team resource without membership check HIGH WHERE team_id = args.teamId without JOIN on team_memberships for context.userId JOIN team_memberships in resource query; derive team access from user membership WHERE team_id = [args.teamId] without JOIN team_memberships WHERE user_id = context.userId
IDOR-004: Sequential ID enumeration MEDIUM Sequential integer or predictable IDs as external resource identifiers enable bulk enumeration Use UUID v4 as external identifier; validate UUID format; never expose internal integer PKs Tool argument typed as number for resource ID, or SERIAL PK used as external identifier

SkillAudit detects all four SA-SKL-IDOR-001 through IDOR-004 patterns through static analysis of skill tool handler database queries: resource-fetching queries without user ownership constraints, userId arguments used directly in queries without self-check guards, team-resource queries without membership JOIN, and tool schemas with numeric resource ID arguments. For related security patterns see SA-SKL-AUT authentication security, SA-SKL-SESS session and state security, and SA-SKL-CSRF CSRF protection security. See the complete SA-SKL attack surface reference for the full vulnerability taxonomy.

Scan your Claude skill for IDOR vulnerabilities

SkillAudit detects missing ownership checks, cross-user data access, team membership bypass, and sequential ID enumeration across the full SA-SKL-IDOR family in 60 seconds.

Get your free audit