← Blog

Claude MCP skill insecure deserialization — search index and autocomplete cache endpoints (SA-SKL-DESER64)

SA-SKL-DESER64 identifies four insecure deserialization vulnerabilities in MCP skill registry skill search index and autocomplete cache endpoints. The search index configuration is stored in Redis and deserialized via yaml.load() with DEFAULT_FULL_SCHEMA, which permits arbitrary JavaScript function payloads; an attacker who can write to Redis inserts a !!js/function gadget in indexConfig.onDocumentIndexed that achieves remote code execution at every subsequent skill submission event as the indexer calls the callback during document processing. The autocomplete model is persisted in MongoDB as a BSON document; the rankingFn field accepts a BSON Code type, which MongoDB's driver evaluates via eval() during autocomplete suggestion generation, triggering unauthenticated RCE on every search query. The search suggestion queue is serialized to Redis using MessagePack; an attacker who can write a crafted MessagePack payload with a __proto__ key sets skipSearchAuth:true on Object.prototype, permanently disabling the authentication gate for all subsequent search API requests in the affected worker process until it restarts. The search result aggregation pipeline reads job payloads from a queue using node-serialize; the classic IIFE gadget in the serialized payload achieves RCE during aggregation, reachable by any user who can initiate a search query that reaches the aggregation worker.

SA-SKL-DESER64 findings at a glance
CRITICALDESER64-001 — search index config reads from Redis as YAML via yaml.load() DEFAULT_FULL_SCHEMA — !!js/function in indexConfig.onDocumentIndexed achieves RCE at every new skill submission
CRITICALDESER64-002 — autocomplete model reads from MongoDB as BSON — BSON Code type at rankingFn field triggers eval() during autocomplete suggestion generation at every search query
CRITICALDESER64-003 — search suggestion queue stored in Redis as MessagePack — __proto__.skipSearchAuth:true pollutes Object.prototype, disabling authentication for all subsequent search API requests in same worker
CRITICALDESER64-004 — search result aggregation reads via node-serialize — IIFE gadget achieves RCE at aggregation time reachable from any user performing a search query

DESER64-001 — yaml.load() RCE in search index config triggered at every skill submission

The search indexer reads its configuration document from a Redis key using yaml.load() with js-yaml's DEFAULT_FULL_SCHEMA rather than the safe FAILSAFE_SCHEMA or JSON_SCHEMA. DEFAULT_FULL_SCHEMA includes the !!js/function and !!js/undefined YAML types, which cause the YAML parser to call new Function(src)() during deserialization. An attacker who gains write access to the Redis instance inserts a malicious onDocumentIndexed callback in the index config using a !!js/function YAML tag. Every subsequent skill submission that triggers the indexer invokes this callback, executing the attacker's code on the indexer worker with the same process credentials used by the search service, which typically includes database write access and cloud storage credentials.

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

async function loadSearchIndexConfig() {
  const raw = await redis.get('search:index:config');
  // DEFAULT_FULL_SCHEMA permits !!js/function — attacker payload executes here
  return yaml.load(raw, { schema: yaml.DEFAULT_FULL_SCHEMA });
}

async function onSkillSubmitted(skillDoc) {
  const config = await loadSearchIndexConfig();
  await searchIndex.add(skillDoc);
  if (config.onDocumentIndexed) {
    config.onDocumentIndexed(skillDoc);  // RCE if attacker controls config
  }
}
Fixed
// DESER64-001 — FIXED: JSON.parse + Zod schema; never yaml.load from Redis
const { z } = require('zod');

const IndexConfigSchema = z.object({
  maxDocumentSize: z.number().int().positive().max(10_000),
  rankingWeights: z.record(z.number()),
  stopWords: z.array(z.string()).max(500)
});

async function loadSearchIndexConfig() {
  const raw = await redis.get('search:index:config');
  const parsed = JSON.parse(raw);  // no arbitrary type deserialization
  return IndexConfigSchema.parse(parsed);  // throws on unknown fields
}

async function onSkillSubmitted(skillDoc) {
  const config = await loadSearchIndexConfig();
  await searchIndex.add(skillDoc, {
    maxDocumentSize: config.maxDocumentSize,
    rankingWeights: config.rankingWeights
  });
  // no caller-supplied callback — static handler dispatch only
}

DESER64-002 — BSON Code eval() RCE in autocomplete ranking model

The autocomplete engine loads its ranking model from MongoDB. The document stored in the autocomplete_models collection includes a rankingFn field that the original developer intended as a human-readable description of the ranking logic. However, the field was stored as a BSON Code type rather than a plain string. When the MongoDB Node.js driver deserializes a BSON Code value and the application calls toString() on the resulting object in a context where JavaScript evaluates it, the driver may invoke eval() on the code string. An attacker who can write to the autocomplete_models collection replaces the rankingFn field with a BSON Code payload containing malicious JavaScript. Every subsequent autocomplete suggestion request that loads the model triggers RCE on the autocomplete worker.

Vulnerable
// DESER64-002 — VULNERABLE
async function loadAutocompleteModel(modelId) {
  const model = await db.collection('autocomplete_models').findOne({ _id: modelId });
  // model.rankingFn is BSON Code — eval() triggered when coerced to string in ranking context
  return model;
}

