Deserialization attack prevention
Why it matters
Unsafe deserialization (CWE-502, OWASP A08 Software and Data Integrity Failures) enables remote code execution when attacker-controlled serialized objects are reconstructed by a library that executes code during deserialization. The node-serialize library is the canonical Node.js example: it evaluates immediately-invoked function expressions (IIFEs) embedded in the serialized payload. NIST 800-53 SI-10 requires validation of all input before processing. Unlike JSON.parse (which only creates primitive values and plain objects), unsafe deserialization libraries can reconstruct class instances, triggering constructor side effects defined by the attacker.
Severity rationale
Low because exploiting unsafe deserialization requires a specific vulnerable library to be used on attacker-controlled input, but successful exploitation achieves arbitrary code execution.
Remediation
Replace unsafe deserialization libraries with JSON.parse followed by Zod schema validation. Never call node-serialize.unserialize() on untrusted input:
import { z } from 'zod'
// Unsafe — executes IIFEs in the payload:
// const data = require('node-serialize').unserialize(userInput)
// Safe — only parses JSON primitives, then validates shape:
const DataSchema = z.object({
type: z.enum(['config', 'preferences']),
value: z.number().int().nonnegative(),
})
const parsed = JSON.parse(userInput) // No code execution
const data = DataSchema.parse(parsed) // Throws on invalid shape
Audit package.json for node-serialize, serialize-javascript (when used to deserialize), or qs with allowPrototypes: true — these are the most commonly exploited deserialization vectors in Node.js.
DetectionPro
The detection method for this pattern is part of AuditBuffet Pro.
The full method (what to look for, pass and fail conditions, and how results get reported) ships inside the Security Hardening Audit. The pattern definition, severity rationale, and remediation remain openly licensed under CC-BY-4.0.
External references
- cwe · CWE-502 — Deserialization of Untrusted Data
- owasp:2021 · A08 — Software and Data Integrity Failures
- nist:rev5 · SI-10 — Information Input Validation
- soc2:2017 · CC6.8 — Prevention and detection of unauthorized or malicious software
Taxons
History
- 2026-04-18·v1.0.0·Initial import from security-hardening·automated
- 2026-07-06·v1.0.1·Add SOC 2 TSC mapping (CC6.8) from the verified compliance crosswalk register (docs/compliance/).·by soc2-mapping-enrichment-ship-2