SAASMENT

Security skill · Find and fix

Input validation and deserialization review.

Review how an application validates untrusted input and deserializes data (JSON, XML, YAML, form data, uploads, archives, binary object formats), checking schema validation at trust boundaries, size and depth limits, type confusion, unsafe object construction, XML entity handling, and file and archive parsing, then fix and verify with hostile-input tests. Use when auditing parsers, upload handlers, import features, message consumers, or any code that turns external bytes into objects.

Download .zipInstall via MCPFind and fixMIT
  • Code review

Facts

Category
Find and fix
License
MIT
Tags
  • Code review
Version
1.0.0
Last updated
2026-12-02
Folder
input-validation-deserialization-review/
MCP resource
skill://input-validation-deserialization-review/SKILL.md
Files
  • SKILL.md
  • LICENSE
  • references/format-checks.md
Standards

Original Saasment content. Saasment is in early access; this skill does not require joining it.

Install via MCP or as files

Connect your client to https://www.saasment.com/api/mcp (see client setup) and call get_skill:

{
  "name": "get_skill",
  "arguments": {
    "slug": "input-validation-deserialization-review"
  }
}

Or download the .zip and unpack it into your agent's skills directory:

Terminal, from your project root (user-level: ~/.cursor/skills)

mkdir -p .cursor/skills
curl -fsSL https://www.saasment.com/ai-security/skills/input-validation-deserialization-review/download.zip -o /tmp/input-validation-deserialization-review.zip
unzip -o /tmp/input-validation-deserialization-review.zip -d .cursor/skills
# result: .cursor/skills/input-validation-deserialization-review/SKILL.md

Review SKILL.md before enabling a skill. Skills are instructions your agent will follow.

SKILL.md

---
name: input-validation-deserialization-review
description: Review how an application validates untrusted input and deserializes data (JSON, XML, YAML, form data, uploads, archives, binary object formats), checking schema validation at trust boundaries, size and depth limits, type confusion, unsafe object construction, XML entity handling, and file and archive parsing, then fix and verify with hostile-input tests. Use when auditing parsers, upload handlers, import features, message consumers, or any code that turns external bytes into objects.
license: MIT
metadata:
  author: Saasment
  version: "1.0.0"
  category: both
  tags: "code-review"
---

# Input validation and deserialization review (find and fix)

License: MIT. Copyright (c) 2026 Saasment. Source: https://www.saasment.com/ai-security/skills/input-validation-deserialization-review

Input validation answers "is this value acceptable here?". Deserialization answers "what does the program build from these bytes?". Bugs appear when the answers are skipped or too generous: a number where a string was expected, a nested document a million levels deep, an archive that writes outside its folder, an XML file that pulls in local files, or a binary format that lets the sender pick which classes to instantiate. This skill reviews both and puts the checks at the trust boundary.

## When to use

- You audit API handlers, webhook receivers, message consumers, importers, upload features, or configuration loaders.
- A pull request adds a new parser, a new accepted file type, or a new serialization format.
- A static analysis tool flagged deserialization, XML, or archive handling.

## Safe by default

- Review only code and systems you own or are authorized to test. Use synthetic test files and a local or test environment.
- Never deserialize a file you did not create to "see what happens" with a format that can run code (native object serialization, pickle-style formats, some YAML modes). Trace the code instead, or use a disposable sandbox with no network and no secrets.
- Keep probe inputs harmless: large-but-bounded sizes, a marker string, a temporary directory. Do not send decompression bombs or recursive payloads to shared or production systems.
- Do not weaken a validator to make a test pass. Fix the test data.

## Procedure

