Skip to main content
HighAI codeOWASP A08:2021CWE-502

How to fix: Unsafe Deserialization of User Input

The response body contains patterns of deserializing user-controlled data without schema validation (JSON.parse, eval, node-serialize). Unsafe deserialization is a top OWASP vulnerability class.

Why it matters

Unsafe deserialization can lead to remote code execution, denial of service, or authentication bypass depending on the deserialization library and the shape of attacker-controlled input.

AI-generated code commonly pipes request body directly to JSON.parse without validating the structure, type, or content of the result. When combined with libraries that execute code during deserialization (node-serialize, pickle), this enables RCE.

How to fix it

  1. 1Always validate deserialized data against a schema: zod, joi, or ajv.
  2. 2Never use node-serialize, PHP unserialize, Python pickle on user data.
  3. 3Set type expectations before using: const body = RequestBodySchema.parse(await req.json()).
  4. 4Reject unexpected fields with strict schema validation (no passthrough/unknown keys).

Code examples

Zod schema validation

TypeScript
import { z } from 'zod';

const CreateUserSchema = z.object({
  name: z.string().min(1).max(100),
  email: z.string().email(),
  role: z.enum(['user', 'admin']).optional(),
});

// Safe
const body = CreateUserSchema.parse(await req.json());

References

Detected automatically by VulnRadar. The check id is vibe-insecure-deserialize, stable across every scan so you can filter or diff on it.

See every ai code check

Questions

How severe is Unsafe Deserialization of User Input?
VulnRadar rates this high severity in the ai code category. The severity is fixed per check, not scored per site, so the same finding is the same severity on every scan.
Does VulnRadar check for this automatically?
Yes. It runs as part of every scan under the check id vibe-insecure-deserialize, which stays the same between runs so you can filter, diff, or gate CI on it.
Which standards does Unsafe Deserialization of User Input map to?
It maps to CWE-502. In the OWASP Top 10 it falls under A08:2021.

Missing a check?

The detection set is open. If you know a misconfiguration this does not catch, propose it: the issue template asks for the threat model, how to detect it, the false-positive risk, and a test fixture, which is the same thing a maintainer would have to work out anyway.

Propose a checkHow a check is built

Scan your own site for unsafe deserialization of user input

VulnRadar runs this check and hundreds more against a URL in seconds. No agent to install, just paste a URL.

Or scan this site as a demoRead the docs

How to fix: Unsafe Deserialization of User Input | VulnRadar