One of the most fundamental things to understand when developing a secure site is this: all information not generated within the application itself is potentially tainted. This includes data from forms, files, and databases.
When data is described as being tainted, this doesn’t mean it’s necessarily malicious. It means it might be malicious. You can’t trust the source, so you should inspect it to make sure it’s valid. This inspection process is called filtering, and you only want to allow valid data to enter your application.
There are a few best practices regarding the filtering process:
Use a whitelist approach. This means you err on the side of caution and assume data to be invalid unless you can prove it to be valid.
Never correct invalid data. History has proven that attempts to correct invalid data often result in security vulnerabilities due to errors.
Use a naming convention to help distinguish between filtered and tainted data. Filtering is useless if you can’t reliably determine whether something has been filtered.
In order to solidify these concepts, consider a simple HTML form allowing a user to select among three colors:
<p>Please select a color:
It’s easy to appreciate the desire to trust
process.php. After all, the form seemingly ...