1. **List trust boundaries.** Find every place bytes or strings from outside enter: request bodies, query strings, headers, cookies, uploaded files, archive members, queue messages, database fields written by other systems, third-party API responses, and model output. For each, note the format and the code that parses it.
2. **Check validation at the boundary.** Each boundary parses into a typed structure with a schema that states required fields, types, ranges, lengths, formats, and allowed values. Unknown fields are rejected or dropped. Validation happens on the server regardless of client checks. Prefer allowlists to blocklists. Patterns by format are in `references/format-checks.md`.
3. **Check limits.** Maximum body size, string length, array length, nesting depth, number of fields, number of archive entries, uncompressed size, and parse time. Limits are enforced before the data is fully read or expanded.
4. **Check type and encoding handling.** Arrays versus strings, numbers versus numeric strings, null, booleans, very large or negative numbers, Unicode normalization and lookalike characters in identifiers, and duplicate keys (parsers disagree on which wins).
5. **Check object construction.** Formats that name classes or types (native object serialization, pickle-style, polymorphic JSON or YAML with type tags, XML decoders) must not let the sender choose arbitrary types. Prefer data-only formats mapped to fixed classes. If native serialization must stay, use an allowlist of permitted classes and sign or encrypt the payload with a key the attacker does not have (see `crypto-misuse-review`).
6. **Check XML.** DTDs and external entities disabled, entity expansion limited, XInclude off, and XSLT or schema loading from user-provided locations blocked.
7. **Check files and archives.** Size and count limits, content-type verified by content and not only by name or header, stored under a generated name outside the web root, entry names with `..`, absolute paths, and links rejected during extraction, and files served with a safe content type and download disposition.
8. **Check where validated data goes next.** Validation does not replace output handling: parameterize queries, encode output for its context, and validate again if the data crosses another trust boundary (see `sql-injection-find-and-fix`, `xss-find-and-fix`, `ssrf-find-and-fix`).
9. **Fix.** Add a schema at each boundary, enforce limits in the framework or reverse proxy as well as in code, switch risky formats, harden parsers, and add tests for each fix.

## Verification

- Confirm missing validation with a test request containing a wrong type, an extra field, an empty value, an oversized value, and a nested structure beyond the limit; each should fail with a 4xx response and no stack trace. Before the fix, at least one is accepted or causes a 5xx error.
- Confirm size and depth limits by sending bounded oversized input to a local server and asserting rejection without high memory use.
- Confirm XML hardening with a harmless test document that declares an external entity pointing at a temporary file you created; assert the content does not appear in the output.
- Confirm archive handling with a test archive whose member name is `../outside.txt` built in a temporary directory; assert extraction refuses it and no file appears outside the target.
- Confirm deserialization allowlists with a harmless test class that is not on the list; assert it is rejected.
- Confirm duplicate-key and type-confusion cases by asserting the same result from every layer that parses the data (proxy, validator, application).

## Reporting

Table: id, boundary, format, what was missing (schema, limit, type check, constructor control), reachable by whom, fix, test. List boundaries you could not review.

## References

- OWASP Input Validation Cheat Sheet: https://cheatsheetseries.owasp.org/cheatsheets/Input_Validation_Cheat_Sheet.html
- OWASP Deserialization Cheat Sheet: https://cheatsheetseries.owasp.org/cheatsheets/Deserialization_Cheat_Sheet.html
- OWASP File Upload Cheat Sheet: https://cheatsheetseries.owasp.org/cheatsheets/File_Upload_Cheat_Sheet.html
- OWASP XML External Entity Prevention Cheat Sheet: https://cheatsheetseries.owasp.org/cheatsheets/XML_External_Entity_Prevention_Cheat_Sheet.html
- CWE-502 (deserialization of untrusted data): https://cwe.mitre.org/data/definitions/502.html
- Companion skills: `secure-code-review-checklist`, `sql-injection-find-and-fix`, `insecure-output-handling-review`.

Helper files

LICENSE
MIT License

Copyright (c) 2026 Saasment

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
references/format-checks.md
# Checks by data format

License: MIT. Copyright (c) 2026 Saasment.

## Quick decision table

