Explain different approaches for Input validation.
Input Validation is the outer defensive perimeter for your web application. This perimeter protects the core business logic, processing and output generation. Beyond the perimeter is everything considered potential enemy territory which is...literally everything other than the literal code executed by the current request. All possible entrances and exits on the perimeter are guarded day and night by trigger happy sentries who prefer to shoot first and never ask questions. Connected to this perimeter are separately guarded (and very suspicious looking) “allies” including the Model/Database and File system. Nobody wants to shoot them but if they press their luck...pop. Each of these allies have their own perimeters which may or may not trust ours.
The common phrase seen in PHP is “user input”. This is one of those compartmentalising by trust value issues. In suggesting that users are untrusted, we imply that everything else is trusted. This is untrue. Users are just the most obvious untrusted source of input since they are known strangers over which we have no control.
Validation Considerations
Input validation is both the most fundamental defense that a web application relies upon and the most unreliable. A significant majority of web application vulnerabilities arise from a validation failure, so getting this part of our defenses right is essential. Even where we do appear to have gotten it down, we’ll need to be concious of the following considerations.
You should bear these in mind whenever implementing custom validators or adopting a 3rd party validation library. When it comes to 3rd party validators, also consider that these tend to be general in nature and most likely omit key specific validation routines your web application will require. As with any security oriented library, be sure to personally review your preferred library for flaws and limitations. It’s also worth bearing in mind that PHP is not above some bizarre arguably unsafe behaviours. Consider the following example from PHP’s filter functions:
filter_var('php://', FILTER_VALIDATE_URL);
The above example passes the filter without issue. The problem with accepting a php:// URL is that it can be passed to PHP functions which expect to retrieve a remote HTTP URL and not to return data from executing PHP (via the PHP wrapper). The flaw in the above is that the filter options have no method of limiting the URI scheme allowed and users’ expect this to be one of http, https or mailto rather than some generic PHP specific URI. This is the sort of generic validation approach we should seek to avoid at all costs.
Be Wary Of Context
Validating input is intended to prevent the entry of unsafe data into the web application. It has a significant stumbling block in that validation is usually performed to check if data is safe for its first intended use.
For example, if I receive a piece of data containing a name, I may validate it fairly loosely to allow for apostrophes, commas, brackets, spaces, and the whole range of alphanumeric Unicode characters (not all of which need literally be alphabetic according to Western languages). As a name, we’d have valid data which can be useful for display purposes (it’s first intended use). However, if we use that data elsewhere (e.g. a database query) we will be putting it into a new context. In that new context, some of the characters we allow would still be dangerous - our name might actually be a carefully crafted string intended to perform an SQL Injection attack.
The outcome of this is that input validation is inherently unreliable. Input validation works best with extremely restricted values, e.g. when something must be an integer, or an alphanumeric string, or a HTTP URL. Such
_________ _________ ____ ____ ______ _______.
________ ________ _________ __________ _____ _________ _______ ________ _________.
__________ ______ _____ ___ ___ _____ __________ ______ _____ ____ _________.
__________ ____ _________ ______ _____ _______.
_______ __________ ___ ________ ___ __________ ________ _______.
____ ___ _______ ________ ______.
_________ _____ ____ _______ __________ ___ _________.
____ ____ ________ _______ _______ ________ _________ ___ ______ _______ __________ ___.
_____ _________ ____ ___ _______ ___ ___ _____ ____ _________ ______.
__________ ________ __________ __________ _____ _______ ____.
_______ ______ ____ __________ ________ __________ __________ __________.
________ ____ _______ _________ ____ ________ ___.
_________ _______ __________ ___ ________ _______ ____ ____ ______.
____ ______ ________ ____ _________ __________ _____ ________ _______ ______ ________.
________ ________ _____ ____ _____ ____ _______ _________ _____ _____.
________ ______ ______ _____ ____ ______ _____.
______ _____ __________ ______ __________.
_____ __________ ____ ________ _______.
_______ _____ ______ ___ _______ ___ _______ _________ _____ ____.
______ _____ ____ ______ ________ __________ ________ _________ ________.
____ ___ ________ _____ ____ ____ ___ _______ ______ ___.
__________ ______ ___ ___ ___ ______ _______ _______ _______ ______ _______.
___ ________ _______ _____ ________ _________.
_______ _______ __________ ________ __________ ______ _______ ____ ___.
________ _____ _______ ________ _____ _________.
____ ______ _______ _____ _______ ________.
__________ ___ _____ ______ _____ ___ _____.
___ ______ __________ _______ ________ ___.
_____ ___ _____ ___ ____ _________ _____ ________ _______.
__________ ___ ____ ____ _____ _______ _____ ______.
_______ __________ ____ _______ _____ ____ ________ ___ _________ ____.
_________ ____ ________ ___ ____ ______ ___.
_____ ___ _____ ________ _________ __________ ____ _____ _______.
______ ______ __________ _______ _______.
___ __________ _____ __________ _________ ________ _______ ____ ____ _________ ________ ______.
________ ___ _____ _________ _________ ___ _______ __________ _____.
_______ ________ __________ ______ ______ _______ ______ ___ _________ ______ _____ _________.
________ ___ __________ ________ ________ _________ _________ _____ _________ ___ ____ ____.
_________ _________ _______ ______ _________ _______ ________.
_____ _______ ____ _______ ______ ___ ___.
__________ ______ ______ ___ __________ _____ ________ ______ _____ ___ _______.
______ _________ ______ _____ ______ ___ ____ _______ _____ ____ ____ ____.
______ ___ _________ __________ ______ ________ ________ ________ _____ _________.
__________ __________ _______ ____ _________ ________ _________.
____ ________ ________ ____ ________ ________ _______ _______ ______ __________ ______.
__________ ______ ______ _______ ____ _____ _______ __________.
___ ________ _________ _________ __________ _______.
_________ _______ ________ _______ _________ _________ ______ ____ ___ _______ _________.
______ _____ _______ ______ ___ ______ ________ ___ _______ ____.
________ ________ _________ __________ ________ _______.
________ ___ ______ _____ ________ ______ _________.
____ ________ ______ ____ ______.
_________ _________ __________ __________ _________ ________ _______ ________.
______ _________ ____ _____ ____ __________ __________ _______ ______ ___ ________.
________ ______ _______ ______ ______ ___ ____ _____.
_________ __________ _______ _________ _____ _____ ________ ___ ______.
_______ ___ __________ ____ ____ ____ ____ ___ _______ _______ _________ ________.
___ ______ _____ _________ _______ _______.
_______ __________ ______ __________ _______ _________ _____ ________ _________ ____ _____.
__________ ____ _____ _____ __________ ________ _________ _______ ________ __________ _________.
____ ______ ________ _________ ___ __________ ____ ______ ________ ________.
__________ __________ _________ _________ ___ _______ ____ _________ _______ ___ _______ ________.
_______ ________ ___ ________ __________.
_________ ________ _______ _______ ______ _______ ______ ____ _________ ____ ________ ________.
__________ _______ __________ ___ ______ __________ __________ _________ __________ _______ _________.
_______ ______ _____ ____ _____ ______ _________ ____ __________ _____.
_____ ________ ___ _____ ____ ________ ____ __________ ___.
________ ____ ________ _____ _______ ________ __________ _________ __________.
________ __________ _______ ____ _____ ___ ______ ____ _____ _____.
_____ _______ _____ _______ _____ ________ _________ ___.
_______ ____ _______ _______ _______ ____.
______ ____ _________ ________ ________ _____ _________.
______ __________ ___ ______ ___.
_____ _______ _______ _______ _______ ___ __________ _____ ______ _____ ____.
_____ _______ ______ ____ _______ ________.
___ ________ _______ ______ _________ ______ ____ ________ ________ ___.
___ _________ ______ ________ __________ ___ __________ ______.
____ _______ _________ _____ _____ ____ __________ ______ _______ ____ ___.
______ ___ ___ _______ __________.
__________ ________ ___ _____ ______ ___.
__________ ___ _____ _________ ______.
___ _______ _________ __________ ____ _________ _______ _____ _______ _____ ___.
________ _________ _______ _____ __________ _______ __________ _________ __________ __________ _______ ___.
________ _______ _____ _______ _______ ____ ___ ___ ___ ___.
______ ____ _____ __________ ____.
_____ ___ _________ __________ ________ _________ ______ _____ ________ _______.
_____ __________ _______ _____ ___ __________.
___ __________ __________ ______ __________ _________ _______ ___ _________.
__________ _______ __________ ___ ___.
______ ________ _________ ______ ____ ____ ____ ___.
__________ ____ ___ __________ ______ ____ ___ __________ ___ ________ _______ ___.
_______ _______ __________ _________ ________ __________ _______.
________ ______ __________ _________ _______ _______ __________ _________.
_____ _________ _______ ___ ______.
______ ___ _____ __________ ___.
_________ ___ ____ ________ ______ _________ ______.
_________ _____ _____ ______ ______ ______ __________ _______ _________ ____.
__________ _________ __________ ___ ______ _________ ________ ______ __________ _______ __________ ____.
______ _____ ____ ____ _______ ____.
___ _____ _____ ______ ___ ______ ___ _____ ______.
_____ ______ ______ __________ ______ _________ _____ ______ ________ ____.
______ ____ ____ ___ _____.
______ _______ ________ __________ _____ _________ __________.
_____ ________ _________ _________ _________ __________ ___ ____.
_____ _________ ______ ______ __________ _____.
___ __________ ____ _____ _________ __________ ______ _______ _________ _______ ____ _______.
____ _______ _______ ________ __________ ____ ___ ____ ________ _________ _______ _____.
____ ___ _______ __________ __________.
____ _________ _________ _____ _______ _____ __________ _____ ___ _______ __________.
_______ ___ _______ _______ ______ __________ _____ ______.
____ _____ _____ __________ _____ _____ ____ ________ ________.
_______ __________ ___ __________ __________.
___ __________ ______ ________ _______ ______.
_____ _______ _____ __________ ___ ___ ________ ________ _________ _______.
___ ________ ___ _____ ___ ___ ______.
________ __________ _______ _________ ____.
____ ___ __________ _________ ______ _________ _________.
______ ___ _____ _________ ____ __________ ________ __________ ________.
_______ _____ _____ ___ ___ ______ _____ _______ _____ _____.
__________ ___ _______ _______ ________ _________ ____ _______ ___ _________.
____ __________ ______ _______ ___ ____ __________ ___.
____ ______ ______ ________ _______ _____ _________.
_____ ___ __________ _______ ___ ________.
_________ __________ ________ ________ ____ ___ ________ ____.
____ ______ ______ ______ __________ _________.
____ ______ _____ ____ _________ _______ ____.
_________ ____ ______ ________ ____ _________ _____ _____ __________ ____ _____ _______.
_______ _____ __________ __________ ______ ___.
_____ ____ _________ _________ _________ _____ _______ ___ ______ _____.
________ ________ ____ ________ ____ _________ ____ _______ __________ __________ _______.
______ ___ _____ _______ ____ ______ _________ __________ _____ ____ ___.
______ ______ _________ ________ ______.
___ ____ __________ ________ ________.
______ _________ __________ _____ ___ ____ _________ ______ ___ __________ ______ ________.
_____ _____ _________ _____ _________ _________.
- Solved Assignments
- Study Notes
- Guess Papers
- Question Papers
✓ Unlock up to 60% of the answer
✓ No payment required