Claude MCP skill prototype pollution via skill configuration merging and deep object assignment — SA-SKL-INJECTION11
Skill configuration merging is a common operation in MCP skill platforms — developer-submitted configuration objects are merged into application defaults to customize skill runtime behavior. When this merge uses a deep-object-merge function and the source object comes from user input (the skill manifest, the skill configuration API endpoint, or the skill runtime options), prototype pollution is possible. SA-SKL-INJECTION11 covers four patterns: lodash.merge() with attacker-supplied __proto__ keys, Object.assign() shallow spread with nested prototype paths, for...in enumeration without hasOwnProperty(), and Ajv schema validation that permits __proto__ as an additional property before Ajv v8.
lodash.merge(applicationConfig, req.body.config) with attacker payload {"__proto__":{"isAdmin":true}} sets Object.prototype.isAdmin = true for all objects in the process for the lifetime of the request handler; privilege escalation gates checking obj.isAdmin silently evaluate trueObject.assign(target, userOptions) where attacker sends {"constructor":{"prototype":{"polluted":true}}} — shallow assign copies the constructor key; accessing userOptions.constructor.prototype reaches Object.prototype; subsequent property reads on any plain object return the injected valuefor (const key in userConfig) { appConfig[key] = userConfig[key]; } iterates the prototype chain; attacker object constructed via Object.create({ injected: true }) exposes inherited property through for...in; missing hasOwnProperty() guard copies inherited keys into application configadditionalProperties: false validates schema structure but does not specifically forbid __proto__ as a key name because JSON Schema does not define it as special; attacker payload passes Ajv validation, then subsequent Object.assign({}, req.body.config) pollutes Object.prototypeINJECTION11-001 — lodash.merge() prototype pollution via __proto__ in skill config
MCP skill platforms that accept a developer-supplied configuration object to override defaults often use lodash.merge() for deep merging because it correctly handles nested objects and arrays. The vulnerability arises because lodash.merge() recursively processes every key in the source object, including __proto__. When the merge function recurses into __proto__, it writes properties directly onto Object.prototype — the shared prototype for all plain objects in the Node.js process. Any object created after the pollution (and before a process restart) will inherit the injected properties, silently defeating authorization checks that look for the property with a truthy test.
lodash versions below 4.17.21 carry CVE-2019-10744, making this directly exploitable with no additional steps. Even lodash 4.17.21+ can be polluted via constructor.prototype as an alternative path. The impact is process-wide and persistent across all requests handled by the same Node.js worker until the process restarts.
// VULNERABLE — skill runtime configuration merge
const lodash = require('lodash');
app.post('/api/skills/:id/configure', async (req, res) => {
const defaultConfig = { timeout: 5000, retries: 3, isAdmin: false };
// req.body.skillConfig comes from the developer's skill manifest
// Attacker payload: { "__proto__": { "isAdmin": true } }
const merged = lodash.merge({}, defaultConfig, req.body.skillConfig);
// Prototype is now polluted — Object.prototype.isAdmin === true
// Every subsequent plain object inherits isAdmin: true
const user = await db.getUser(req.session.userId); // plain object from DB row
if (merged.isAdmin || req.user.isAdmin) {
// req.user.isAdmin is a plain object property lookup
// After pollution: ({}).isAdmin === true — always passes
return res.json({ adminToken: generateAdminToken() });
}
res.json({ config: merged });
});
Process-wide impact: Prototype pollution via lodash.merge() affects all objects allocated in the same process after the polluted merge. A single malicious skill configuration request can elevate every subsequent request's privilege checks until the Node.js worker restarts. In clustered environments, each worker that processes the malicious request is independently compromised.
The fix serializes the user-supplied configuration through JSON.parse(JSON.stringify()) before merging. This round-trip through JSON drops __proto__ keys because JSON.stringify() does not serialize prototype properties. In Node.js 17 and later, structuredClone() provides the same sanitization with better performance and correct handling of non-JSON types. Apply the sanitization step before any merge operation, not after.
// FIXED — sanitize user input before deep merge
const lodash = require('lodash');
app.post('/api/skills/:id/configure', async (req, res) => {
const defaultConfig = { timeout: 5000, retries: 3, isAdmin: false };
// Strip __proto__ and constructor keys via JSON round-trip
// JSON.stringify silently drops __proto__ — it is not a serializable key
const sanitized = JSON.parse(JSON.stringify(req.body.skillConfig));
// Node 17+: use structuredClone() — handles circular refs, Date, Map, Set
// const sanitized = structuredClone(req.body.skillConfig);
const merged = lodash.merge({}, defaultConfig, sanitized);
// Object.prototype is unaffected — sanitized object has no __proto__ key
res.json({ config: merged });
});
Detection: SkillAudit scans for lodash.merge(, _.merge(, and deepmerge( calls where any argument is derived from req.body, req.query, params, or any MCP tool call parameter. If no preceding JSON.parse(JSON.stringify( or structuredClone( sanitization is detected on that argument, the call is flagged INJECTION11-001 CRITICAL. The scanner also checks lodash version constraints in package.json and flags lodash <4.17.21 as a secondary finding citing CVE-2019-10744.
INJECTION11-002 — Object.assign() shallow spread with nested __proto__
Object.assign(target, source) performs a shallow copy — it copies only the source object's own enumerable properties. At first glance this seems safe: __proto__ is not an own enumerable property of a plain object literal. The pollution vector here is different: the attacker sends {"constructor":{"prototype":{"polluted":true}}}. constructor is an own enumerable property when explicitly present in a JSON object; Object.assign() copies it to the target. If any subsequent code accesses target.constructor.prototype, it now reaches a user-controlled object. When that path modifies Object.prototype (or the downstream code merges target.constructor.prototype into another object), pollution occurs.
// VULNERABLE — skill options assignment
app.post('/api/skills/:id/options', (req, res) => {
const defaultOptions = { debug: false, maxTokens: 1000 };
// Attacker sends: { "constructor": { "prototype": { "admin": true } } }
const options = Object.assign({}, defaultOptions, req.body.skillOptions);
// options.constructor now points to attacker-controlled object
// options.constructor.prototype === Object.prototype after some lodash internals
// or attacker chains: options.constructor.prototype.admin = true via further assign
// Even without immediate pollution, the constructor key is unexpected
// and can be used to bypass instanceof checks or confuse serialization
saveSkillOptions(options);
res.json({ saved: true });
});
Alternative pollution path: Some merge utilities iterate nested objects recursively after an initial Object.assign(). When a utility calls Object.assign(target.constructor, source.constructor) during recursive merge, it modifies the constructor function itself — potentially replacing methods on Function.prototype. The exploit chain is more complex than direct __proto__ pollution but equally impactful in deep-merge pipelines.
The correct fix filters the source object's keys before assignment, explicitly blocking __proto__, constructor, and prototype. For more robust protection, validate the entire shape of the incoming object with a schema library (zod, ajv) before any assignment. Reject any object that contains these reserved keys at the schema validation layer rather than relying solely on the key filter.
// FIXED — key blocklist before Object.assign
function safeAssign(target, source) {
const BLOCKED_KEYS = new Set(['__proto__', 'constructor', 'prototype']);
const sanitized = {};
for (const key of Object.keys(source)) {
if (BLOCKED_KEYS.has(key)) continue;
// Also block nested objects whose keys include reserved names
const val = source[key];
if (val !== null && typeof val === 'object' && !Array.isArray(val)) {
sanitized[key] = safeAssign({}, val); // recursive sanitization
} else {
sanitized[key] = val;
}
}
return Object.assign(target, sanitized);
}
app.post('/api/skills/:id/options', (req, res) => {
const defaultOptions = { debug: false, maxTokens: 1000 };
const options = safeAssign({}, Object.assign({}, defaultOptions, {}));
safeAssign(options, req.body.skillOptions); // safe — blocked keys filtered
saveSkillOptions(options);
res.json({ saved: true });
});
INJECTION11-003 — for...in enumeration without hasOwnProperty()
The for...in loop in JavaScript iterates all enumerable properties of an object, including those inherited from its prototype chain. For plain object literals created with {} or new Object(), the prototype chain typically contains only non-enumerable properties from Object.prototype, so for...in over a plain object works safely in practice. The flaw emerges when the user-supplied configuration object is not a plain literal: an attacker can construct an object with an enumerable inherited property by calling Object.create(protoObj) where protoObj contains the injection payload. If the skill runtime deserializes user data through a custom parser (not JSON.parse()) or if a prototype-polluted payload has already set enumerable properties on Object.prototype, then for...in without a hasOwnProperty() guard copies those inherited properties into the application configuration object.
// VULNERABLE — configuration copy loop without hasOwnProperty guard
function applySkillConfig(appConfig, userConfig) {
for (const key in userConfig) {
// No hasOwnProperty check — iterates inherited properties too
appConfig[key] = userConfig[key]; // <-- copies prototype-chain properties
}
return appConfig;
}
// If Object.prototype has been polluted earlier in the request pipeline:
// Object.prototype.injectedKey = 'malicious';
// Then: for...in on ANY plain object yields 'injectedKey'
// applySkillConfig copies it into appConfig unconditionally
// Also exploitable without prior pollution — attacker supplies a custom object:
// const malicious = Object.create({ adminOverride: true });
// applySkillConfig({}, malicious); // copies adminOverride from prototype
Chain of consequences: INJECTION11-003 is particularly dangerous as a second-stage vulnerability. If any earlier request handler used lodash.merge() or similar without sanitization (INJECTION11-001), Object.prototype may already be polluted. Every subsequent for...in loop in the same process then copies the pollution forward into new configuration objects, amplifying the initial attack across all subsequent request handling code.
Two fixes are equally correct. The first adds a hasOwnProperty() guard inside the loop — use Object.prototype.hasOwnProperty.call(userConfig, key) rather than userConfig.hasOwnProperty(key) because the hasOwnProperty method itself can be overridden on user-supplied objects. The second replaces for...in entirely with Object.keys(), which returns only own enumerable string keys and never includes prototype chain properties.
// FIXED — option A: hasOwnProperty guard
function applySkillConfigSafe(appConfig, userConfig) {
for (const key in userConfig) {
// Use Object.prototype.hasOwnProperty.call() — not userConfig.hasOwnProperty()
// in case attacker has overridden hasOwnProperty on the object itself
if (Object.prototype.hasOwnProperty.call(userConfig, key)) {
appConfig[key] = userConfig[key];
}
}
return appConfig;
}
// FIXED — option B: Object.keys() (preferred — simpler, no prototype traversal)
function applySkillConfigSafeV2(appConfig, userConfig) {
for (const key of Object.keys(userConfig)) {
// Object.keys() only returns own enumerable string keys
// prototype chain is never visited regardless of pollution state
appConfig[key] = userConfig[key];
}
return appConfig;
}
Detection: SkillAudit's AST-based scanner flags every for (... in ...) loop body where the right-hand side may be a user-controlled object and the loop body does not contain an Object.prototype.hasOwnProperty.call( guard on the same variable. The finding is reported as INJECTION11-003 HIGH. The scanner also suggests automated remediation: replace the for...in pattern with an Object.keys().forEach() equivalent.
INJECTION11-004 — Ajv schema validation does not prevent prototype pollution by default
Developers commonly add Ajv JSON schema validation as a first-line defense against malformed skill configuration input, expecting that strict schema enforcement will prevent prototype pollution. The flaw is that JSON Schema — and Ajv implementing it — treats __proto__ as an ordinary string key. An additionalProperties: false constraint rejects keys that are not listed in properties, but if the schema includes __proto__ in properties (even accidentally by being too permissive), or if the schema uses a broad pattern that matches any string key, the validation passes. The validated payload is then passed to a merge function that processes __proto__ as a prototype-writing operation rather than an ordinary property assignment. Ajv v8 introduced a breaking change that rejects __proto__ keys by default; versions prior to v8 do not.
// VULNERABLE — Ajv pre-v8 validation followed by Object.assign merge
const Ajv = require('ajv'); // version 6.x or 7.x
const ajv = new Ajv();
const skillConfigSchema = {
type: 'object',
properties: {
timeout: { type: 'number' },
retries: { type: 'number' },
logLevel: { type: 'string' }
},
additionalProperties: false // <-- looks strict, but doesn't block __proto__ in Ajv <v8
};
app.post('/api/skills/:id/config', (req, res) => {
const valid = ajv.validate(skillConfigSchema, req.body.config);
if (!valid) return res.status(400).json({ errors: ajv.errors });
// Ajv <v8: payload { "__proto__": { "isAdmin": true } } passes validation
// because __proto__ is not a listed property AND additionalProperties: false
// is applied only after the schema's own properties are checked.
// The validation result is true — the check passes.
const merged = Object.assign({}, defaultConfig, req.body.config);
// Object.prototype is now polluted
res.json({ saved: true });
});
Trust boundary confusion: Validation passing creates a false sense of security. Code that runs after ajv.validate() returns true treats the data as safe, skipping further sanitization. The assumption that "Ajv validated it, so it cannot be dangerous" is incorrect for prototype pollution in Ajv versions before v8. The gap between JSON Schema semantics (treats __proto__ as a plain key) and JavaScript object semantics (treats __proto__ as a prototype setter) is exactly where the attack lives.
Three complementary fixes apply here. First, upgrade to Ajv v8, which rejects __proto__ keys by default. Second, add an explicit propertyNames constraint to the schema that rejects the dangerous key names regardless of Ajv version — this provides defense-in-depth even if the application is later downgraded or the Ajv version is not controlled. Third, apply the JSON.parse(JSON.stringify()) sanitization from INJECTION11-001 after validation and before merge.
// FIXED — Ajv v8 + propertyNames constraint + sanitization
const Ajv = require('ajv'); // version 8.x
const ajv = new Ajv();
const skillConfigSchema = {
type: 'object',
properties: {
timeout: { type: 'number', minimum: 100, maximum: 30000 },
retries: { type: 'number', minimum: 0, maximum: 5 },
logLevel: { type: 'string', enum: ['debug', 'info', 'warn', 'error'] }
},
additionalProperties: false,
// Explicit propertyNames constraint — works in Ajv v6/v7/v8 as defense-in-depth
propertyNames: {
not: {
enum: ['__proto__', 'constructor', 'prototype']
}
}
};
app.post('/api/skills/:id/config', (req, res) => {
const valid = ajv.validate(skillConfigSchema, req.body.config);
if (!valid) return res.status(400).json({ errors: ajv.errors });
// Additional sanitization — independent layer, does not rely solely on Ajv
const sanitized = JSON.parse(JSON.stringify(req.body.config));
const merged = Object.assign({}, defaultConfig, sanitized);
res.json({ saved: true });
});
Detection summary
| Finding | Severity | Trigger | Fix |
|---|---|---|---|
| INJECTION11-001 | CRITICAL | lodash.merge() with user object |
JSON.parse(JSON.stringify()) + structuredClone() |
| INJECTION11-002 | CRITICAL | Object.assign() with nested user input |
Key blocklist + schema validation |
| INJECTION11-003 | HIGH | for...in without hasOwnProperty |
Object.keys() or hasOwnProperty guard |
| INJECTION11-004 | HIGH | Ajv pre-v8 additionalProperties |
Upgrade to v8 + propertyNames constraint |
SkillAudit's static analysis engine detects all four INJECTION11 patterns on every skill submission. Deep-merge calls with unsanitized user objects trigger CRITICAL findings; for...in loops without hasOwnProperty guards trigger HIGH findings with automated fix suggestions. See also SA-SKL-INJECTION10 for dynamic require() and module-loading code injection vulnerabilities in MCP skill runtimes, and SA-SKL-UPLOAD13 for path traversal and symlink attacks that can overwrite the same skill configuration files that prototype pollution targets.