Trusting nothing from outside.
WHERE UNTRUSTED DATA COMES FROM
Users Files APIs Databases populated by others Command-line arguments
WHAT TO VALIDATE
Type Range and length Format Whether required values are present
WHY
Assuming shape produces failures on real data, and vulnerabilities.
WHEN TO VALIDATE
At the boundary, where data enters.
Then trust it internally.
WHAT THAT PREVENTS
Checks scattered throughout the code Uncertainty about what is safe
WHAT TO DO WITH INVALID DATA
Reject it clearly, with a message stating what was wrong.
WHAT NOT TO DO
Attempt to correct it silently Continue with a default nobody chose
FOR PATHS
Validate that they resolve where you expect.
FOR ANYTHING REACHING A DATABASE
Parameterised queries, always.
FOR ANYTHING DISPLAYED IN A WEB PAGE
Escape it, so it cannot be interpreted as markup.
WHAT TO ASSUME ABOUT EXTERNAL DATA
That it is wrong, until checked.