Claude MCP skill insecure deserialization — skill rate limiting and quota enforcement pipeline endpoints — SA-SKL-DESER50
SA-SKL-DESER50 documents four insecure deserialization vulnerabilities in MCP skill registry rate limiting and quota enforcement pipeline endpoints. Rate limiting and quota enforcement pipelines execute on every inbound API request, making deserialization gadgets in these paths exploitable by any authenticated or unauthenticated API consumer rather than only privileged administrators. DESER50-001: yaml.load() with DEFAULT_FULL_SCHEMA on Redis-cached rate limit configuration enables RCE at every rate limit breach event; DESER50-002: BSON Code type deserialization from MongoDB enables eval() during quota enforcement at every API request; DESER50-003: MessagePack deserialization of the rate limit event queue enables prototype pollution that disables authentication on all subsequent requests; DESER50-004: node-serialize deserialization on quota aggregation enables IIFE RCE reachable from any API consumer.
yaml.load() DEFAULT_FULL_SCHEMA — !!js/function in rateLimitConfig.onLimitExceeded achieves RCE at every rate limit breach event triggered by any API consumer; fix: FAILSAFE_SCHEMA; JSON for all rate limit config; Zod RateLimitConfigSchema; named-event dispatch tableCode type at quotaEnforcerFn field triggers eval() during quota enforcement at every API request; fix: reject BSON Code; promoteValues:false; Zod string-only schema; named-enforcer lookup with allowlist of enforcer strategies__proto__.skipRateLimitAuth:true pollutes Object.prototype, disabling authentication checks for all subsequent rate limit API requests in process until restart; fix: null-prototype target; Zod strict(); JSON instead of MessagePack; reject __proto__ keys explicitlynode-serialize — IIFE gadget achieves RCE at quota aggregation time reachable from any user making API requests since aggregation runs on every request; fix: JSON.parse + Zod; detect and reject _$$ND_FUNC$$_ payloads; sealed config at deploy timeDESER50-001 — RCE via yaml.load() on Redis-cached rate limit configuration
Severity: CRITICAL
The rate limiting pipeline reads its configuration from Redis using yaml.load() with the default DEFAULT_FULL_SCHEMA. This schema enables the !!js/function YAML type tag, which reconstructs JavaScript functions from their source text at parse time. Any process that can write to the Redis key storing rate limit configuration can embed a function payload at rateLimitConfig.onLimitExceeded, and that payload will execute inside the registry API process every time a rate limit breach is detected.
Rate limit breaches are triggered by any API consumer making requests above the configured threshold. This means the RCE trigger is not gated on administrative access or privileged operations — a free-tier API key holder can deliberately exceed the rate limit to force repeated executions of the attacker-controlled payload. The payload executes in the same process as the registry API server with full access to environment variables containing database credentials, cloud provider tokens, and signing keys. The attacker need not control any network path to the Redis instance directly — compromising any upstream service that writes to the rate limit configuration key (a configuration management pipeline, an A/B testing system, an operator console) is sufficient.
const yaml = require('js-yaml');
async function getRateLimitConfig(skillId) {
const raw = await redis.get(`ratelimit:config:${skillId}`);
return yaml.load(raw); // DEFAULT_FULL_SCHEMA — executes !!js/function payloads
}
// In rate limit middleware:
const config = await getRateLimitConfig(skillId);
if (requestCount > config.limit) {
config.onLimitExceeded?.(req, res); // executes attacker function if config is poisoned
}
const yaml = require('js-yaml');
const RateLimitConfigSchema = z.object({
limit: z.number().int().min(1).max(10000),
windowMs: z.number().int().min(1000).max(86400000),
onLimitExceeded: z.enum(['block', 'throttle', 'log']), // named strategies only
});
const ON_LIMIT_HANDLERS = { block: blockHandler, throttle: throttleHandler, log: logHandler };
async function getRateLimitConfig(skillId) {
const raw = await redis.get(`ratelimit:config:${skillId}`);
const parsed = JSON.parse(raw); // JSON only — no YAML function tags
const validated = RateLimitConfigSchema.parse(parsed);
return validated;
}
// In rate limit middleware:
const config = await getRateLimitConfig(skillId);
if (requestCount > config.limit) {
await ON_LIMIT_HANDLERS[config.onLimitExceeded](req, res);
}
The fix replaces yaml.load() with JSON.parse() for all rate limit configuration reads from Redis, eliminating the YAML function tag execution path entirely. The Zod RateLimitConfigSchema enforces that onLimitExceeded is one of three named handler strings rather than arbitrary code, and the named dispatch table resolves those strings to pre-defined handler functions. No configuration value from Redis is ever used as executable code; the handler resolution happens entirely in server-controlled lookup tables.
DESER50-002 — eval() via BSON Code type in MongoDB quota enforcer field
Severity: CRITICAL
The quota enforcement model reads from MongoDB using the Node.js driver's default BSON deserialization settings, which promote BSON Code objects to JavaScript Code instances. When the quotaEnforcerFn field in the quota model document contains a BSON Code value, the driver deserializes it as a callable Code instance. The quota enforcement middleware then invokes this function to evaluate whether the request falls within the quota bounds, triggering eval()-equivalent code execution with the request context as the argument.
The quotaEnforcerFn field can be set to a BSON Code value via MongoDB injection in any upstream endpoint that writes to the quota model collection without validating the BSON type of function fields. MCP skill registry platforms often have several such write paths: quota configuration UI endpoints, bulk configuration import routes, and administrative migration scripts. An attacker who can inject a BSON Code payload into any of these paths will have their payload executed once per API request during quota enforcement — a high-frequency execution surface that maximizes the probability of successful exfiltration or persistent access establishment before the payload is detected and removed.
// MongoDB driver default: promoteValues: true (default) promotes BSON Code to Code object
const quotaDoc = await QuotaModel.findOne({ skillId });
// quotaDoc.quotaEnforcerFn is a BSON Code object if stored as Code type
if (quotaDoc.quotaEnforcerFn) {
const enforcer = new Function('req', quotaDoc.quotaEnforcerFn.code);
const withinQuota = enforcer(req); // executes attacker code
if (!withinQuota) return res.status(429).json({ error: 'Quota exceeded' });
}
const QUOTA_ENFORCERS = {
'standard': standardQuotaEnforcer,
'burst-allowed': burstAllowedEnforcer,
'hard-cap': hardCapEnforcer,
};
const QuotaModelSchema = z.object({
skillId: z.string(),
quotaEnforcerName: z.enum(['standard', 'burst-allowed', 'hard-cap']),
dailyLimit: z.number().int().min(0),
burstLimit: z.number().int().min(0).optional(),
});
// Use promoteValues: false to prevent BSON Code promotion
const quotaDoc = await QuotaModel.findOne({ skillId }, {}, { promoteValues: false });
const validated = QuotaModelSchema.parse(quotaDoc.toObject());
const enforcer = QUOTA_ENFORCERS[validated.quotaEnforcerName];
const withinQuota = await enforcer(req, validated);
The fix uses promoteValues: false in the MongoDB driver options to prevent BSON Code objects from being promoted to callable JavaScript instances. The Zod QuotaModelSchema validates that quotaEnforcerName is one of three named enforcer strings and rejects any document that contains unexpected fields. The named dispatch table resolves enforcer names to pre-defined server-side functions, ensuring that no value read from MongoDB is ever used as executable code.
DESER50-003 — Prototype pollution via MessagePack rate limit event queue disables authentication
Severity: CRITICAL
The rate limit event queue is stored in Redis and serialized using MessagePack. When a rate limit event is dequeued, the MessagePack payload is deserialized into a plain JavaScript object without prototype isolation. A MessagePack payload containing a key named __proto__ with an object value is deserialized directly onto Object.prototype, poisoning every subsequent plain-object property lookup in the Node.js process for the remainder of the process lifetime.
Setting __proto__.skipRateLimitAuth to true causes any authentication middleware that checks if (obj.skipRateLimitAuth) to evaluate true for every request, even on objects that never had this property set, because the lookup falls through to the poisoned prototype. The authentication bypass persists across all subsequent requests in the process until the Node.js worker restarts. Rate limit event queues are frequently writable by services that report rate limit violations — telemetry collectors, CDN edge nodes, reverse proxies — any of which can be a vector for injecting a malicious MessagePack event without requiring direct access to the registry API server or its Redis instance.
const msgpack = require('msgpack5')();
async function processRateLimitEvent() {
const raw = await redis.lpop('ratelimit:events');
if (!raw) return;
const event = msgpack.decode(Buffer.from(raw, 'base64'));
// event may contain __proto__: { skipRateLimitAuth: true }
// This merges onto Object.prototype, affecting all subsequent objects
Object.assign({}, event); // triggers prototype pollution during spread
await handleRateLimitEvent(event);
}
const RateLimitEventSchema = z.object({
skillId: z.string(),
consumerId: z.string(),
timestamp: z.number(),
requestCount: z.number().int().min(0),
windowStart: z.number(),
}).strict();
async function processRateLimitEvent() {
const raw = await redis.lpop('ratelimit:events');
if (!raw) return;
// Use JSON instead of MessagePack — no __proto__ key support in JSON.parse
const parsed = JSON.parse(raw);
if (typeof parsed === 'object' && parsed !== null && '__proto__' in parsed) {
logger.warn('Rejected rate limit event with __proto__ key — potential prototype pollution attempt');
return;
}
const target = Object.create(null); // null-prototype target prevents prototype chain pollution
const event = RateLimitEventSchema.parse(Object.assign(target, parsed));
await handleRateLimitEvent(event);
}
The fix replaces MessagePack with JSON for rate limit event queue serialization. JSON.parse() does not set prototype properties for __proto__ keys — it treats them as regular own properties. The explicit __proto__ key check provides a secondary defense with alerting. The Object.create(null) null-prototype target prevents any assignment from reaching Object.prototype. The Zod strict() schema via RateLimitEventSchema rejects any payload that contains fields not defined in the schema, eliminating unknown-key pollution vectors.
DESER50-004 — RCE via node-serialize IIFE gadget in quota aggregation
Severity: CRITICAL
The quota aggregation pipeline reads serialized aggregation state from Redis using node-serialize. The node-serialize library supports a special marker _$$ND_FUNC$$_ that reconstructs functions from their serialized source text. An Immediately Invoked Function Expression (IIFE) embedded in a serialized payload using this marker executes at deserialization time without any subsequent call, triggering RCE as soon as node-serialize's unserialize() processes the payload.
Quota aggregation runs on every API request to determine whether the requesting consumer has remaining quota for the current billing window. This means the RCE trigger executes at the same frequency as inbound API traffic — a high-volume execution surface with no authentication gate between the trigger and the RCE. Any service that can write to the Redis key storing quota aggregation state (quota reset jobs, billing reconciliation services, usage reporting pipelines) can inject a node-serialize IIFE payload. The aggregation result is not checked for the _$$ND_FUNC$$_ marker before deserialization, so the payload executes before any validation can occur.
const serialize = require('node-serialize');
async function getQuotaAggregation(consumerId) {
const raw = await redis.get(`quota:agg:${consumerId}`);
if (!raw) return null;
return serialize.unserialize(raw); // executes _$$ND_FUNC$$_ IIFE at parse time
}
// In quota enforcement middleware (runs on every request):
const agg = await getQuotaAggregation(req.consumerId);
if (agg && agg.usedQuota >= agg.totalQuota) {
return res.status(429).json({ error: 'Quota exceeded' });
}
const QuotaAggregationSchema = z.object({
consumerId: z.string(),
usedQuota: z.number().int().min(0),
totalQuota: z.number().int().min(0),
windowStart: z.number(),
windowEnd: z.number(),
});
async function getQuotaAggregation(consumerId) {
const raw = await redis.get(`quota:agg:${consumerId}`);
if (!raw) return null;
if (raw.includes('_$$ND_FUNC$$_')) {
logger.error('Rejected quota aggregation with node-serialize function marker — potential RCE attempt');
return null;
}
const parsed = JSON.parse(raw); // JSON.parse only — no function reconstruction
return QuotaAggregationSchema.parse(parsed);
}
The fix replaces node-serialize with JSON.parse() for all quota aggregation deserialization. JSON.parse() does not support function reconstruction — values containing the _$$ND_FUNC$$_ marker are treated as plain strings. The explicit marker check before parsing provides an early-detection tripwire that logs the injection attempt before any parsing occurs. The Zod QuotaAggregationSchema validates that the deserialized object matches the expected shape and numeric bounds, rejecting payloads with unexpected fields or out-of-range values that could affect quota enforcement logic.
Run SkillAudit to detect yaml.load() without FAILSAFE_SCHEMA, BSON Code deserialization paths, MessagePack __proto__ pollution vectors, and node-serialize usage in your MCP skill registry source code. Join the waitlist for access.