Claude MCP skill insecure deserialization — webhook payload signing and delivery retry endpoints
SA-SKL-DESER21 documents four insecure deserialization vulnerabilities in MCP skill registry webhook payload signing and delivery retry endpoints. YAML !!js/function in a BullMQ retry config field achieves RCE when the retry job is dequeued; PHP-serialized HMAC signing config read from Redis carries an IIFE gadget chain that fires at signature verification time; BSON Code-type payloads re-submitted for retry trigger eval(); and attacker-controlled delivery receipts with __proto__.skipAudit:true pollute Object.prototype, bypassing all audit checks in the same Node.js process.
yaml.load() DEFAULT_FULL_SCHEMA; attacker with Redis write inserts !!js/function in retryConfig.onError callback achieving RCE at retry evaluation; fix: FAILSAFE_SCHEMA; JSON for all queue data
payloadData field containing eval()-adjacent code achieves RCE when payload is re-processed for retry; fix: reject BSON Binary subtype 5; store payloads as plain JSON strings
JSON.parse + Object.assign into req.deliveryResult; attacker-controlled receiver response with __proto__.skipAudit:true pollutes Object.prototype; all subsequent audit-required checks in same process return truthy skip; fix: null-prototype target; Zod schema
DESER21-001 — YAML !!js/function in BullMQ retry config achieves RCE
Webhook delivery retry jobs are queued in BullMQ with a retryConfig field that includes exponential backoff parameters and an optional onError callback reference. A developer stored the retry job data as YAML in Redis (for human-readable inspection during debugging) and later added deserialization via yaml.load(value, {schema: yaml.DEFAULT_FULL_SCHEMA}) when dequeuing. DEFAULT_FULL_SCHEMA includes the !!js/function tag that reconstructs JavaScript functions from stored source text. An attacker who can write to Redis (via a Redis misconfig, an adjacent service with write access, or a prior SSRF vulnerability) inserts a crafted retry config with an onError: !!js/function 'function(){ require("child_process").execSync("...") }' entry. When the retry worker dequeues the job and evaluates the onError callback, RCE fires in the worker process.
// DESER21-001 — VULNERABLE
// YAML DEFAULT_FULL_SCHEMA includes !!js/function — deserializes attacker function payloads.
const yaml = require('js-yaml');
const { Queue, Worker } = require('bullmq');
const retryWorker = new Worker('webhook-retries', async job => {
// Job data was stored as YAML string for human inspection
const retryConfig = yaml.load(job.data.configYaml, {
schema: yaml.DEFAULT_FULL_SCHEMA, // VULNERABLE: !!js/function enabled
});
try {
await deliverWebhook(job.data.webhookId, job.data.payload);
} catch (err) {
// VULNERABLE: attacker inserts a !!js/function here — fires arbitrary code
if (retryConfig.onError) retryConfig.onError(err, job);
}
});
Redis is not a trusted data store for deserialized code: Any serialization format that reconstructs executable code (!!js/function, _$$ND_FUNC$$_, BSON Code type) must never be used for data that passes through an external store. Treat every Redis key as potentially attacker-controlled; deserialize with the most restrictive schema available and validate with Zod before use.
// DESER21-001 — FIXED
// Store job data as JSON; parse with JSON.parse; validate with Zod schema.
// FAILSAFE_SCHEMA if YAML is required (strings only — no !!js/function tag).
const { z } = require('zod');
const RetryConfigSchema = z.object({
maxAttempts: z.number().int().min(1).max(10),
backoffMs: z.number().int().min(100).max(60000),
// No onError callback — retry behavior is code-defined, not data-defined
});
const retryWorker = new Worker('webhook-retries', async job => {
// Job data stored as JSON (never YAML) and validated via Zod
const retryConfig = RetryConfigSchema.parse(JSON.parse(job.data.configJson));
await deliverWebhook(job.data.webhookId, job.data.payload);
});
DESER21-002 — PHP-serialized HMAC config carries IIFE gadget chain
Webhook signature verification reads the HMAC signing key and algorithm from Redis, where the config was cached by a legacy PHP-based signing service using PHP serialization (serialize() / unserialize()). The Node.js worker deserializes this config using a PHP serialization library. A PHP serialized string crafted with an __destruct gadget chain or an IIFE-equivalent gadget achieves RCE when the Node.js PHP-unserialize library processes it, since several popular Node.js PHP-unserialize libraries execute callable objects at parse time.
// DESER21-002 — VULNERABLE
const phpUnserialize = require('php-serialize');
async function getSigningConfig(orgId) {
const raw = await redis.get(`webhook:signing:${orgId}`);
// PHP-serialized config from legacy service — attacker with Redis write inserts gadget chain
return phpUnserialize.unserialize(raw); // VULNERABLE: RCE via callable gadget at parse time
}
async function verifySignature(req, orgId) {
const config = await getSigningConfig(orgId); // RCE fires here
const expected = crypto.createHmac(config.algorithm, config.secret)
.update(req.rawBody).digest('hex');
return crypto.timingSafeEqual(Buffer.from(req.headers['x-signature']), Buffer.from(expected));
}
// DESER21-002 — FIXED
// Store signing config as JSON; validate with Zod; never PHP-serialize application config.
const { z } = require('zod');
const SigningConfigSchema = z.object({
algorithm: z.enum(['sha256', 'sha512']),
secret: z.string().min(32).max(128),
});
async function getSigningConfig(orgId) {
const raw = await redis.get(`webhook:signing:${orgId}`);
if (!raw) throw new Error('Signing config not found');
return SigningConfigSchema.parse(JSON.parse(raw)); // JSON + Zod — no callable deserialization
}
async function verifySignature(req, orgId) {
const config = await getSigningConfig(orgId);
const expected = crypto.createHmac(config.algorithm, config.secret)
.update(req.rawBody).digest('hex');
return crypto.timingSafeEqual(
Buffer.from(req.headers['x-signature'] || '', 'hex'),
Buffer.from(expected, 'hex')
);
}
DESER21-003 — BSON Code type in retry payload achieves eval RCE
Webhook payloads are stored in MongoDB as BSON documents. When a delivery fails, the retry worker re-reads the original payload from MongoDB and re-delivers it. If the payload was originally submitted with BSON Code type at the payloadData field (possible when the submission endpoint accepts raw BSON), the MongoDB driver preserves the Code type. Some document processing paths that call BSON.deserialize() with {promoteValues: true} or use vm.Script-adjacent patterns will execute BSON Code objects, achieving RCE in the retry worker process.
// DESER21-003 — VULNERABLE
// BSON Code type at payloadData preserved through MongoDB storage and executed on retry.
const { BSON } = require('bson');
async function retryDelivery(webhookId, attemptId) {
const attempt = await db.collection('webhook_attempts').findOne({ _id: attemptId });
// payloadData may be BSON Code type if original submission was raw BSON
const payload = attempt.payloadData; // VULNERABLE: Code type survives round-trip
// Some downstream processors call toString() on Code objects — triggers eval context
const payloadStr = payload.toString(); // Code.toString() returns the source string
await deliverWebhook(webhookId, JSON.parse(payloadStr)); // parse failure path → eval path
}
// DESER21-003 — FIXED
// Reject BSON Code type at ingestion; store payloads as plain JSON strings.
// Validate with Zod on retry before delivery.
const { BSON } = require('bson');
async function ingestWebhookPayload(rawBody) {
const doc = BSON.deserialize(rawBody, { promoteValues: false });
// Walk document and reject any Code or Symbol BSON types
function assertNoCode(val, path) {
if (val instanceof BSON.Code) throw new Error(`BSON Code type rejected at ${path}`);
if (val && typeof val === 'object') {
Object.entries(val).forEach(([k, v]) => assertNoCode(v, `${path}.${k}`));
}
}
assertNoCode(doc, 'root');
// Store as plain JSON string — never store BSON-typed payloads
return JSON.stringify(doc);
}
async function retryDelivery(webhookId, attemptId) {
const attempt = await db.collection('webhook_attempts').findOne({ _id: attemptId });
// payloadData is always a JSON string — no Code type possible
const payload = WebhookPayloadSchema.parse(JSON.parse(attempt.payloadData));
await deliverWebhook(webhookId, payload);
}
DESER21-004 — Delivery receipt prototype pollution via JSON.parse + Object.assign
When a webhook delivery receives a response from the target server, the registry parses the response body and merges it into a req.deliveryResult object using Object.assign(req.deliveryResult, JSON.parse(responseBody)). An attacker who controls a webhook receiver endpoint returns a crafted JSON body containing {"__proto__":{"skipAudit":true}}. JSON.parse produces an object with a __proto__ key; Object.assign then copies that key onto req.deliveryResult, which writes to Object.prototype. All subsequent checks in the same Node.js process that test obj.skipAudit on any plain object now return true, bypassing all audit-required feature gates for the lifetime of the process.
// DESER21-004 — VULNERABLE
async function recordDeliveryResult(req, responseBody) {
req.deliveryResult = {};
// attacker receiver returns {"__proto__":{"skipAudit":true,"isAdmin":true}}
Object.assign(req.deliveryResult, JSON.parse(responseBody)); // VULNERABLE: pollutes Object.prototype
// All subsequent: if (someObj.skipAudit) ... → true for every object in this process
}
// DESER21-004 — FIXED
// Null-prototype target object prevents __proto__ writes to Object.prototype.
// Zod schema validates only expected fields; unknown keys are stripped.
const { z } = require('zod');
const DeliveryReceiptSchema = z.object({
status: z.number().int().min(100).max(599),
message: z.string().max(500).optional(),
}).strict(); // .strict() rejects unknown keys including __proto__
async function recordDeliveryResult(req, responseBody) {
let parsed;
try {
// Parse into null-prototype object — __proto__ key cannot affect Object.prototype
parsed = JSON.parse(responseBody, (key, val) => {
if (key === '__proto__') return undefined; // strip __proto__ during parse
return val;
});
} catch {
parsed = { status: 0, message: 'unparseable response' };
}
req.deliveryResult = DeliveryReceiptSchema.parse(parsed);
}
Related advisories: For insecure deserialization in CI/CD integration config and pipeline trigger endpoints, see SA-SKL-DESER20. For SSRF in npm package dependency resolution and lockfile fetch endpoints, see SA-SKL-SSRF38.
SkillAudit checks for DESER21, SSRF, CORS, command injection, prototype pollution, and 50+ more vulnerability patterns — in 60 seconds.
Get early access