Input validation: what your app should check before it trusts a form or API request
Review expected input types, formats, sizes and server-side checks before an app trusts form fields or API requests.
Every form field, API parameter and uploaded file is data from outside your system. OWASP's Input Validation Cheat Sheet (https://cheatsheetseries.owasp.org/cheatsheets/Input_Validation_Cheat_Sheet.html) defines input validation as checking whether data meets the application's requirements before the application uses it. It reduces the risk of malformed data, invalid business operations and excessive resource consumption.
Validation is not the only defence
OWASP is explicit that validation sits alongside other controls: parameterized queries for SQL, context-aware output encoding for cross-site scripting (XSS), and separate authorization checks. A valid account identifier does not mean the caller may access that account.
Check syntax and meaning
Syntax is the expected type and format; semantics is whether the value makes sense for the operation. OWASP's example: a booking needs valid dates and an end date after its start date. It suggests rules per field: fixed choices must match an allowed set (including values from drop-down menus), numbers and dates need type, format and min/max, strings need length limits and structure, objects need allowed and required fields, and arrays need item-count limits with every item validated.
Allowlist, not denylist
OWASP says to define what is accepted and reject the rest, not to try to recognise every malicious string. Its example: blocking apostrophes rejects legitimate names without making a database query safe. For free-form comments, an allowlist can permit broad Unicode text with a length limit.
Practical points from the cheat sheet
- Limit size before parsing. Apply request size limits and parser limits such as nesting depth before buffering or parsing, since a check after parsing cannot protect a parser that has already run out of resources.
- A type is not a quantity. Converting text to an integer only establishes a type; it does not establish an acceptable amount.
- Structured data. Use schema validators. For JSON, configure required and additional properties explicitly: listing a property alone neither requires it nor rejects unknown fields.
- Reject, do not repair. Reject invalid requests with a clear error rather than continuing with partly validated data, and bind only intended fields to application objects.
- Regular expressions. Use them for simple structured fields, require a match of the entire value, bound the input length first, and avoid patterns with excessive backtracking.
- User-written HTML. Use a maintained sanitization library; validation and regex cannot replace it.
- Uploads. Treat filename and content type as untrusted; an allowed extension alone does not make the content safe.
- Email addresses. Format validation does not prove the person can read that mailbox.
Common pitfalls OWASP lists
Client-only checks (browser checks are bypassable; validate on the server), trusting internal sources such as partner feeds or queues, "cleaning" input by removing characters, stopping at the outer fields of nested data, assuming regex or Unicode normalization makes data safe, trusting upload metadata, and logging rejected input verbatim.
Questions for your developer
- Is every field validated on the server, with explicit length, range and allowed values?
- Do we reject unknown fields and oversized requests early?
- Are SQL queries parameterized, and is output encoded, independent of validation?
- How do we handle uploads and user-supplied HTML?
Limits
We did not read the linked cheat sheets on file upload, deserialization, mass assignment or email verification. This is an overview, not a security review.
By Omnistu.