Static analysis (SAST) check · TypeScript

Deserialization from request input (TypeScript)

Data from a Next.js request is passed to a deserialiser that can rebuild functions or arbitrary objects.

Why it matters

A crafted payload runs code.

How to fix it

Parse with JSON.parse into a schema-validated type (zod); never node-serialize, serialize-javascript eval, or js-yaml's unsafe schemas on request data.

Example

The rule's own test fixtures, verbatim: the test suite requires the rule to report the first and not the second.

Vulnerable: reported (TypeScript)
import serialize from "node-serialize";

export async function POST(request: Request) {
  const raw = await request.text();
  const state = serialize.unserialize(raw);
  return Response.json(state);
}
Fixed: not reported (TypeScript)
import { z } from "zod";

const State = z.object({ step: z.number() });

export async function POST(request: Request) {
  const raw = await request.text();
  const state = State.parse(JSON.parse(raw));
  return Response.json(state);
}

What TrustIvan reads

Runs on repository scans of TypeScript source once static analysis is turned on (SAST_RULES and the separately built analyzer image); it is off by default.

Weakness classes and references

Terms: SAST (static application security testing), Taint analysis, CWE (Common Weakness Enumeration), OWASP Top 10

All static analysis (SAST) checks · The whole catalogue · How this works in TrustIvan · Documentation

See TrustIvan on your own estate.

Book thirty minutes with an engineer and bring an image, a repository or a cloud account, or start free on the hosted service.