How to fix: API Endpoint Missing Input Validation
An API endpoint appears to process request body data without schema validation. AI-generated API handlers commonly skip input validation, trusting that clients will send well-formed data.
Why it matters
Without input validation, attackers can send malformed data that causes type errors, crashes, database constraint violations, or logic bypasses. Negative numbers, empty strings, excessively long inputs, and unexpected types are common attack vectors.
AI tools generate clean-path code that works for valid input. Adversarial inputs (negative price, 10000-character name, null where object expected) are not handled, leading to crashes or unexpected behavior that can be exploited.
How to fix it
- 1Validate all request inputs with a schema library: zod, joi, yup, or typebox.
- 2Reject unknown fields (strip extra properties or error on them).
- 3Enforce length limits, type constraints, and business rules at the API boundary.
- 4Return 400 Bad Request with a structured error for invalid input, never 500.
Code examples
Zod validation for POST endpoint
import { z } from 'zod';
const CreateItemSchema = z.object({
name: z.string().min(1).max(200).trim(),
price: z.number().positive().finite(),
quantity: z.number().int().min(0).max(10000),
});
export async function POST(req: Request) {
const result = CreateItemSchema.safeParse(await req.json());
if (!result.success) {
return Response.json({ error: result.error.flatten() }, { status: 400 });
}
const { name, price, quantity } = result.data;
// ... proceed with validated data
}References
Detected automatically by VulnRadar. The check id is vibe-no-input-validation, stable across every scan so you can filter or diff on it.
More ai code checks
- LowGeneric Error Messages Leak No Context
- MediumTODO/FIXME Security Note in Response
- Higheval() Usage in Page Scripts
- HighSSL Certificate Verification Disabled
- HighMath.random() Used for Security Tokens
- CriticalHardcoded Credential in Authentication Logic
- CriticalJWT 'none' Algorithm Accepted
- CriticalSQL String Concatenation Pattern Detected
Questions
- How severe is API Endpoint Missing Input Validation?
- 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-no-input-validation, which stays the same between runs so you can filter, diff, or gate CI on it.
- Which standards does API Endpoint Missing Input Validation map to?
- It maps to CWE-20. In the OWASP Top 10 it falls under A03: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.