

Input validation is one of the most critical yet underutilized secure coding techniques. This article breaks down the essentials and offers practical recommendations to help you improve your security practices.
Input validation has been a best practice since the late 1990s, and most developers recognize its importance. However, it often gets deprioritized, or developers rely solely on frameworks without fully understanding their effectiveness.
Focusing solely on code quality
Needing reminders to prioritize security
Lacking confidence in identifying security flaws
The developers who successfully catch these issues often do so because they’ve seen them before, highlighting the value of secure development education and training.
Validate inputs as soon as they enter your system. This prevents invalid data from propagating, reducing the risk of exceptions and errors later on. Early validation can also act as an attack indicator—if server-side validation catches something that passed client-side checks, it suggests an intrusion attempt. This assumes that your client-side checks match your server-side checks. They really should!
Example: HTML5 Form Controls HTML5 form controls are a straightforward way to enforce early validation. Here's a simple example that ensures account numbers are 5-15 digits long:
<form>
<input type="text" name="account" pattern="^[0-9]{5,15}$"
Use HTML5 form validation rules in combination with CSS pseudo-classes like :valid and :invalid to style input based on validation outcomes. The JavaScript Constraint Validation API can provide further checks, ensuring form elements adhere to specified attributes. I included a link to some example code that shows these concepts in action. Check it out.
Validating early will help you avoid problems. Always make sure to enforce your client-side validation with matching server-side validation.
Case in Point: Trust Boundary Failures
During a penetration test, I set my display name to <script>alert(0)</script>. The system correctly handled the input, but months later, the script executed when accessed by a different application that trusted the data. This is a classic example of a trust boundary failure. Always validate data from external sources, even if it appears safe.
Deny-list validation, which tries to block known bad inputs, is often ineffective because attackers can easily bypass it using various encoding tricks. Consider the < character—it can be encoded in over 70 different ways, making deny-lists difficult to maintain.

70+ encodings of the < character
HTML5 Validation with CSS & JS Example
CWE Top 25: https://cwe.mitre.org/top25/
Why Don't Developers Detect Improper Input Validation?: https://arxiv.org/abs/2102.06251
OWASP Input Validation Cheat Sheet: https://cheatsheetseries.owasp.org/cheatsheets/Input_Validation_Cheat_Sheet.html
