← API Security learning pathAPI Security · Module 4 of 8
Input validation and safe data handling
Treat every input as untrusted.
📖 Key ideas
- Validate every input on the server against a schema: type, length, format and allowed values.
- Use parameterised queries or a trusted ORM so input is never joined into SQL or commands.
- Limit request size, array length and file uploads (type, size and storage location).
- Encode output for its context, such as HTML, to prevent stored script attacks in clients.
- Return only the fields a client needs; never send password hashes or internal flags.
💡 Real-life example: Validating input is like a bank teller checking a cheque's date, amount and signature before paying: they do not just trust whatever is written.
Schema validationChecking input against defined rules
Parameterised queryQuery with data passed separately from the command
Output encodingConverting data so it is shown, not executed
Excessive data exposureReturning more fields than the client needs