← Blog

Claude MCP skill insecure deserialization — skill dependency resolution and version lock endpoints (SA-SKL-DESER52)

SA-SKL-DESER52 identifies four insecure deserialization vulnerabilities in MCP skill registry dependency resolution and version lock endpoints. A YAML !!js/function gadget in a Redis-cached lock file achieves RCE at every dependency conflict event; a BSON Code field in MongoDB triggers eval() on every version constraint resolution; a MessagePack payload poisons Object.prototype to bypass dependency auth registry-wide; and a node-serialize IIFE achieves RCE on every lock file aggregation request.

SA-SKL-DESER52 findings at a glance
CRITICALDESER52-001 — dependency lock file reads from Redis as YAML via yaml.load() DEFAULT_FULL_SCHEMA; !!js/function in lockFile.onResolveConflict achieves RCE at every dependency conflict resolution event; can modify resolved dependency versions before written to lock file
CRITICALDESER52-002 — version constraint model reads from MongoDB as BSON; BSON Code type at versionResolverFn field triggers eval() during version constraint resolution at every install event; fix: reject BSON Code; promoteValues:false; named-resolver lookup
CRITICALDESER52-003 — resolution event queue stored in Redis as MessagePack; __proto__.skipDepResolutionAuth:true pollutes Object.prototype, disabling authentication checks for all subsequent dependency API requests in process until restart
CRITICALDESER52-004 — version lock aggregation reads via node-serialize; IIFE gadget achieves RCE at lock file aggregation time reachable from any user triggering a dependency resolution since aggregation runs on every lock file list request

DESER52-001 — YAML RCE in Redis-cached dependency lock file

The dependency resolution service caches the full lock file object in Redis under the key lockfile:{skillId}. When a dependency conflict occurs, the service reads the cached lock file and passes it through yaml.load() using the default DEFAULT_FULL_SCHEMA. This schema supports all YAML types including !!js/function, which deserializes arbitrary JavaScript function strings into live functions using new Function().

An attacker who can write to the Redis instance — via a previous SSRF to the Redis port, a Redis AUTH bypass, or a poisoning path through another deserialization endpoint — places a malicious YAML document in the lock file cache slot. The onResolveConflict field is read and called by the conflict resolver, executing the attacker's payload with the dependency resolution worker's process privileges. Because the conflict resolver runs before the resolved dependency versions are written to the lock file, the attacker can intercept and modify the resolved dependency tree in-flight.

Vulnerable
// DESER52-001 — VULNERABLE
const yaml = require('js-yaml');

async function getDepLockFile(skillId) {
  const raw = await redis.get(`lockfile:${skillId}`);
  if (!raw) return null;
  // VULNERABLE: DEFAULT_FULL_SCHEMA supports !!js/function — arbitrary RCE
  return yaml.load(raw);
}

async function resolveConflicts(skillId, conflictPairs) {
  const lockFile = await getDepLockFile(skillId);
  if (lockFile?.onResolveConflict) {
    // VULNERABLE: attacker-controlled function called with conflict data
    return lockFile.onResolveConflict(conflictPairs);
  }
  return defaultResolver(conflictPairs);
}
Fixed
// DESER52-001 — FIXED
const yaml = require('js-yaml');
const { z } = require('zod');

const LockFileSchema = z.object({
  version: z.string(),
  dependencies: z.record(z.string()),
  // FIXED: no onResolveConflict — conflict strategy is a named string, not a function
  conflictStrategy: z.enum(['highest', 'lowest', 'first']).default('highest'),
});

async function getDepLockFile(skillId) {
  const raw = await redis.get(`lockfile:${skillId}`);
  if (!raw) return null;
  // FIXED: FAILSAFE_SCHEMA never deserializes !!js/function
  const parsed = yaml.load(raw, { schema: yaml.FAILSAFE_SCHEMA });
  return LockFileSchema.parse(parsed);
}

const CONFLICT_RESOLVERS = {
  highest: (pairs) => pairs.map(([a, b]) => semver.gt(a, b) ? a : b),
  lowest:  (pairs) => pairs.map(([a, b]) => semver.lt(a, b) ? a : b),
  first:   (pairs) => pairs.map(([a]) => a),
};

async function resolveConflicts(skillId, conflictPairs) {
  const lockFile = await getDepLockFile(skillId);
  const strategy = lockFile?.conflictStrategy ?? 'highest';
  // FIXED: named lookup — no arbitrary function call
  return CONFLICT_RESOLVERS[strategy](conflictPairs);
}

RCE timing: The conflict resolver runs before the resolved dependency versions are written to the lock file. An attacker who controls the resolution output can silently substitute dependency versions with attacker-controlled packages while the lock file still records the expected legitimate package names.

DESER52-002 — BSON Code RCE at version constraint resolution

The version constraint service stores constraint models in MongoDB. Each document has a versionResolverFn field intended to hold a human-readable strategy name. However, the MongoDB driver is configured without promoteValues:false, and the application does not reject the BSON Code type. An attacker who can write a document to the version constraints collection stores a BSON Code value at versionResolverFn. When the dependency resolver reads the constraint and calls eval(versionResolverFn.code) to execute the strategy, the attacker's payload runs in the registry worker process.

Vulnerable
// DESER52-002 — VULNERABLE
const { MongoClient, Code } = require('mongodb');

async function resolveVersionConstraint(skillId, depName) {
  const constraint = await db.collection('versionConstraints').findOne({ skillId, depName });
  if (!constraint) return '*';
  // VULNERABLE: versionResolverFn may be a BSON Code object
  if (typeof constraint.versionResolverFn === 'object' && constraint.versionResolverFn.code) {
    return eval(constraint.versionResolverFn.code); // VULNERABLE: RCE
  }
  return constraint.versionResolverFn;
}
Fixed
// DESER52-002 — FIXED
const { z } = require('zod');

