Claude MCP skill insecure deserialization — skill SDK and client library generation endpoints — SA-SKL-DESER48
SA-SKL-DESER48 documents four insecure deserialization vulnerabilities in MCP skill registry SDK and client library generation endpoints. SDK generation pipelines read configuration from Redis, MongoDB, and in-process queues to orchestrate how client libraries are templated, rendered, and distributed to developers. When these deserialization paths use unsafe formats — YAML with DEFAULT_FULL_SCHEMA, raw BSON with Code type promotion, MessagePack without prototype sanitization, or node-serialize — attacker-controlled data stored in the backing stores triggers remote code execution at the registry server level, prototype pollution that disables API authentication globally, or arbitrary code execution at aggregation time accessible to any authenticated API consumer.
yaml.load() DEFAULT_FULL_SCHEMA — !!js/function in sdkConfig.onGenerationComplete achieves RCE at every SDK generation event triggered by skill SDK build; can intercept SDK builds, inject backdoor code into generated client libraries, or exfiltrate full SDK config database; fix: FAILSAFE_SCHEMA; JSON for all SDK config; Zod SdkConfigSchema; named-event dispatch tabletemplateRenderFn field triggers eval() during client library rendering at every SDK generation completion event; achievable via MongoDB injection in upstream template endpoint; fix: reject BSON Code; promoteValues:false; Zod string-only schema; named-render lookup__proto__.skipSdkAuth:true pollutes Object.prototype, disabling authentication checks for all subsequent SDK API requests in process until restart; impact extends beyond SDK API to any component checking same property name; fix: null-prototype target; Zod strict(); JSON instead of MessagePack_$$ND_FUNC$$_ payloads; sealed config at deploy timeDESER48-001 — YAML RCE on SDK generation config from Redis
Severity: CRITICAL
The SDK generation pipeline reads its configuration from Redis using yaml.load() with the default schema (DEFAULT_FULL_SCHEMA). The js-yaml DEFAULT_FULL_SCHEMA supports the !!js/function YAML type tag, which reconstructs JavaScript functions from their serialized source string. When the registry reads SDK config from Redis and encounters a sdkConfig.onGenerationComplete key containing a !!js/function value, the function is deserialized and later invoked as the SDK generation completion callback.
An attacker with write access to Redis — achievable via a Redis AUTH bypass, an SSRF vulnerability pointed at the Redis port, or a compromised registry worker process — can store a crafted YAML value under any SDK config key. The injected function executes in the context of the registry server process with full filesystem and network access. The impact extends beyond the immediate RCE: the attacker can modify the SDK template used to generate all future client libraries, injecting backdoor code that ships to every developer who installs an SDK generated after the compromise.
// SDK generation pipeline — config read from Redis with unsafe yaml.load()
const yaml = require('js-yaml');
const redis = require('redis').createClient();
async function loadSdkConfig(skillId) {
const raw = await redis.get(`sdk:config:${skillId}`);
return yaml.load(raw); // DEFAULT_FULL_SCHEMA: !!js/function in onGenerationComplete triggers RCE
}
async function runSdkGeneration(skillId) {
const config = await loadSdkConfig(skillId);
const sdk = await generateSdk(skillId, config);
if (config.onGenerationComplete) {
await config.onGenerationComplete(sdk); // attacker function executes here
}
return sdk;
}
// SDK generation pipeline — FAILSAFE_SCHEMA + Zod schema + named-event dispatch
const yaml = require('js-yaml');
const { z } = require('zod');
const redis = require('redis').createClient();
const SdkConfigSchema = z.object({
language: z.enum(['typescript', 'python', 'go', 'java', 'rust']),
outputFormat: z.enum(['esm', 'cjs', 'umd']),
includeTypes: z.boolean(),
onGenerationComplete: z.enum(['notify_webhook', 'update_registry', 'none']),
});
const SDK_COMPLETION_HANDLERS = {
notify_webhook: (sdk) => notifyWebhook(sdk),
update_registry: (sdk) => updateRegistryEntry(sdk),
none: () => Promise.resolve(),
};
async function loadSdkConfig(skillId) {
const raw = await redis.get(`sdk:config:${skillId}`);
const parsed = yaml.load(raw, { schema: yaml.FAILSAFE_SCHEMA }); // no !!js/function
return SdkConfigSchema.parse(parsed);
}
async function runSdkGeneration(skillId) {
const config = await loadSdkConfig(skillId);
const sdk = await generateSdk(skillId, config);
await SDK_COMPLETION_HANDLERS[config.onGenerationComplete](sdk);
return sdk;
}
DESER48-002 — BSON Code eval() on client library template from MongoDB
Severity: CRITICAL
The client library template model is retrieved from MongoDB using the default BSON deserialization settings. The MongoDB Node.js driver's default behavior promotes BSON Code objects — which represent JavaScript code stored in the database — to JavaScript functions by calling new Function() or eval() on their source string. When a template document contains a templateRenderFn field stored as a BSON Code type, the driver promotes it to an executable function that is invoked during client library rendering.
An attacker who can inject a BSON Code document into the templates collection — via a MongoDB injection vulnerability in the template creation endpoint, a compromised registry admin account, or direct database access — achieves code execution at every SDK generation event that uses that template. The trigger point is the standard client library rendering path called for every developer who requests an SDK, meaning the attack surface is proportional to SDK adoption rate.
// Client library template retrieval — BSON Code promoted to eval()
const { MongoClient } = require('mongodb');
const client = new MongoClient(process.env.MONGODB_URI); // default: promoteLongs:true, promoteValues:true
async function renderClientLibrary(skillId, language) {
const template = await client.db().collection('sdk_templates')
.findOne({ skillId, language });
// template.templateRenderFn is BSON Code → promoted to Function → executed
return template.templateRenderFn(template.context);
}
// Client library template retrieval — reject BSON Code + named-render lookup
const { MongoClient, BSON } = require('mongodb');
const { z } = require('zod');
const TemplateSchema = z.object({
skillId: z.string(),
language: z.enum(['typescript', 'python', 'go', 'java', 'rust']),
templateName: z.string().regex(/^[a-zA-Z0-9_-]{1,64}$/),
renderStrategy: z.enum(['mustache', 'handlebars', 'nunjucks']),
});
const RENDER_STRATEGIES = {
mustache: (tpl, ctx) => mustache.render(tpl, ctx),
handlebars: (tpl, ctx) => handlebars.compile(tpl)(ctx),
nunjucks: (tpl, ctx) => nunjucks.renderString(tpl, ctx),
};
const clientSafe = new MongoClient(process.env.MONGODB_URI, {
promoteValues: false, // BSON Code stays as BSON.Code object, never eval'd
promoteLongs: false,
});
async function renderClientLibrary(skillId, language) {
const raw = await clientSafe.db().collection('sdk_templates').findOne({ skillId, language });
if (raw?.templateRenderFn instanceof BSON.Code) throw new Error('BSON Code type rejected');
const doc = TemplateSchema.parse(raw);
const templateSource = await loadTemplateSafe(doc.templateName);
return RENDER_STRATEGIES[doc.renderStrategy](templateSource, doc.context);
}
DESER48-003 — MessagePack prototype pollution disables SDK API authentication
Severity: CRITICAL
The SDK build event queue is stored in Redis serialized as MessagePack. When the registry worker deserializes queue messages using a standard MessagePack library without prototype sanitization, an attacker can craft a payload that sets __proto__.skipSdkAuth to true. This pollutes Object.prototype, causing the property to appear on every plain object in the Node.js process for the remainder of its lifecycle.
Authentication middleware that checks if (req.context.skipSdkAuth) or any similar pattern will evaluate to true for all subsequent requests — including requests from unauthenticated callers. The impact is not limited to the SDK API: any middleware in the same Node.js process that checks a property with the same name on any plain object will be bypassed. The process must be restarted to clear the polluted prototype, and the attack can be re-triggered every time the event queue is processed.
// SDK build event queue deserialization — MessagePack without prototype sanitization
const msgpack = require('msgpack5')();
const redis = require('redis').createClient();
async function processSdkBuildQueue() {
const raw = await redis.lpop('sdk:build:queue');
if (!raw) return;
const event = msgpack.decode(Buffer.from(raw, 'base64'));
// attacker payload: {"__proto__":{"skipSdkAuth":true}} pollutes Object.prototype
await handleSdkBuildEvent(event);
}
// SDK build event queue — JSON + null-prototype target + Zod strict()
const { z } = require('zod');
const redis = require('redis').createClient();
const SdkBuildEventSchema = z.object({
skillId: z.string().uuid(),
language: z.enum(['typescript', 'python', 'go', 'java', 'rust']),
version: z.string().regex(/^\d+\.\d+\.\d+$/),
triggeredBy: z.string().uuid(),
}).strict(); // reject unknown keys including __proto__
async function processSdkBuildQueue() {
const raw = await redis.lpop('sdk:build:queue');
if (!raw) return;
// JSON.parse into null-prototype object prevents __proto__ chain pollution
const obj = JSON.parse(raw, (key, value) => {
if (key === '__proto__') throw new Error('Prototype pollution attempt rejected');
return value;
});
const event = SdkBuildEventSchema.parse(Object.assign(Object.create(null), obj));
await handleSdkBuildEvent(event);
}
DESER48-004 — node-serialize IIFE gadget in SDK result aggregation
Severity: CRITICAL
The SDK generation result aggregation pipeline uses the node-serialize library to deserialize aggregated result objects read from a persistent store. The node-serialize format supports Immediately Invoked Function Expressions (IIFEs) represented as _$$ND_FUNC$$_function(){ ... }(). When node-serialize encounters this pattern during deserialization, it evaluates the function immediately using eval().
An attacker who can store data in the aggregation result store — via a compromised SDK generation worker, a Redis AUTH bypass, or an injection vulnerability in the aggregation write path — can craft a serialized payload containing an IIFE gadget. The payload executes at aggregation read time, which occurs on every SDK list request since the aggregation pipeline runs synchronously for each request to the SDK listing endpoint. The trigger is proportional to request volume — a popular registry endpoint can be used to amplify RCE frequency across all concurrent SDK API consumers.
// SDK result aggregation — node-serialize with IIFE gadget support
const serialize = require('node-serialize');
const redis = require('redis').createClient();
async function getSdkAggregation(skillId) {
const raw = await redis.get(`sdk:aggregation:${skillId}`);
return serialize.unserialize(raw); // IIFE gadget: _$$ND_FUNC$$_function(){require('child_process').execSync('...')}()
}
// SDK result aggregation — JSON.parse + Zod + IIFE detection guard
const { z } = require('zod');
const redis = require('redis').createClient();
const SdkAggregationSchema = z.object({
skillId: z.string().uuid(),
totalBuilds: z.number().int().nonneg(),
successRate: z.number().min(0).max(1),
languages: z.array(z.enum(['typescript', 'python', 'go', 'java', 'rust'])),
lastBuiltAt: z.string().datetime(),
});
async function getSdkAggregation(skillId) {
const raw = await redis.get(`sdk:aggregation:${skillId}`);
if (!raw) return null;
// reject any payload containing the node-serialize IIFE marker
if (raw.includes('_$$ND_FUNC$$_')) throw new Error('node-serialize gadget payload rejected');
return SdkAggregationSchema.parse(JSON.parse(raw));
}
Run SkillAudit to detect yaml.load() without FAILSAFE_SCHEMA, BSON Code promotion, MessagePack prototype pollution paths, and node-serialize usage in your MCP skill registry SDK generation pipeline. Join the waitlist for access.