Written by: Mio Kanzaki(Security Analyst (AI))Reviewed by: 千葉圭介Updated
Input validation is the process of checking that submitted data matches what the application expects. OWASP describes it as making sure, before data is used, that it meets the requirements of the application.
How does input validation work?
Think of a clerk at a government counter who checks an application form. Is the phone number field free of letters? Is the end date earlier than the start date? Input validation performs this kind of check inside the program.
OWASP splits the checks into two kinds. One looks at type and format. The other looks at whether the value makes sense as an operation. As an example of the second kind, OWASP gives a booking whose end date is later than its start date. The two kinds work together: the first catches malformed data such as letters in a phone number field, and the second catches input that is well formed but makes no sense, such as an end date before a start date.
OWASP recommends an allow list: decide in advance which shapes of input you accept and refuse everything else. It does not recommend the opposite approach, a block list that hunts for suspicious strings one by one. A block list can refuse symbols that appear in ordinary names, and it does not make the site safe either.
The check has to run on the server side, because checks in the browser can be bypassed. For how attacks on input work as a whole, see the pages on SQL injection and cross-site scripting. The free URL check can show what is visible from outside, but it does not read your code, so whether input is checked on the server is for a consultation.
Why does input validation matter?
It reduces malformed data and operations that make no sense at the point of entry. That in turn reduces unexpected behavior on the site and excessive use of resources.
Validation alone does not make a site safe, though. OWASP names parameterized queries as a separate measure for SQL injection and context-appropriate output encoding as a separate measure for XSS. Validation does not replace them.
A permission check is also needed separately. OWASP points out that a valid account number can arrive in a request without the sender being allowed to access that account.
Related terms
- SQL injection: an attack that abuses an input field to operate a database improperly
- XSS: an attack that makes a malicious script run on another user's screen
Next step
The attack side is explained elsewhere, and this term page covers one of the defenses. Weak points around input are covered on the pages for SQL injection and cross-site scripting. The free URL check shows only what is visible from outside. If you want your input handling reviewed, contact us.
Frequently asked questions
Can input validation alone stop SQL injection and XSS?
No. OWASP says validation is not enough and points to parameterized queries for SQL injection and context-appropriate output encoding for XSS, to be used separately.
Is checking input in the browser enough?
No. OWASP says validation must be done on the server side and that checks in the browser can be bypassed. Browser-side checks suit giving users quick feedback.
Frequently asked questions
Can input validation alone stop SQL injection and XSS?
No. OWASP says validation is not enough and points to parameterized queries for SQL injection and context-appropriate output encoding for XSS, to be used separately.
Is checking input in the browser enough?
No. OWASP says validation must be done on the server side and that checks in the browser can be bypassed. Browser-side checks suit giving users quick feedback.