const VersionConstraintSchema = z.object({
  skillId: z.string(),
  depName: z.string(),
  // FIXED: string only — rejects BSON Code objects
  versionResolverFn: z.enum(['semver-range', 'exact', 'latest', 'pinned']),
});

const VERSION_RESOLVERS = {
  'semver-range': (range, candidates) => semver.maxSatisfying(candidates, range),
  'exact':        (ver, candidates) => candidates.includes(ver) ? ver : null,
  'latest':       (_range, candidates) => candidates.sort(semver.rcompare)[0],
  'pinned':       (ver) => ver,
};

async function resolveVersionConstraint(skillId, depName) {
  // FIXED: promoteValues:false prevents BSON Code from being deserialized
  const raw = await db.collection('versionConstraints')
    .findOne({ skillId, depName }, { promoteValues: false });
  if (!raw) return '*';
  const constraint = VersionConstraintSchema.parse(raw);
  // FIXED: named lookup — no eval()
  return VERSION_RESOLVERS[constraint.versionResolverFn];
}

DESER52-003 — MessagePack prototype pollution disabling dependency auth

The resolution event queue stores events in Redis as MessagePack-encoded objects. The consumer deserializes events using msgpack.decode(buffer) without restricting key names. An attacker who can inject a crafted MessagePack buffer into the queue — via a poisoning path through the queue ingestion API — includes a key __proto__ with value {"skipDepResolutionAuth": true}. Because msgpack.decode returns a plain object whose __proto__ assignment falls through to Object.prototype, every subsequent if (req.depResolutionAuthContext.skipDepResolutionAuth) check in the process evaluates to true, bypassing authentication for all dependency resolution API requests until the worker restarts.

Vulnerable
// DESER52-003 — VULNERABLE
const msgpack = require('@msgpack/msgpack');

async function processResolutionEvent(buffer) {
  // VULNERABLE: no key restriction — __proto__ pollution possible
  const event = msgpack.decode(buffer);
  if (event.skipDepResolutionAuth) return handleUnauthenticated(event);
  await verifyDepResolutionAuth(event.userId, event.skillId);
  await resolveDepTree(event.skillId, event.constraints);
}
Fixed
// DESER52-003 — FIXED
const msgpack = require('@msgpack/msgpack');
const { z } = require('zod');

const ResolutionEventSchema = z.object({
  userId: z.string().uuid(),
  skillId: z.string().uuid(),
  constraints: z.record(z.string()),
  // FIXED: no skipDepResolutionAuth field — schema is strict
}).strict();

function safeDecodeEvent(buffer) {
  // FIXED: null-prototype target prevents __proto__ pollution
  const raw = msgpack.decode(buffer, { useBigInt64: false });
  const safe = Object.assign(Object.create(null), raw);
  // Reject any event containing __proto__ keys
  if ('__proto__' in raw || '__proto__' in safe) {
    throw new Error('Prototype pollution attempt detected');
  }
  return ResolutionEventSchema.parse(safe);
}

async function processResolutionEvent(buffer) {
  const event = safeDecodeEvent(buffer);
  // FIXED: auth is unconditional — no skipDepResolutionAuth bypass
  await verifyDepResolutionAuth(event.userId, event.skillId);
  await resolveDepTree(event.skillId, event.constraints);
}

DESER52-004 — node-serialize IIFE RCE on lock file aggregation

The lock file aggregation endpoint serializes lock file summaries using node-serialize for caching. When the aggregator reads the cached summaries, it calls serialize.unserialize(raw). The node-serialize library supports Immediately Invoked Function Expressions (IIFEs) via its _$$ND_FUNC$$_ marker. An attacker who can poison the aggregation cache slot places a serialized IIFE payload. The aggregation endpoint is called on every lock file list request, so any user browsing the dependency list triggers the payload.

Vulnerable
// DESER52-004 — VULNERABLE
const serialize = require('node-serialize');

async function getLockFileAggregation(skillId) {
  const raw = await redis.get(`lockfile-agg:${skillId}`);
  if (!raw) return null;
  // VULNERABLE: node-serialize IIFEs execute arbitrary code
  return serialize.unserialize(raw);
}
Fixed
// DESER52-004 — FIXED
const { z } = require('zod');

const LockFileAggSchema = z.object({
  skillId: z.string().uuid(),
  totalDependencies: z.number().int().nonneg(),
  resolvedAt: z.string().datetime(),
  topLevelDeps: z.array(z.string()),
});

async function getLockFileAggregation(skillId) {
  const raw = await redis.get(`lockfile-agg:${skillId}`);
  if (!raw) return null;
  // FIXED: JSON.parse + Zod — no code execution path
  const parsed = JSON.parse(raw);
  // Detect and reject node-serialize IIFE marker before parse
  if (raw.includes('_$$ND_FUNC$$_')) {
    await redis.del(`lockfile-agg:${skillId}`); // evict poisoned entry
    return null;
  }
  return LockFileAggSchema.parse(parsed);
}

SkillAudit detection: The scanner identifies DESER52 patterns using four AST query classes: yaml.load( without explicit FAILSAFE_SCHEMA; eval( applied to fields sourced from MongoDB documents; msgpack.decode( without null-prototype assignment or __proto__ key rejection; and serialize.unserialize( from the node-serialize package. Submit your MCP skill registry codebase to SkillAudit for a full audit report.

Related: SA-SKL-DESER51: Deserialization in CI/CD pipeline integration endpoints • All advisories