One of the most important security steps that developers should take is to include input validation. If you’re planning on taking the Security+ exam, this post should help in understanding input validation.
For example, can you answer this question?
Q. Which of the following developer techniques results in significant security vulnerabilities for online website applications?
A. Buffer overflow
B. XSRF
C. Poor input validation
D. Hardening
More, do you know why the correct answer is correct and the incorrect answers are incorrect? Answer and explanation at end of this post.
Understanding Input Validation
Input validation is the practice of checking data for validity before using it. Input validation prevents an attacker from sending malicious code that an application will use by either sanitizing the input to remove malicious code or rejecting the input. The lack of input validation is one of the most common security issues on web-based applications. It allows many different types of attacks, such as buffer overflow, SQL injection, command injection, and cross-site scripting attacks.
Consider a web form that includes a text box for a first name. You can logically expect a valid first name to have only letters, and no more than 25 letters. The developer uses input validation techniques to ensure that the name entered by the user meets this validity check. If a user enters other data, such as numbers, semicolons, or Hypertext Markup Language (HTML) code, it fails the validity check. Instead of using the data, the application rejects it and provides an error to the user.
You’ve probably seen input validation checks and error-handling routines in use if you’ve ever filled out a form on a web page. If you didn’t fill out all the required text boxes, or if you entered invalid data into one or more of the boxes, the website didn’t crash. Instead, it redisplayed the page and showed an error. WWebsites often use a red asterisk next to text boxes with missing or invalid data.
Some common checks performed by input validation include:
- Verifying proper characters. Some fields such as a zip code use only numbers, whereas other fields such as state name use only letters. Other fields are a hybrid. For example, a phone number uses only numbers and dashes. Developers can configure input validation code to check for specific character types, and even verify that characters are entered in the correct order. For example, a telephone number mask of ###-###-#### accepts only three numbers, a dash, three numbers, a dash, and four numbers.
- Implementing boundary or range checking. These checks ensure that values are within expected boundaries or ranges. For example, if the maximum purchase for a product is three, a range check verifies the quantity is three or less. The validation check identifies data outside the range as invalid and the application does not use it.
- Blocking HTML code. Some malicious attacks embed HTML code within the input as part of an attack. These can be blocked by preventing the user from entering the < and > characters, which are used within HTML code.
- Preventing the use of certain characters. Some attacks, such as SQL injection attacks, use specific characters such as the dash (-), apostrophe (‘), and equal sign (=). Blocking these characters helps to prevent these attacks.
Client-Side and Server-Side Input Validation
It’s possible to perform input validation at the client and the server.
- Client-side input validation is quicker, but is vulnerable to attacks.
- Server-side input validation takes longer, but is secure because it ensures the application doesn’t receive invalid data.
Many applications use both. Imagine Homer is using a web browser to purchase the newest version of Scrabbleships through the Duff website. Customers cannot purchase more than three at a time.
In client-side input validation, the validation code is included in the HTML page sent to Homer. If he enters a quantity of four or more, the HTML code gives him an error message, and doesn’t submit the page to the server until Homer enters the correct data.
Unfortunately, it’s possible to bypass client-side validation techniques. Many web browsers allow users to disable JavaScript in the web browser, which bypasses client-side validation. It’s also possible to use a web proxy to capture the data sent from the client in the HTTP POST command and modify it before forwarding to the server.
Server-side input validation checks the inputted values when it reaches the server. This ensures that the user hasn’t bypassed the client-side checks.
Using both client-side and server-side validation provides speed and security. The client-side validation checks prevent round-trips to the user until the user has entered the correct data.
Remember this
The lack of input validation is one of the most common security issues on web-based applications. Input validation verifies the validity of inputted data before using it, and server-side validation is more secure than client-side validation. Input validation protects against many attacks, such as buffer overflow, SQL injection, command injection, and cross-site scripting attacks.
Q. Which of the following developer techniques results in significant security vulnerabilities for online website applications?
A. Buffer overflow
B. XSRF
C. Poor input validation
D. Hardening
Answer is C. Poor input validation often causes security vulnerabilities and can lead to major losses when exploited.
Buffer overflow and cross-site request forgery (XSRF) are attacks that can be mitigated by input validation. They are not techniques used by developers.
Hardening both operating systems and applications helps make them more secure from security vulnerabilities.