Claude MCP skill insecure deserialization — skill search indexing and query caching endpoints — SA-SKL-DESER28
SA-SKL-DESER28 documents four insecure deserialization vulnerabilities in MCP skill registry search indexing and query caching infrastructure. Search and caching layers are high-throughput, low-latency paths that prioritize performance — a tradeoff that frequently leads to unsafe serialization choices. YAML full-schema deserialization of Redis-cached query plans enables remote code execution at result transformation time. BSON Code type deserialization in MongoDB search index metadata triggers eval() during result ranking. MessagePack prototype pollution via cached query results bypasses global authentication checks for the life of the Node.js process. And node-serialize deserialization in search suggestion aggregation provides a classic IIFE RCE gadget reachable from any authenticated search query.
yaml.load(queryPlan, DEFAULT_FULL_SCHEMA) on Redis-cached query plan; !!js/function in onResultTransform achieves RCE at query result transformation timeBSON.Code type at rankingFn field triggers eval() during result ranking computation__proto__.skipAuth:true pollutes Object.prototype, bypassing auth check for all subsequent search results in the processnode-serialize deserialization of search suggestion aggregation summary; IIFE gadget achieves RCE at suggestion aggregation time reachable from any authenticated search queryDESER28-001 — YAML full-schema RCE via Redis query plan cache
The search query caching layer stores query execution plans in Redis to avoid recompiling frequently-used search configurations. When reading a cached plan back, the code uses yaml.load(cachedPlan, { schema: yaml.DEFAULT_FULL_SCHEMA }). The js-yaml DEFAULT_FULL_SCHEMA activates the !!js/function and !!js/regexp type tags, which construct live JavaScript functions from serialized source strings during deserialization.
An attacker who can write a crafted entry to the Redis cache — via a Redis AUTH bypass, a misconfigured Redis binding on 0.0.0.0 without TLS, or through a separate SSRF vulnerability that reaches the Redis port — plants a payload in the queryPlan.onResultTransform field. When the next search request reads that cache entry, yaml.load() constructs and executes the attacker's function during result transformation. Because onResultTransform runs in the search result pipeline, the RCE executes with the full privileges of the Node.js worker process — including access to the Anthropic API key used for LLM-assisted prompt-injection audit analysis.
DESER28-001 fix: Replace DEFAULT_FULL_SCHEMA with FAILSAFE_SCHEMA or switch cache serialization entirely to JSON. Validate deserialized query plans against a Zod QueryPlanSchema before use. For callable fields like onResultTransform, use a named-function lookup table keyed on a string identifier — never deserialize function source.
async function getQueryPlan(queryHash) {
const cached = await redis.get(`qp:${queryHash}`);
if (!cached) return null;
// DEFAULT_FULL_SCHEMA enables !!js/function — RCE gadget
return yaml.load(cached, { schema: yaml.DEFAULT_FULL_SCHEMA });
}
const TRANSFORM_FNS = {
'default': defaultTransform,
'highlight': highlightTransform,
'score-boost': scoreBoostTransform,
};
async function getQueryPlan(queryHash) {
const cached = await redis.get(`qp:${queryHash}`);
if (!cached) return null;
// JSON only — no executable type tags
const raw = JSON.parse(cached);
const plan = QueryPlanSchema.parse(raw); // Zod: string fields only
// resolve callable by name, not by deserializing function source
plan.onResultTransform = TRANSFORM_FNS[plan.transformName] ?? TRANSFORM_FNS['default'];
return plan;
}
DESER28-002 — BSON Code eval in MongoDB search index metadata
The search indexing pipeline stores ranking function configuration in a MongoDB collection alongside index metadata. When reading index metadata, the driver uses default BSON deserialization options. MongoDB's BSON Code type represents JavaScript source that the MongoDB server can execute server-side in map-reduce operations. When the Node.js BSON library deserializes a document containing a Code field, it creates a BSON.Code object. If the application subsequently calls .valueOf(), eval(), or passes the Code object to a function that calls it, remote code execution results.
In this case, the rankingFn field on the index metadata document is passed to a ranking computation function that calls fn(result) for each search result. When the BSON Code object is passed and the ranking computation calls it, Node.js executes the attacker-supplied source. An attacker who can write to the search index metadata collection — through a MongoDB authentication misconfiguration or through a separate injection vulnerability — plants the payload in the rankingFn field, achieving RCE on every search result computation.
DESER28-002 fix: Pass { promoteValues: false } to BSON deserialize to prevent automatic value promotion. Add an explicit check that rejects any field containing a BSON.Code instance before use. Validate index metadata against a Zod schema that accepts only string and number fields. Use a named-ranker lookup table — never store or execute function source from the database.
// WRONG — BSON Code deserialized and called as function
const indexMeta = await db.collection('search_indexes').findOne({ id: indexId });
const ranked = results.map(r => indexMeta.rankingFn(r)); // RCE if rankingFn is BSON.Code
// RIGHT — promoteValues:false + Code rejection + named ranker lookup
const RANKERS = { 'bm25': bm25Rank, 'tfidf': tfidfRank, 'semantic': semanticRank };
const rawMeta = await db.collection('search_indexes').findOne(
{ id: indexId },
{ promoteValues: false }
);
// reject any BSON Code types in the document
if (containsBsonCode(rawMeta)) throw new Error('invalid index metadata');
const meta = IndexMetaSchema.parse(rawMeta); // Zod: strings/numbers only
const ranker = RANKERS[meta.rankerName] ?? RANKERS['bm25'];
const ranked = results.map(r => ranker(r, meta.rankerParams));
DESER28-003 — MessagePack prototype pollution bypasses global auth check
The query result cache stores serialized search results in Redis using the msgpack library for compact encoding. When a cached result is read back, the code calls msgpack.decode(buffer) into a plain JavaScript object. If the cached payload was written by an attacker or corrupted in transit, it can contain a MessagePack map with the string key __proto__. When the MessagePack decoder writes this key to the target object, it assigns properties to Object.prototype — affecting every object in the Node.js process for the remainder of its lifetime.
The critical gadget in this registry codebase is an authentication middleware that checks if (req.session.skipAuth) before the ownership verification. If an attacker plants {"__proto__": {"skipAuth": true}} in the MessagePack cache payload, the prototype pollution sets Object.prototype.skipAuth = true. Every subsequent request to any endpoint that reads req.session.skipAuth will return true, bypassing ownership checks and granting unauthenticated access to all search results, including private skill audit data, until the Node.js process restarts.
DESER28-003 fix: Replace MessagePack with JSON for all cache serialization. If MessagePack is required for performance, decode into a null-prototype target (Object.create(null)) and validate with Zod.strict() before use. Explicitly block __proto__, constructor, and prototype keys during deserialization. Remove skipAuth pattern from authentication middleware — auth decisions must come from explicit session state, not property presence.
// WRONG — msgpack decode into plain object; __proto__ pollutes Object.prototype
const cached = await redis.getBuffer(`sr:${queryHash}`);
const results = msgpack.decode(cached); // prototype pollution if __proto__ in payload
// RIGHT — JSON + null-prototype target + Zod strict
const cached = await redis.get(`sr:${queryHash}`);
const raw = JSON.parse(cached);
// null-prototype prevents __proto__ pollution
const safe = Object.assign(Object.create(null), raw);
const results = SearchResultsSchema.strict().parse(safe);
DESER28-004 — node-serialize IIFE RCE in search suggestion aggregation
The search suggestion aggregation pipeline caches intermediate aggregation summaries using node-serialize. The node-serialize library supports an immediately invoked function expression (IIFE) gadget: if a serialized string field begins with _$$ND_FUNC$$_ followed by a function expression wrapped in parentheses and immediately invoked with (), the library evaluates the function during deserialization. This is a well-documented CVE (CVE-2017-5941) that has been exploited in the wild.
The search suggestion endpoint is reachable from any authenticated user — it fires on every keystroke in the search box. An attacker who can write to the suggestion aggregation cache (via Redis access or a separate injection) plants a node-serialize payload in the aggregation summary. The next authenticated user who triggers the autocomplete endpoint causes the Node.js process to execute the attacker's code with full server privileges. Because search suggestions are computed frequently and cached aggressively, the payload executes repeatedly across multiple worker processes until the cache TTL expires.
DESER28-004 fix: Remove node-serialize entirely — replace with JSON.parse() and Zod validation. Add an explicit detector that rejects any string containing _$$ND_FUNC$$_ before deserialization. Seal aggregation configuration at deploy time using Object.freeze() so that cached summaries cannot override server-side aggregation parameters.
// WRONG — node-serialize IIFE gadget; any _$$ND_FUNC$$_ payload achieves RCE
const cached = await redis.get(`sugg:${prefix}`);
const summary = serialize.unserialize(cached); // RCE if _$$ND_FUNC$$_ in payload
// RIGHT — JSON.parse + Zod + _$$ND_FUNC$$_ detector + frozen config
async function getSuggestionSummary(prefix) {
const cached = await redis.get(`sugg:${prefix}`);
if (!cached) return null;
if (cached.includes('_$$ND_FUNC$$_')) {
await redis.del(`sugg:${prefix}`); // evict poisoned cache entry
logger.warn('node-serialize gadget detected and evicted', { prefix });
return null;
}
const raw = JSON.parse(cached);
return SuggestionSummarySchema.parse(raw); // Zod strict schema
}
SkillAudit scans for unsafe deserialization in search and caching infrastructure: yaml.load() with full schema on cached data, BSON Code type usage in MongoDB queries, MessagePack decode targets susceptible to prototype pollution, and node-serialize usage anywhere in the codebase.
Scan your registry| Finding | Severity | Vector | Impact |
|---|---|---|---|
| DESER28-001 | CRITICAL | Redis query plan cache via YAML full schema | RCE at result transformation time; access to Anthropic API key and all audit data |
| DESER28-002 | CRITICAL | MongoDB BSON Code type in search index metadata | RCE during result ranking computation; full worker process compromise |
| DESER28-003 | CRITICAL | MessagePack __proto__ pollution in Redis result cache | Global auth bypass for all search endpoints for life of Node.js process |
| DESER28-004 | CRITICAL | node-serialize IIFE gadget in suggestion aggregation cache | RCE reachable from any authenticated search query; executes repeatedly across worker processes |
See also: SA-SKL-DESER27 (release automation and publish queue deserialization patterns) for related deserialization vulnerabilities in the skill publishing pipeline.