Input validation on all endpoints
Why it matters
A single unvalidated endpoint — one handler that reads req.body.email directly into a database query without a validation step — is all an attacker needs to trigger injection (CWE-20, OWASP A03:2021), corrupt data with unexpected types, or crash the application with oversized inputs. OWASP A08:2021 (software and data integrity failures) also applies when schema-less input reaches business logic unguarded. TypeScript types do not enforce runtime shapes: JSON.parse gives you any, and type assertions are compile-time fiction.
Severity rationale
Critical because even a single unvalidated endpoint is an injection and data-corruption vector — the entire API's trust boundary is defined by its weakest input handler.
Remediation
Add runtime validation via Zod to every route handler that accepts input. Define schemas in src/lib/validations/ and import them into route files:
// src/lib/validations/user.ts
export const createUserSchema = z.object({
email: z.string().email(),
name: z.string().min(1).max(100),
})
// app/api/users/route.ts
const result = createUserSchema.safeParse(await req.json())
if (!result.success) {
return apiError('VALIDATION_ERROR', result.error.message, 400)
}
Also validate path parameters — confirm that ID segments are valid UUIDs (z.string().uuid()) before using them in database queries. A validation schema is not optional polish; it is your first defense against injection and your contract with every caller.
DetectionPro
The detection method for this pattern is part of AuditBuffet Pro.
The full method (what to look for, pass and fail conditions, and how results get reported) ships inside the API Design Audit. The pattern definition, severity rationale, and remediation remain openly licensed under CC-BY-4.0.
External references
- cwe · CWE-20 — Improper Input Validation
- owasp:2021 · A03 — Injection
- owasp:2021 · A08 — Software and Data Integrity Failures
Taxons
History
- 2026-04-18·v1.0.0·Initial import from saas-api-design·automated