input-validation
Skill26 starsChanged 6 months agoMITView on GitHub
Use when an endpoint, Server Action, route handler, form handler, or webhook receiver accepts a request body, query param, search param, header, or form data. Catches unvalidated `req.body`, missing schema parsing, type-cast assumptions, dates as strings, and trust-boundary holes.
10 other projects use a version of this.
Adopted by
Most recently taken up by
- Wade-DevCode/awesome-coding-skills-cntheir own version, first seen Nov 8, 2026
- Sagargupta16/agent-recipestheir own version, first seen Nov 1, 2026
- drvoss/everything-copilot-clitheir own version, first seen Oct 26, 2026
- jars-demo/jars-skillstheir own version, first seen Oct 25, 2026
- Jinbae10/skillstheir own version, first seen Jul 7, 2026
- kimtth/agent-skill-100-lines-or-lesstheir own version, first seen Jun 26, 2026
Used with
Projects with it also use rate-limiting and refactor.
Other files people use alongside this one.
Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
harperaaSkillrate-limiting
Implement rate limiting to prevent brute force attacks, spam, and resource abuse. Use this skill when you need to protect endpoints from automated attacks, prevent API abuse, limit request frequency, or control infrastructure costs. Triggers include "rate limiting", "rate limit", "brute force", "prevent spam", "API abuse", "resource exhaustion", "DoS", "withRateLimit", "too many requests", "429 error".
Also in 3 projects that use this
GitHubSkillrefactor
Surgical code refactoring to improve maintainability without changing behavior. Covers extracting functions, renaming variables, breaking down god functions, improving type safety, eliminating code smells, and applying design patterns. Less drastic than repo-rebuilder; use for gradual improvements.
Also in 3 projects that use this
Other versions10 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 10
- drvoss/everything-copilot-cli★ 48same name
- JeremyMorgan/code-review-skills★ 15same name
- YepAPI/skills★ 8same name
- Wade-DevCode/awesome-coding-skills-cn★ 7same name
- Sagargupta16/agent-recipes★ 4same name
- kimtth/agent-skill-100-lines-or-less★ 2same name
- OpenOps-Studio/vibe-driven-dev★ 1same name
- hereshecodes/secureskills★ 0same name
- jars-demo/jars-skills★ 0same name
- Jinbae10/skills★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository19 other files it gives its agents.
- api-route-hardeningSkill
- auth-and-sessionsSkill
- authorizationSkill
- caching-and-invalidationSkill
- database-query-safetySkill
- data-privacySkill
- error-handlingSkill
- file-uploadsSkill
- jobs-and-queuesSkill
- llm-endpoint-safetySkill
- migrations-and-schemaSkill
- observabilitySkill
- production-readinessSkill
- reliability-patternsSkill
- rsc-boundariesSkill
- secrets-and-envSkill
- testing-strategySkill
- transactions-and-consistencySkill
- webhooksSkill
The file
We split this skill into the rules it gives an agent
2 rules. 0 are common, 1 is distinctive, and 1 is very specific to this project.
0
Common
Most of the 8 edited versions we read keep these.
1
Distinctive
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 58
If the validation lives three function calls down, you'll forget it once and ship a vulnerability.
- Very specific: line 106
Never trust new Date(input) — it accepts garbage and silently produces Invalid Date.
“Common” is measured: kept by at least 6 in 10 of the 8 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Input Validation & Trust Boundaries
A trust boundary is anywhere data crosses from outside your code into it. Parse, don't validate — turn unknown input into a fully-typed value at the boundary, or reject it. Once parsed, the rest of your code can trust the types.
When to use
- Writing a route handler / Server Action that reads
request.json(),formData(), orsearchParams - Receiving a webhook payload
- Parsing query strings, URL params, headers, cookies for anything beyond identity
- Reading data from
localStorage, IndexedDB, URL hash on the client - Consuming a third-party API response (yes, that's a trust boundary too)
When to skip
- Internal function calls between fully-typed code with no external input
- Pure rendering of already-parsed, already-trusted data
Parse, don't validate
The wrong shape:
// BAD — type assertion is a lie. The runtime value can be anything.
const body = (await req.json()) as { email: string; age: number }
await db.user.create({ data: body }) // 💥 if `age` is "twenty-one"The right shape:
import { z } from 'zod'
const CreateUser = z.object({
email: z.string().email().toLowerCase().trim(),
age: z.number().int().min(13).max(120),
})
export async function POST(req: Request) {
const parsed = CreateUser.safeParse(await req.json())
if (!parsed.success) {
return Response.json({ error: 'Invalid input', issues: parsed.error.flatten() }, { status: 400 })
}
// parsed.data is now fully typed AND validated
await db.user.create({ data: parsed.data })
return new Response(null, { status: 201 })
}The schema is the type. The runtime check and the compile-time type are the same object — they cannot drift.
The rules
1. Validate at every trust boundary. Not "deeper in the code."
If the validation lives three function calls down, you'll forget it once and ship a vulnerability. Validate at the boundary — the route handler, Server Action, webhook receiver — and pass typed data inward.
2. Use Zod or Valibot. Not handwritten checks. Not Joi-from-2018.
// BAD — handwritten, leaky, drifts from the type
if (typeof body.email !== 'string' || !body.email.includes('@')) { ... }
// GOOD
z.string().email()Valibot is lighter (better for edge bundles); Zod is more ergonomic. Pick one per project.
3. Whitelist, not blacklist.
Define the shape you accept; reject everything else. Strict mode:
const Body = z.object({
title: z.string().min(1).max(200),
}).strict() // reject unknown keys
// Without strict(): user sends { title, role: 'admin' } and your spread copies role into the DB.strict() (or .passthrough() only with intent) prevents mass assignment — the bug where extra keys in the body get spread into your DB write.
4. Coerce, then validate. Don't trust string→number→string conversions.
Query params and form data are strings. Headers are strings. Coerce explicitly:
const Search = z.object({
page: z.coerce.number().int().min(1).default(1),
limit: z.coerce.number().int().min(1).max(100).default(20),
})
const { page, limit } = Search.parse(Object.fromEntries(searchParams))5. Validate dates as ISO strings, then coerce to Date.
const Body = z.object({
publishAt: z.string().datetime().transform((s) => new Date(s)),
})Never trust new Date(input) — it accepts garbage and silently produces Invalid Date.
6. Headers and cookies are user input.
The Authorization header, User-Agent, Origin, Referer, custom X-* headers — all attacker-controllable. Validate before using.
7. Length limits on every string. Size limits on every array.
z.string().max(10_000) // not unbounded
z.array(z.string()).max(100) // not unbounded
z.string().regex(/^[a-z0-9-]+$/) // slugs etcUnbounded inputs are how you get OOM crashes and request smuggling. See api-route-hardening for body-size limits at the framework level.
8. Never eval, Function, or pass user input to a templating engine without escaping.
Self-explanatory. Same rule applies to building shell commands, child_process.exec, and SQL strings (use parameterization — see database-query-safety).
9. Don't use the parsed shape as the DB shape implicitly.
Validation schema and DB schema overlap but aren't the same. Don't db.user.create({ data: parsed }) and assume — at minimum strip server-controlled fields (id, createdAt, role, isAdmin) from the validation schema, or use pick/omit deliberately.
const PublicUserUpdate = UserSchema.pick({ name: true, bio: true })
// User cannot ever set `role`, `email`, `isAdmin` via this endpoint10. The same rules apply to webhook payloads.
A "Stripe webhook" is bytes from the internet until you've verified the signature and parsed the schema. See webhooks.
Client-side validation is UX, not security
Forms can validate with the same Zod schema (share it between client and server) for nice UX. The server still validates, because anyone can curl past the form.
War story
A vibe-coded note app accepted PATCH /api/notes/:id with (await req.json()) as { content: string }. A user sent { content: "x", userId: "<other-user-id>" }, the server spread the body into a Prisma update, and the note transferred to another account. Took down the entire ownership model. The fix was .strict() and an explicit pick. Cost: hours of data reconciliation across 8k notes.
Quick checklist
- Every endpoint parses input via Zod/Valibot at the boundary
- Schemas use
.strict()(or explicitpick) — no mass assignment - String/array fields have explicit max lengths
- Dates are validated as ISO strings, then coerced
- Query params are coerced explicitly (no
as number) - Server-controlled fields (
id,role,userId) cannot come from request body - Headers / cookies / webhook payloads validated, not trusted
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

