Skip to main content
interlace
Plugin: secure-codingRules

no-unsafe-deserialization

Detects unsafe deserialization of untrusted data

CWE: CWE-693
OWASP Mobile: OWASP Mobile Top 10

Detects unsafe deserialization of untrusted data. This rule is part of eslint-plugin-secure-coding.

πŸ’Ό This rule is set to error in the recommended config.

Quick Summary

AspectDetails
CWE ReferenceCWE-502 (Unsafe Deserialization)
SeverityCritical (CVSS 9.8)
Auto-FixπŸ’‘ Suggestions available
CategorySecurity

Value & investment case

Why this rule pays for itself. Framework: cicd-impact/philosophy.md.

DimensionValue
CWECWE-502 β€” Deserialization of Untrusted Data (CVSS 9.8 β€” Critical)
Feedback-loop tierEditor / pre-commit (sub-second) β€” cheapest layer per the feedback-loop hierarchy
Defensive-layer leverage~10Γ— cheaper than unit-test Β· ~1,000Γ— cheaper than production rollback Β· 10,000+Γ— cheaper than disclosure β€” RCE-class vulnerability sits at the highest tier of the cost-ratio table (cost-ratio anchors)
Niche relevanceCritical: fintech, cybersecurity, infra/devtools (downstream RCE blast radius) Β· High: B2B SaaS, healthtech Β· Medium: B2C, marketplaces
Investor-frame impactInsecure deserialization β†’ Remote Code Execution (CVSS 9.8). One incident = full system compromise β†’ mandatory disclosure β†’ audit cycle restart β†’ customer trust event. The single highest-leverage rule by counterfactual-value math: the catch costs ~$0; the unprevented bug costs the company.

Read also: philosophy.md Β§investor-frame Β· niche-presets.json Β· analyzer-evaluation-framework.md

Vulnerability and Risk

Vulnerability: Unsafe deserialization happens when an application accepts serialized objects from untrusted sources and deserializes them without validation.

Risk: Serialized data can contain malicious payloads that, upon deserialization, execute arbitrary code (Remote Code Execution - RCE), modify application logic, or cause Denial of Service (DoS). This is often considered one of the most critical security risks.

Rule Details

Unsafe deserialization occurs when untrusted data is deserialized in a way that allows attackers to execute arbitrary code or manipulate application logic. This includes:

  • Using eval() or Function() on untrusted data
  • YAML parsers that execute code
  • JSON with prototype pollution
  • Insecure serialization libraries

What is NOT reported

Two exclusions were added in 2026-07 after a 1,470-file corpus run (webpack, lodash, eslint-plugin-import, two NestJS boilerplates) produced 35 findings, all of them false, all at CVSS 9.8 CRITICAL:

  • setTimeout / setInterval with a non-string first argument. These are a code-execution sink only in their implied-eval form. setTimeout(cb, 1000) is a scheduler. The rule previously reported await new Promise(resolve => setTimeout(resolve, 1000)) β€” an ordinary sleep β€” because setTimeout is on the dangerous-function list and resolve is an enclosing arrow-function parameter. setTimeout("alert(" + userCode + ")", 100) still reports.
  • Calls inside a deserializer implementation. super.deserialize(context), this.deserialize(context), and any x.deserialize(…) sitting inside a function named deserialize / unserialize / fromJSON / fromBuffer. That is a class implementing a (de)serialization protocol and chaining to the next layer of it β€” webpack's static deserialize(context) factories account for 33 of the 35 findings. A rule that cannot see the protocol cannot judge it.

Why This Matters

IssueImpactSolution
πŸ’» RCEFull system compromiseUse safe deserializers
🎭 Object ManipulationLogic bypassValidate before deserializing
πŸ”“ Auth BypassUnauthorized accessUse JSON.parse() for JSON data

Examples

❌ Incorrect

const func = new Function(req.body.input);

βœ… Correct

// Use JSON.parse() for JSON data
const data = JSON.parse(userInput);

// YAML with safeLoad
import yaml from 'js-yaml';
const config = yaml.safeLoad(userYaml);
// Or with explicit safe schema
const config = yaml.load(userYaml, { schema: yaml.SAFE_SCHEMA });

// Validate before deserialization
if (isValidJson(userInput)) {
  const data = JSON.parse(userInput);
}

// Use safe serialization libraries
import { safeDeserialize } from 'safe-serialize';
const obj = safeDeserialize(userInput);

Configuration

{
  rules: {
    'secure-coding/no-unsafe-deserialization': ['error', {
      dangerousFunctions: ['eval', 'Function', 'serialize.unserialize'],
      safeLibraries: ['safe-serialize', 'json5'],
      validationFunctions: ['isValidJson', 'validateInput']
    }]
  }
}

Options

OptionTypeDefaultDescription
dangerousFunctionsstring[]["eval","Function","setTimeout","setInterval","unserialize","deserialize","parseUnsafe"]Functions that execute or deserialize untrusted input
safeLibrariesstring[]["JSON","safe-json-parse","js-yaml.safeLoad","protobuf","msgpack"]Parsers that do not execute their input
validationFunctionsstring[]["validateInput","sanitizeData","checkSchema","validateSchema"]Function names that count as input validation
trustedSanitizersstring[][]Additional function names to consider as safe deserializers
trustedAnnotationsstring[][]Additional JSDoc annotations to consider as safe markers
strictModebooleanfalseDisable all false positive detection (strict mode)

Error Message Format

The rule provides LLM-optimized error messages (Compact 2-line format) with actionable security guidance:

πŸ”’ CWE-502 OWASP:A08 CVSS:9.8 | Deserialization of Untrusted Data detected | CRITICAL
   Fix: Review and apply the recommended fix | https://owasp.org/Top10/A08_2021/

Message Components

ComponentPurposeExample
Risk StandardsSecurity benchmarksCWE-502 OWASP:A08 CVSS:9.8
Issue DescriptionSpecific vulnerabilityDeserialization of Untrusted Data detected
Severity & ComplianceImpact assessmentCRITICAL
Fix InstructionActionable remediationFollow the remediation steps below
Technical TruthOfficial referenceOWASP Top 10

Known False Negatives

The following patterns are not detected due to static analysis limitations:

Values from Variables

Why: Values stored in variables are not traced.

// ❌ NOT DETECTED - Value from variable
const value = userInput;
dangerousOperation(value);

Mitigation: Validate all user inputs.

Wrapper Functions

Why: Custom wrappers not recognized.

// ❌ NOT DETECTED - Wrapper
myWrapper(userInput); // Uses dangerous API internally

Mitigation: Apply rule to wrapper implementations.

Dynamic Invocation

Why: Dynamic calls not analyzed.

// ❌ NOT DETECTED - Dynamic
obj[method](userInput);

Mitigation: Avoid dynamic method invocation.

Further Reading

Did this rule catch something? Star the repo to get new CWE coverage as we ship it β€” or follow the AI-code-security benchmarks behind these rules.