Claude MCP skill insecure deserialization — skill search index and autocomplete pipeline endpoints — SA-SKL-DESER49
SA-SKL-DESER49 documents four insecure deserialization vulnerabilities in MCP skill registry search index and autocomplete pipeline endpoints. DESER49-001: search index config reads from Redis as YAML via yaml.load() DEFAULT_FULL_SCHEMA — !!js/function in indexConfig.onDocumentIndexed achieves RCE at every document indexing event triggered by skill publication; DESER49-002: autocomplete model reads from MongoDB as BSON — BSON Code type at rankingFn field triggers eval() during autocomplete suggestion ranking at every search query event; DESER49-003: search event queue stored in Redis as MessagePack — __proto__.skipSearchAuth:true pollutes Object.prototype, disabling authentication checks for all subsequent search API requests in process until restart; DESER49-004: search result aggregation reads via node-serialize — IIFE gadget achieves RCE at search aggregation time reachable from any user performing a search since aggregation runs on every search results page.
yaml.load() DEFAULT_FULL_SCHEMA — !!js/function in indexConfig.onDocumentIndexed achieves RCE at every document indexing event; fix: FAILSAFE_SCHEMA; JSON for all index config; Zod IndexConfigSchema; named-event dispatch tablerankingFn field triggers eval() during autocomplete suggestion ranking at every search query; fix: reject BSON Code; promoteValues:false; Zod string-only schema; named-ranking lookup with allowlist of ranking strategies__proto__.skipSearchAuth:true pollutes Object.prototype, disabling authentication checks for all subsequent search API requests in process until restart; fix: null-prototype target; Zod strict(); JSON instead of MessagePack; reject __proto__ keys explicitly_$$ND_FUNC$$_ payloads; sealed config at deploy timeDESER49-001 — RCE via yaml.load() DEFAULT_FULL_SCHEMA on search index config from Redis
Severity: CRITICAL
The search index configuration is stored in Redis as a YAML string and loaded using yaml.load(raw) with the default schema, which is DEFAULT_FULL_SCHEMA. This schema supports the !!js/function YAML type tag, which causes the YAML parser to construct a JavaScript Function object by calling the Function constructor with the serialized function body. Any party that can write to the index:config:${skillId} Redis key — including through a Redis injection in another pipeline stage, a compromised background job, or an insider threat — can place a !!js/function value at the onDocumentIndexed key and achieve RCE at the moment the indexing pipeline processes the next skill publication event.
The trigger surface is wide: document indexing fires on every skill publish, every skill update, and every metadata change — these are high-frequency events in a live registry. The RCE executes in the Node.js process running the indexing pipeline, which typically has access to internal network services, database credentials in environment variables, and the filesystem containing deployed skill artifacts. An attacker with access to Redis (a common lateral movement target in cloud environments) can place the payload once and receive execution on every subsequent skill indexing event without any further interaction.
// Search index config from Redis deserialized as YAML — !!js/function triggers RCE
const raw = await redisClient.get(`index:config:${skillId}`);
const indexConfig = yaml.load(raw); // DEFAULT_FULL_SCHEMA: !!js/function eval
await indexConfig.onDocumentIndexed(doc); // RCE if attacker controls Redis key
const raw = await redisClient.get(`index:config:${skillId}`);
const indexConfig = IndexConfigSchema.parse(JSON.parse(raw)); // JSON.parse + Zod; no YAML
const handler = INDEX_EVENT_DISPATCH[indexConfig.onDocumentIndexed]; // named dispatch, no eval
if (!handler) throw new Error('Unknown index event handler');
await handler(doc, indexConfig);
The fix replaces YAML deserialization with JSON.parse followed by Zod schema validation. JSON has no mechanism for expressing executable code, eliminating the entire class of function-injection gadgets. The onDocumentIndexed field is treated as a string key into a server-side dispatch table (INDEX_EVENT_DISPATCH) whose values are statically defined handler functions — arbitrary code execution via config is structurally impossible because the config never carries executable code. YAML must not be used for any data read from external stores; it is appropriate only for static, deploy-time configuration files committed to source control.
DESER49-002 — RCE via BSON Code type on autocomplete ranking function from MongoDB
Severity: CRITICAL
The autocomplete model document is retrieved from MongoDB using .lean() and the rankingFn field is called directly as a function. MongoDB's BSON format supports a Code type that stores executable JavaScript. When the driver deserializes a BSON Code value into a JavaScript object via .lean(), the resulting value is a wrapper object that, when called as a function, executes the stored JavaScript code via eval. Any party that can write a BSON Code value to the rankingFn field in the autocomplete models collection achieves RCE at every autocomplete suggestion request — which fires on every keystroke in the skill search interface.
The autocomplete pipeline runs on every character typed into the search box, making this one of the highest-frequency code execution paths in the registry. BSON Code injection is particularly difficult to detect in code review because the MongoDB document appears to store a function value, which looks intentional to developers unfamiliar with the BSON Code type's execution semantics. The fix must reject BSON Code type values at deserialization time, before any field access occurs, to prevent the driver from constructing callable objects from stored code.
// Autocomplete model from MongoDB — BSON Code at rankingFn triggers eval()
const model = await AutocompleteModel.findOne({ skillId }).lean();
const ranked = model.rankingFn(candidates); // eval() if BSON Code type stored at rankingFn
const model = await AutocompleteModel.findOne({ skillId })
.lean({ transform: doc => { if (doc.rankingFn && typeof doc.rankingFn !== 'string') throw new Error('BSON Code rejected'); return doc; } });
const parsed = AutocompleteModelSchema.parse(model); // Zod: rankingFn is z.string() enum
const ranker = RANKING_STRATEGIES[parsed.rankingFn]; // named lookup, no eval
if (!ranker) throw new Error('Unknown ranking strategy');
const ranked = ranker(candidates, parsed.rankingParams);
The fix uses a lean transform to inspect the raw deserialized value of rankingFn before Zod parsing. If the value is not a plain string — indicating that the BSON driver constructed a Code object — an error is thrown immediately, before the value is accessed as a callable. The Zod schema constrains rankingFn to z.string() and the value is used only as a lookup key into the RANKING_STRATEGIES allowlist. The strategies map contains only statically defined functions declared in application source code; no user-supplied or database-sourced code ever executes.
DESER49-003 — Prototype pollution via MessagePack search event queue disables authentication
Severity: CRITICAL
Search events are stored in Redis as MessagePack-encoded buffers and decoded using msgpack.decode(buf). MessagePack, like JSON, can represent objects with arbitrary string keys — including __proto__. When a MessagePack decoder assigns a decoded object's properties to a plain JavaScript object without prototype protection, a key of __proto__ with a value of {"skipSearchAuth": true} causes the assignment to modify Object.prototype.skipSearchAuth. After this modification, every subsequent property lookup of skipSearchAuth on any plain object in the process returns true — including the check if (event.skipSearchAuth) return next() in the authentication middleware, which now skips authentication for all search requests until the Node.js process is restarted.
Prototype pollution via deserialization is particularly severe because it is process-wide and affects all subsequent requests, not just the request that carried the malicious payload. An attacker who controls a single Redis key in the search event queue can disable authentication for the entire search API with a single write. The pollution persists until the process restarts, during which time any unauthenticated request to any search endpoint succeeds regardless of session state.
// Search event queue from Redis as MessagePack — prototype pollution via __proto__
const buf = await redisClient.getBuffer(`search:queue:${eventId}`);
const event = msgpack.decode(buf); // __proto__.skipSearchAuth pollutes Object.prototype
if (event.skipSearchAuth) return next(); // bypassed after pollution
const buf = await redisClient.getBuffer(`search:queue:${eventId}`);
const raw = msgpack.decode(buf, { codec: msgpack.createCodec({ binarraybuffer: true }) });
// Reject prototype pollution keys before Zod parsing
const sanitized = JSON.parse(JSON.stringify(raw, (k, v) => (['__proto__','constructor','prototype'].includes(k) ? undefined : v)));
const event = SearchEventSchema.parse(Object.assign(Object.create(null), sanitized));
The fix uses a JSON round-trip with a replacer function that strips __proto__, constructor, and prototype keys before any property assignment occurs. The sanitized object is then assigned to a null-prototype target via Object.create(null), ensuring that even if a pollution key survived sanitization it would affect only the null-prototype object rather than Object.prototype. The Zod schema with .strict() rejects any keys not explicitly declared, providing a final defence layer. For new implementations, MessagePack should be replaced with JSON — MessagePack offers no semantic advantage over JSON for this use case and introduces additional deserialization attack surface.
DESER49-004 — RCE via node-serialize IIFE gadget in search result aggregation
Severity: CRITICAL
Search result aggregation data is stored in Redis as node-serialize output and loaded using serialize.unserialize(raw). The node-serialize library supports a special key format _$$ND_FUNC$$_ that stores function bodies as strings and executes them via the Function constructor during deserialization. If the stored value is wrapped in an immediately-invoked function expression (IIFE) — _$$ND_FUNC$$_function(){...}() — the code executes at the moment unserialize is called, before the application code accesses any deserialized field.
Search result aggregation runs on every search results page load — this is one of the highest-traffic code paths in the registry, executing for every user who performs a search. Any party that can write to the search:agg:${query} Redis key achieves RCE on every search request for that query string. High-traffic query strings (top skill categories, common skill names) produce the most frequent execution. The node-serialize vulnerability is well-documented and the library is effectively abandoned — it must not be used for any data read from external stores regardless of trust assumptions about the data source.
// Search result aggregation via node-serialize — IIFE gadget = RCE
const raw = await redisClient.get(`search:agg:${query}`);
const agg = serialize.unserialize(raw); // node-serialize: IIFE in _$$ND_FUNC$$_ key triggers exec
const raw = await redisClient.get(`search:agg:${query}`);
if (raw.includes('_$$ND_FUNC$$_')) throw new Error('node-serialize IIFE gadget detected');
const agg = SearchAggregationSchema.parse(JSON.parse(raw));
The fix removes node-serialize entirely and replaces it with JSON.parse followed by Zod schema validation. The explicit check for the _$$ND_FUNC$$_ sentinel string provides defence-in-depth detection of any node-serialize payloads that might have been stored before the migration. The Zod SearchAggregationSchema enforces the exact expected shape of aggregation data, rejecting any fields not present in the schema. All aggregation data written to Redis after deployment must use JSON.stringify — the application should be audited to confirm no other code paths write node-serialize output to the aggregation cache.
Run SkillAudit to detect yaml.load() with DEFAULT_FULL_SCHEMA, BSON Code deserialization paths, MessagePack prototype pollution vectors, and node-serialize usage in your MCP skill registry source code. Join the waitlist for access.