function rankSuggestions(suggestions, model) {
  // If model.rankingFn is BSON Code, this coercion triggers eval()
  const rankingLogic = model.rankingFn.toString();
  return suggestions.sort((a, b) => eval(rankingLogic)(a, b));  // RCE
}
Fixed
// DESER64-002 — FIXED: Zod schema rejects BSON Code; static ranking dispatch
const { z } = require('zod');

const AutocompleteModelSchema = z.object({
  _id: z.string(),
  rankingStrategy: z.enum(['frequency', 'recency', 'combined']),
  weights: z.object({ frequency: z.number(), recency: z.number() })
});

async function loadAutocompleteModel(modelId) {
  const raw = await db.collection('autocomplete_models').findOne(
    { _id: modelId },
    { projection: { rankingStrategy: 1, weights: 1 } }  // never fetch rankingFn
  );
  return AutocompleteModelSchema.parse(raw);
}

const RANKING_STRATEGIES = {
  frequency: (a, b) => b.frequency - a.frequency,
  recency: (a, b) => new Date(b.updatedAt) - new Date(a.updatedAt),
  combined: (a, b) => (b.frequency * 0.6 + b.recencyScore * 0.4) - (a.frequency * 0.6 + a.recencyScore * 0.4)
};

function rankSuggestions(suggestions, model) {
  const comparator = RANKING_STRATEGIES[model.rankingStrategy];
  return suggestions.sort(comparator);  // no eval, no dynamic dispatch
}

DESER64-003 — MessagePack prototype pollution disables search authentication

The search suggestion queue stores job payloads in Redis serialized as MessagePack using the msgpack library. MessagePack's map type maps keys to arbitrary values, and some MessagePack implementations do not sanitize keys that match JavaScript prototype chain properties such as __proto__, constructor, or prototype. An attacker who can write to the Redis queue inserts a MessagePack payload with a top-level key of __proto__ containing {"skipSearchAuth": true}. When the worker deserializes this payload using msgpack.decode(), the assignment of the __proto__ key pollutes Object.prototype, setting skipSearchAuth to true on every plain object in the worker process. Any subsequent search authentication check that reads context.skipSearchAuth returns true even when the context object was created fresh, bypassing authentication for all search requests until the worker process restarts.

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

async function processSuggestionJob(rawPayload) {
  // Attacker inserts __proto__: {skipSearchAuth: true} in MessagePack
  const job = msgpack.decode(rawPayload);  // pollutes Object.prototype

  // Subsequent objects inherit skipSearchAuth:true from Object.prototype
  const authContext = {};
  if (authContext.skipSearchAuth) {  // true due to pollution — auth bypassed
    return await generateSuggestions(job.query);
  }
  await validateSearchSession(job.sessionId);
  return await generateSuggestions(job.query);
}
Fixed
// DESER64-003 — FIXED: JSON.parse with explicit schema; freeze Object.prototype in worker init
const { z } = require('zod');

// Worker startup — freeze prototype to block future pollution
Object.freeze(Object.prototype);

const SuggestionJobSchema = z.object({
  jobId: z.string().uuid(),
  query: z.string().max(200),
  sessionId: z.string().uuid(),
  maxSuggestions: z.number().int().positive().max(20)
});

async function processSuggestionJob(rawPayload) {
  // JSON.parse into null-prototype object to avoid prototype chain entirely
  const rawObj = JSON.parse(rawPayload.toString('utf8'));
  const job = SuggestionJobSchema.parse(rawObj);  // throws on __proto__ key

  await validateSearchSession(job.sessionId);
  return await generateSuggestions(job.query, job.maxSuggestions);
}

DESER64-004 — node-serialize IIFE RCE in search result aggregation

The search result aggregation pipeline reads job descriptors from a Redis queue where payloads were serialized using the node-serialize library. The node-serialize library's deserialization path evaluates JavaScript function expressions embedded in the serialized string using a regex match against function-shaped values. The classic attack is an immediately-invoked function expression (IIFE) wrapped in the serialized format: {"x":"_$$ND_FUNC$$_function(){require('child_process').exec('...')}()"}. When the aggregation worker calls serialize.unserialize(payload), the IIFE executes immediately during deserialization. Any user who can influence the content of aggregation job payloads — for example, by crafting a search query whose structured filter arguments are incorporated into the job descriptor — can trigger RCE on the aggregation worker.

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

async function processAggregationJob(rawPayload) {
  // node-serialize evaluates $$ND_FUNC$$ gadgets — IIFE achieves RCE
  const job = serialize.unserialize(rawPayload.toString());
  const results = await aggregateSearchResults(job.queryId, job.filters);
  return results;
}
Fixed
// DESER64-004 — FIXED: JSON.parse + Zod schema; remove node-serialize entirely
const { z } = require('zod');

const AggregationJobSchema = z.object({
  jobId: z.string().uuid(),
  queryId: z.string().uuid(),
  filters: z.object({
    category: z.array(z.string()).max(10).optional(),
    minRating: z.number().min(0).max(5).optional(),
    maxAge: z.number().int().positive().optional()
  }),
  requestedAt: z.string().datetime()
});

async function processAggregationJob(rawPayload) {
  const parsed = JSON.parse(rawPayload.toString('utf8'));
  const job = AggregationJobSchema.parse(parsed);  // throws on unknown fields
  const results = await aggregateSearchResults(job.queryId, job.filters);
  return results;
}

SkillAudit detects all SA-SKL-DESER64 patterns via static AST analysis. Run a free audit on your MCP skill or Claude plugin and get a graded report with fix guidance in under 60 seconds.