Home/Blog/Cheat Sheets
Cheat Sheets

Cheat Sheet Series – Input Validation

A practical reading of the OWASP Input Validation Cheat Sheet. Accept only the shape you defined, check it on the server, and remember that a valid value is still untrusted when you use it.

Primary source: OWASP Input Validation Cheat Sheet. Pair it with the Query Parameterization Cheat Sheet and the Cross Site Scripting Prevention Cheat Sheet.

Validation decides whether a value is acceptable. Encoding and parameterised queries decide whether it is safe to use.

The check

TopicKey points
Server sideRepeat the check on the server. A check in the browser only helps the person filling in the form.
Allow listAccept known-good values for fixed fields. A list of banned strings is easy to step around.
FormCheck the type, the length and the allowed characters before the value is used.
MeaningA date must be in range, a quantity must be one you can fulfil, and an identifier must belong to this caller.
Free textNormalise Unicode before you compare it. Two strings that look alike can still be different characters.
NumbersParse to a number, then check the range. A numeric string is still text if you join it into a query.
Email and URLCheck the format conservatively. Confirm an email address with a single-use link rather than a clever pattern.
PatternsKeep regular expressions simple. A nested pattern can stall the server on a short input.

Files and use

TopicKey points
File typeAllow-list the types you will keep. Detect the content. Do not trust only the extension the client sent.
File nameRename the file on the server. Never write it using a path the client supplied.
SizeCap the upload and reject an oversized body before you parse it.
StorageKeep uploads where the server will not execute them.
HTMLEncode for the context you render into. Validation does not replace encoding.
QueriesUse parameterised queries. A value that passed validation is still untrusted in SQL.
CommandsDo not build a shell command from the input. If you must call out, pass arguments separately from the command.
Fail closedIf the check or the parser reports an error, reject the input. Do not continue on a warning.

What a test should show

  • A value the browser would block is still blocked when that check is skipped.
  • A well-formed identifier for another customer's record is refused.
  • An upload is renamed, and it is not stored on a path the client chose.
  • HTML responses are encoded, including values that already passed validation.
  • Database calls use parameters.
  • An oversized body is rejected before business logic runs.
#cheat-sheet#input-validation#owasp

Ready to strengthen your security?

Talk to our consultants about your penetration testing requirements, or get a fast, transparent quote.