| Format | Main risks | Controls to look for |
| --- | --- | --- |
| JSON | Wrong types, extra fields, huge or deeply nested bodies, duplicate keys, prototype-style keys in JavaScript | Schema validation, body size limit, depth limit, reject unknown fields, explicit mapping into fixed classes |
| Form data and query strings | Arrays instead of strings, repeated parameters, mass assignment | Parse into a typed structure, allowlist fields, take the first or last value on purpose |
| XML | External entities, entity expansion, XInclude, remote schema loading | DTDs disabled, secure-processing mode, no network access for the parser |
| YAML | Arbitrary object construction in unsafe modes, anchors that expand | Safe loader only, size limit, prefer JSON for untrusted input |
| Native object serialization (Java, pickle-style, others) | Sender chooses classes to build, leading to code execution | Do not accept from untrusted sources; allowlist classes; sign the payload |
| Protocol buffers and similar binary schemas | Missing required fields, unexpected enum values, large messages | Validate after decode, size limits, treat unknown enum values explicitly |
| CSV and spreadsheets | Formula injection when exported to spreadsheet tools, huge files | Prefix risky leading characters on export, row and size limits |
| Archives (zip, tar) | Path traversal, links, huge expansion, many entries | Check each member name, reject links, cap entry count and total size |
| Images and documents | Parser bugs, huge dimensions, embedded active content | Re-encode images, limit dimensions, scan, serve from a separate origin |
| URLs and hostnames | Redirects, internal addresses, scheme confusion | Parse with a standard parser, allowlist scheme and host (see the SSRF skill) |
| Dates, numbers, identifiers | Overflow, negative values, locale surprises, lookalike characters | Range checks, fixed formats, normalize before comparing |

## Schema example (any schema library works)

```text
CreateInvoice {
  customerId: string, uuid format, required
  amountCents: integer, 1 to 10000000, required
  currency: one of ["USD", "EUR", "GBP"], required
  note: string, max 500 characters, optional
  (no other fields allowed)
}
```

Reject on the first violation with a generic 400 message that does not echo the input.

## Archive extraction pattern (language neutral)

1. Resolve the destination directory to an absolute path.
2. For each entry: reject it if it is a symlink, hard link, device, or absolute path.
3. Join the entry name to the destination and resolve the result.
4. Reject the entry if the resolved path is not inside the destination directory.
5. Track the running total of bytes written and the entry count; stop at the limits.
6. Write with restrictive permissions and a generated file name if the original name is not needed.

## Hostile-input test list

Run each against every boundary you fixed, using a local or test deployment.

- Empty body, empty string, whitespace only
- Wrong type: array where a string is expected, object where a number is expected, number as string
- Extra and duplicate fields
- Very long string, very large number, negative number, zero
- Nesting beyond the depth limit
- Unicode lookalikes and mixed normalization forms in identifiers
- Request body larger than the limit, with and without a truthful length header
- Archive with `../` entry name; XML with a harmless declared entity pointing at a file you created

Related

Companion skills

Questions

How do I install the Input validation and deserialization review skill?

Download https://www.saasment.com/ai-security/skills/input-validation-deserialization-review/download.zip and unzip it into your agent's skills directory (for example .cursor/skills, .claude/skills, .agents/skills, or .github/skills) so that input-validation-deserialization-review/SKILL.md exists. Or connect to https://www.saasment.com/api/mcp and call the get_skill tool with the slug input-validation-deserialization-review.

What license is the Input validation and deserialization review skill under?

It is original Saasment content under the MIT license, stated in the SKILL.md frontmatter and in the LICENSE file in the skill folder.

Is it safe to run this skill?

A skill is a set of instructions your agent follows, so read SKILL.md first. It tells the agent to test only systems you own or are authorized to test, to use test environments and synthetic data, and to avoid destructive probes. Downloading it does not run any code on your machine.

← All security skills

Try the platform.

Open the demo workspace with mock data. No login. Register from the banner when you want early access. No security team. No call.

Try the platform