Claude MCP skill insecure deserialization — skill search index and autocomplete query pipeline endpoints (SA-SKL-DESER66)
SA-SKL-DESER66 identifies four insecure deserialization vulnerabilities in MCP skill registry skill search index and autocomplete query pipeline endpoints. YAML deserialization with DEFAULT_FULL_SCHEMA in the search index configuration loading path allows a malicious !!js/function gadget in the onIndexRebuild handler field to achieve remote code execution at every search index rebuild, which is triggered by any skill update submitted by any registry user; MongoDB BSON deserialization without disabling code types in the autocomplete ranking model loading path allows a BSON Code gadget at the rankingFn field to achieve remote code execution via eval() at every autocomplete query keystroke from any user; MessagePack deserialization without key sanitization in the search event queue allows a __proto__.skipSearchAuth:true prototype pollution payload to disable authentication for all subsequent search API requests processed in the same worker; and node-serialize deserialization in the search result aggregation path allows an IIFE gadget to achieve remote code execution at aggregation time, reachable from any user who performs a search query on any skill.
yaml.load() DEFAULT_FULL_SCHEMA — !!js/function in searchConfig.onIndexRebuild achieves RCE at every search index rebuild triggered by any skill updateBSON Code type at rankingFn field triggers eval() during autocomplete query processing at every search keystroke__proto__.skipSearchAuth:true pollutes Object.prototype, disabling authentication for all subsequent search API requests in same workernode-serialize — IIFE gadget achieves RCE at aggregation time reachable from any user performing a search queryDESER66-001 — YAML yaml.load() RCE in search index configuration
The search index worker loads its rebuild configuration from a Redis key serialized as YAML using js-yaml's DEFAULT_FULL_SCHEMA. This schema supports the !!js/function YAML type tag, which js-yaml deserializes by calling new Function() on the tag's string value. An attacker who can write to the Redis key — via a compromised internal service, Redis SSRF, or a misconfigured Redis ACL — plants a !!js/function gadget in the searchConfig.onIndexRebuild field. At every search index rebuild triggered by any skill update event, the worker deserializes this config and immediately executes the attacker's JavaScript in the Node.js process, with access to all environment variables, the filesystem, and the network.
// DESER66-001 — VULNERABLE
const yaml = require('js-yaml');
async function loadSearchConfig() {
const raw = await redis.get('search:config');
// DEFAULT_FULL_SCHEMA supports !!js/function — arbitrary code execution
return yaml.load(raw, { schema: yaml.DEFAULT_FULL_SCHEMA });
}
searchIndexWorker.on('skill.updated', async (event) => {
const config = await loadSearchConfig();
// config.onIndexRebuild may now be attacker-controlled JS function
await config.onIndexRebuild(event.skillId);
});
// DESER66-001 — FIXED: FAILSAFE_SCHEMA; Zod validation; named handler lookup
const yaml = require('js-yaml');
const { z } = require('zod');
const SearchConfigSchema = z.object({
onIndexRebuild: z.enum(['full_rebuild', 'incremental_update', 'delta_patch']),
batchSize: z.number().int().min(1).max(1000),
timeoutMs: z.number().int().min(100).max(30000)
});
const INDEX_REBUILD_HANDLERS = {
full_rebuild: handlers.fullRebuild,
incremental_update: handlers.incrementalUpdate,
delta_patch: handlers.deltaPatch
};
async function loadSearchConfig() {
const raw = await redis.get('search:config');
// FAILSAFE_SCHEMA: only strings, no !!js/function or any type tag
const parsed = yaml.load(raw, { schema: yaml.FAILSAFE_SCHEMA });
return SearchConfigSchema.parse(parsed);
}
searchIndexWorker.on('skill.updated', async (event) => {
const config = await loadSearchConfig();
const handler = INDEX_REBUILD_HANDLERS[config.onIndexRebuild];
await handler(event.skillId);
});
DESER66-002 — BSON Code eval() RCE in autocomplete ranking model
The autocomplete query processor loads its ranking model from a MongoDB document using the MongoDB Node.js driver without disabling BSON code type promotion. When promoteValues is not set to false (or when it defaults to true in legacy driver versions), the driver deserializes BSON Code objects — fields stored with the $code BSON type — by calling eval() on the code string in the current JavaScript context. An attacker who can write to the ranking model MongoDB document plants a BSON Code gadget at the rankingFn field. At every autocomplete query keystroke from any user, the autocomplete processor loads the ranking model, triggering eval() and executing the attacker's JavaScript in the Node.js process.
// DESER66-002 — VULNERABLE
async function loadRankingModel() {
// promoteValues defaults to true — BSON Code fields become eval()'d functions
const doc = await db.collection('autocomplete_models').findOne({ active: true });
return doc; // doc.rankingFn may be a live function from eval()
}
async function processAutocomplete(query) {
const model = await loadRankingModel();
const candidates = await searchIndex.query(query);
// model.rankingFn may now be attacker-controlled eval'd code
return candidates.sort((a, b) => model.rankingFn(a, b, query));
}
// DESER66-002 — FIXED: promoteValues:false; projection excludes rankingFn; named strategy
const RANKING_STRATEGIES = {
bm25_title_boost: ranking.bm25TitleBoost,
semantic_cosine: ranking.semanticCosine,
install_count_decay: ranking.installCountDecay
};
const AutocompleteModelSchema = z.object({
rankingStrategy: z.enum(['bm25_title_boost', 'semantic_cosine', 'install_count_decay']),
maxResults: z.number().int().min(1).max(20),
minScore: z.number().min(0).max(1)
});
async function loadRankingModel() {
const doc = await db.collection('autocomplete_models').findOne(
{ active: true },
// projection excludes rankingFn; promoteValues:false prevents BSON Code eval
{ projection: { rankingFn: 0 }, promoteValues: false }
);
return AutocompleteModelSchema.parse(doc);
}
async function processAutocomplete(query) {
const model = await loadRankingModel();
const candidates = await searchIndex.query(query);
const ranker = RANKING_STRATEGIES[model.rankingStrategy];
return candidates.sort((a, b) => ranker(a, b, query)).slice(0, model.maxResults);
}
DESER66-003 — MessagePack prototype pollution disables search API authentication
The search event queue stores events in Redis serialized as MessagePack. The queue consumer deserializes each event using @msgpack/msgpack without filtering object keys. An attacker who can enqueue a crafted MessagePack payload containing a map entry with the key __proto__ and the value {skipSearchAuth: true} causes the deserializer to write skipSearchAuth onto Object.prototype. Because the search API's authentication middleware checks req.skipSearchAuth as a property lookup on a plain object derived from Object.prototype, every subsequent search API request in the same worker process passes the authentication check without a valid session, allowing unauthenticated access to any search endpoint until the worker restarts.
// DESER66-003 — VULNERABLE
const { decode } = require('@msgpack/msgpack');
searchEventQueue.consume(async (rawMessage) => {
// No key sanitization — __proto__ key pollutes Object.prototype
const event = decode(rawMessage);
await searchIndexWorker.process(event);
});
// auth middleware checks property that now exists on Object.prototype
function requireSearchAuth(req, res, next) {
if (req.skipSearchAuth || req.session?.authenticated) return next();
res.status(401).json({ error: 'Unauthorized' });
}
// DESER66-003 — FIXED: sanitizeDeserialized() rejects __proto__/constructor/prototype keys
const { decode } = require('@msgpack/msgpack');
function sanitizeDeserialized(obj) {
if (typeof obj !== 'object' || obj === null) return obj;
const forbidden = new Set(['__proto__', 'constructor', 'prototype']);
for (const key of Object.keys(obj)) {
if (forbidden.has(key)) throw new Error(`Forbidden key in deserialized payload: ${key}`);
sanitizeDeserialized(obj[key]);
}
return obj;
}
searchEventQueue.consume(async (rawMessage) => {
const raw = decode(rawMessage);
const event = sanitizeDeserialized(raw);
await searchIndexWorker.process(event);
});
// auth middleware uses Object.prototype.hasOwnProperty.call — not affected by pollution
function requireSearchAuth(req, res, next) {
const hasOverride = Object.prototype.hasOwnProperty.call(req, 'skipSearchAuth');
if (hasOverride && req.skipSearchAuth) return res.status(401).json({ error: 'Unauthorized' });
if (req.session?.authenticated) return next();
res.status(401).json({ error: 'Unauthorized' });
}
DESER66-004 — node-serialize IIFE gadget in search result aggregation
The search result aggregation pipeline reads aggregated result objects from a cache layer serialized with node-serialize. This library supports a special _$$ND_FUNC$$_ property pattern where function strings are deserialized by calling eval() on the function body. An attacker who can write to the aggregation cache — via SSRF, a compromised sidecar, or cache poisoning — stores a payload containing an IIFE (Immediately Invoked Function Expression) gadget in the aggregation result object. At aggregation time, any user who performs a search query triggers the aggregation pipeline, which deserializes the cache entry and immediately executes the attacker's JavaScript in the Node.js process.
// DESER66-004 — VULNERABLE
const serialize = require('node-serialize');
async function getAggregatedResults(query) {
const cacheKey = `agg:${query}`;
const cached = await cache.get(cacheKey);
if (cached) {
// node-serialize eval()s _$$ND_FUNC$$_ properties — arbitrary code execution
return serialize.unserialize(cached);
}
const results = await searchIndex.aggregate(query);
await cache.set(cacheKey, serialize.serialize(results), { ttl: 300 });
return results;
}
// DESER66-004 — FIXED: JSON.parse + Zod schema; detect and evict ND_FUNC payloads
const { z } = require('zod');
const SearchResultSchema = z.object({
skillId: z.string().uuid(),
title: z.string().max(200),
score: z.number().min(0).max(1),
installCount: z.number().int().min(0),
lastUpdated: z.string().datetime()
});
const AggregatedResultsSchema = z.array(SearchResultSchema).max(100);
const ND_FUNC_PATTERN = /_\$\$ND_FUNC\$\$_/;
async function getAggregatedResults(query) {
const cacheKey = `agg:${query}`;
const cached = await cache.get(cacheKey);
if (cached) {
if (ND_FUNC_PATTERN.test(cached)) {
await cache.del(cacheKey); // evict poisoned entry
logger.warn({ cacheKey }, 'Evicted node-serialize gadget from aggregation cache');
} else {
try {
return AggregatedResultsSchema.parse(JSON.parse(cached));
} catch { await cache.del(cacheKey); }
}
}
const results = await searchIndex.aggregate(query);
const validated = AggregatedResultsSchema.parse(results);
await cache.set(cacheKey, JSON.stringify(validated), { ttl: 300 });
return validated;
}
SkillAudit scans for all SA-SKL-DESER66 patterns — yaml.load() with permissive schemas in search config paths, BSON Code eval() in ranking model loaders, MessagePack deserialization without prototype pollution protection, and node-serialize usage in aggregation caches. Get a free audit to see the full deserialization analysis for your skill.