Claude MCP skill prototype pollution — lodash.merge and Object.assign configuration merge — SA-SKL-DESER5
MCP skill registries let authors customize their skill's behavior through configuration objects — runtime settings, feature flags, environment overrides. When the registry merges user-supplied configuration into a base config using lodash.merge() or Object.assign(), a carefully crafted __proto__ key in the user input can mutate Object.prototype — the shared prototype inherited by every JS object in the process. SA-SKL-DESER5 covers the four lodash.merge and Object.assign prototype pollution patterns SkillAudit finds in MCP skill registry configuration handling.
lodash.merge(config, userInput) where userInput contains {"__proto__":{"isAdmin":true}}; lodash traverses the prototype chain; Object.prototype.isAdmin becomes true for all objects in the processObject.assign({}, baseConfig, ...userConfigs) where a userConfig was created from JSON with a __proto__ key; V8 propagates the prototype key on spread; fix: JSON.parse(JSON.stringify(input)) before mergeadditionalProperties with no key name restrictions; attacker submits {"__proto__":{"debugMode":true}} in schema properties value and it passes validation{...defaultConfig, ...req.body} where req.body is parsed by qs; query string __proto__[isAdmin]=true creates a __proto__ key in the parsed object; spread picks it upDESER5-001 — lodash.merge with __proto__ key in user input
Versions of lodash prior to 4.17.17 have a known prototype pollution vulnerability via _.merge(). Even in patched versions, the application-level code is responsible for not calling merge() with untrusted input that contains dangerous keys. When a skill registry calls lodash.merge(internalConfig, userSuppliedConfig) to apply author-supplied overrides, the merge traverses nested objects recursively — including the __proto__ key.
// DESER5-001 — VULNERABLE
// lodash.merge traverses __proto__ key in user-supplied configuration,
// mutating Object.prototype for the entire process.
import _ from 'lodash';
const defaultSkillConfig = {
timeout: 30000,
maxRetries: 3,
sandbox: { network: 'none', memory: '256m' },
};
app.post('/api/skills/:skillId/config', authenticate, async (req, res) => {
const userConfig = req.body; // user-supplied JSON
// VULNERABLE: lodash.merge traverses __proto__ in userConfig
const finalConfig = _.merge({}, defaultSkillConfig, userConfig);
await db.saveSkillConfig(req.params.skillId, finalConfig);
res.json({ success: true });
});
// Attacker sends:
// {"sandbox":{"network":"host"},"__proto__":{"isAdmin":true}}
// After lodash.merge, Object.prototype.isAdmin === true
// Every subsequent ({}).isAdmin returns true — including req.user.isAdmin
// DESER5-001 — FIXED
// lodash.mergeWith with custom source validation rejecting dangerous keys.
// Also: Zod schema to constrain the shape before merge.
import _ from 'lodash';
import { z } from 'zod';
const DANGEROUS_KEYS = new Set(['__proto__', 'constructor', 'prototype']);
const SkillConfigSchema = z.object({
timeout: z.number().int().min(1000).max(300000).optional(),
maxRetries: z.number().int().min(0).max(10).optional(),
sandbox: z.object({
network: z.enum(['none', 'bridge']).optional(),
memory: z.string().regex(/^\d+m$/).optional(),
}).optional(),
});
function safeCustomizer(objValue, srcValue, key) {
// Fix 1: reject dangerous key names during merge traversal
if (DANGEROUS_KEYS.has(key)) return objValue;
return undefined; // use default merge for all other keys
}
app.post('/api/skills/:skillId/config', authenticate, async (req, res) => {
// Fix 2: Zod validation before merge limits shape to known fields
const userConfig = SkillConfigSchema.parse(req.body);
// Fix 3: lodash.mergeWith with custom key guard
const finalConfig = _.mergeWith({}, defaultSkillConfig, userConfig, safeCustomizer);
await db.saveSkillConfig(req.params.skillId, finalConfig);
res.json({ success: true });
});
Process-wide mutation: Once Object.prototype is mutated, the effect is permanent for the lifetime of the process. Every object created after the mutation — including req.user objects in subsequent HTTP requests, session objects from other users, and configuration objects read from the database — will have the polluted property. A single attacker request can escalate privileges for all subsequent requests handled by the same process worker, until the process is restarted.
DESER5-002 — Object.assign spread with __proto__ key
When a plain object is created from JSON that contains a "__proto__" key, the resulting object has a property named __proto__ accessible via Object.getOwnPropertyDescriptor but not via prototype traversal — JSON.parse() alone is safe. The danger arises when that object is later spread with Object.assign(): in some V8 versions, Object.assign({}, obj) where obj has an own property named __proto__ can trigger prototype chain mutation depending on the descriptor type.
// DESER5-002 — VULNERABLE
// Object.assign with spread of multiple userConfigs, one of which has __proto__.
// V8 behavior: own property __proto__ with data descriptor may mutate prototype.
app.post('/api/skills/:skillId/bulk-config', authenticate, async (req, res) => {
const userConfigs = req.body.configs; // array of config objects
// Each config parsed from JSON — JSON.parse alone is safe
// But Object.assign with spread can trigger prototype mutation in V8
const merged = Object.assign({}, defaultSkillConfig, ...userConfigs);
await db.saveSkillConfig(req.params.skillId, merged);
res.json({ success: true });
});
// Attacker sends:
// {"configs": [{"timeout": 5000}, {"__proto__": {"isAdmin": true}}]}
// Object.assign propagates the __proto__ property from the second config
// DESER5-002 — FIXED
// JSON.parse(JSON.stringify(input)) strips __proto__ and constructor keys
// before Object.assign — the round-trip produces a clean plain object.
app.post('/api/skills/:skillId/bulk-config', authenticate, async (req, res) => {
const userConfigs = req.body.configs;
if (!Array.isArray(userConfigs) || userConfigs.length > 5) {
return res.status(400).json({ error: 'Invalid configs array' });
}
// Fix: round-trip through JSON serialization strips dangerous keys
// JSON.stringify omits properties with function values and skips __proto__
// JSON.parse produces a clean object with no prototype chain manipulation
const sanitised = userConfigs.map(c => JSON.parse(JSON.stringify(c)));
// Now safe to spread — sanitised objects have no __proto__ own property
const merged = Object.assign({}, defaultSkillConfig, ...sanitised);
await db.saveSkillConfig(req.params.skillId, merged);
res.json({ success: true });
});
DESER5-003 — AJV schema with additionalProperties allowing __proto__ keys
When a skill registry allows authors to supply a JSON Schema definition for their skill's input parameters (for documentation and client validation), the registry may use AJV to validate the schema before storing it. If the AJV schema used to validate the user-supplied schema has additionalProperties: true or no restriction on property names inside properties, the user-supplied schema can contain a "__proto__" property definition. When this schema is later merged with a base schema object via lodash.merge() or Object.assign(), the pollution occurs at schema-load time.
// DESER5-003 — VULNERABLE
// AJV meta-schema validation allows additionalProperties in user-supplied schema.
// User schema with __proto__ property definition passes AJV validation.
// Deep merge at schema registration time mutates Object.prototype.
import Ajv from 'ajv';
import _ from 'lodash';
const ajv = new Ajv();
const baseSchema = {
type: 'object',
properties: { query: { type: 'string' } },
};
app.post('/api/skills/:skillId/input-schema', authenticate, async (req, res) => {
const userSchema = req.body;
// AJV validates that userSchema is a valid JSON Schema — but allows any property names
const isValidSchema = ajv.validateSchema(userSchema);
if (!isValidSchema) return res.status(400).json({ error: 'Invalid JSON Schema' });
// VULNERABLE: lodash.merge with schema that may have __proto__ key
// e.g. {"type":"object","properties":{"__proto__":{"type":"object","default":{"isAdmin":true}}}}
const finalSchema = _.merge({}, baseSchema, userSchema);
await db.saveInputSchema(req.params.skillId, finalSchema);
res.json({ success: true });
});
// DESER5-003 — FIXED
// Pre-validation step strips dangerous keys from schema before merge.
// AJV configured with strict mode — unknown keywords rejected.
import Ajv from 'ajv';
import _ from 'lodash';
const DANGEROUS_KEYS = new Set(['__proto__', 'constructor', 'prototype']);
function sanitiseSchemaObject(obj, depth = 0) {
if (depth > 10 || typeof obj !== 'object' || obj === null) return obj;
const clean = {};
for (const [key, value] of Object.entries(obj)) {
if (DANGEROUS_KEYS.has(key)) continue; // Fix 1: drop dangerous keys
clean[key] = typeof value === 'object'
? sanitiseSchemaObject(value, depth + 1) // Fix 2: recurse safely
: value;
}
return clean;
}
app.post('/api/skills/:skillId/input-schema', authenticate, async (req, res) => {
// Fix 3: sanitise before AJV validation — prevents dangerous keys reaching merge
const userSchema = sanitiseSchemaObject(req.body);
const ajv = new Ajv({ strict: true }); // strict mode rejects unknown keywords
const isValidSchema = ajv.validateSchema(userSchema);
if (!isValidSchema) return res.status(400).json({ error: 'Invalid JSON Schema' });
const finalSchema = _.mergeWith({}, baseSchema, userSchema,
(objVal, srcVal, key) => DANGEROUS_KEYS.has(key) ? objVal : undefined
);
await db.saveInputSchema(req.params.skillId, finalSchema);
res.json({ success: true });
});
DESER5-004 — qs library __proto__ in req.body spread
Express's body-parser with extended: true uses the qs library to parse URL-encoded bodies. The qs library supports nested objects via bracket notation: config[timeout]=5000 produces { config: { timeout: '5000' } }. The same mechanism produces __proto__[isAdmin]=true → { __proto__: { isAdmin: 'true' } } in the parsed object. When this parsed body is spread into a configuration object, the prototype pollution vector exists.
// DESER5-004 — VULNERABLE
// qs parses __proto__[isAdmin]=true as a __proto__ key in the req.body object.
// Object spread picks up the prototype key.
import express from 'express';
const app = express();
app.use(express.urlencoded({ extended: true })); // uses qs — supports nested objects
app.post('/api/skills/:skillId/settings', authenticate, (req, res) => {
// VULNERABLE: req.body may have __proto__ own property from qs parsing
const settings = { ...defaultSettings, ...req.body };
// settings.__proto__ may now be { isAdmin: 'true' }
applySettings(req.params.skillId, settings);
res.json({ success: true });
});
// Attacker sends URL-encoded body:
// __proto__[isAdmin]=true&timeout=5000
// qs produces: { __proto__: { isAdmin: 'true' }, timeout: '5000' }
// Spread propagates __proto__ onto the new object's prototype
// DESER5-004 — FIXED
// Zod validation before spread: schema defines known keys only.
// Use JSON body parser (not qs) for structured data — JSON.parse does not create __proto__ own props.
import express from 'express';
import { z } from 'zod';
const app = express();
// Fix 1: use JSON body parser for skill settings (not URL-encoded / qs)
app.use(express.json());
const SettingsSchema = z.object({
timeout: z.number().int().min(1000).max(300000),
maxRetries: z.number().int().min(0).max(10),
webhookUrl: z.string().url().optional(),
});
app.post('/api/skills/:skillId/settings', authenticate, (req, res) => {
// Fix 2: Zod parse — only declared fields are present in the result; __proto__ absent
const settings = SettingsSchema.parse(req.body);
// Fix 3: spread is now safe — Zod output is a plain object with known keys only
const finalSettings = { ...defaultSettings, ...settings };
applySettings(req.params.skillId, finalSettings);
res.json({ success: true });
});
Use JSON body parser over URL-encoded for structured data: The qs library's nested object parsing is a source of prototype pollution vectors regardless of the spread operation. For API endpoints that accept structured configuration, use express.json() (which calls JSON.parse()) rather than express.urlencoded({ extended: true }). JSON.parse() does not create own properties named __proto__ — the resulting object is clean. Reserve URL-encoded body parsing for simple flat form submissions. For more deserialization patterns in MCP skill registries see SA-SKL-DESER4 (Redis pub/sub and BullMQ).
How SkillAudit detects SA-SKL-DESER5
SkillAudit's static analysis scans for four patterns:
- DESER5-001: Finds
_.merge(orlodash.merge(calls; checks whether any source argument comes from request body, query params, or other external input without an intervening Zod/Joi validation; flags CRITICAL. - DESER5-002: Finds
Object.assign(with spread (...array) where the array elements are derived from external input; checks for JSON round-trip sanitization; flags HIGH if absent. - DESER5-003: Finds
ajv.validateSchema(followed by a merge of the validated input; checks for a sanitizeSchemaObject-equivalent step that removes__proto__keys; flags HIGH. - DESER5-004: Finds
express.urlencoded({ extended: true })in the same codebase as object spread ofreq.bodywithout Zod pre-validation; flags MEDIUM.
| Pattern | Root cause | Fix | Severity |
|---|---|---|---|
| DESER5-001 | lodash.merge with untrusted source containing __proto__ key | Zod schema pre-validation + lodash.mergeWith with key guard | CRITICAL |
| DESER5-002 | Object.assign spread with __proto__ own property in V8 | JSON.parse(JSON.stringify(input)) round-trip before spread | HIGH |
| DESER5-003 | AJV schema validation allows __proto__ in additionalProperties | sanitiseSchemaObject to strip dangerous keys before merge | HIGH |
| DESER5-004 | qs body parser produces __proto__ own prop from bracket notation | Use express.json() + Zod validation before any spread | MEDIUM |