- All user modifiable input is evil (which means “handle with extreme caution”).
It is not that these things should be avoided, just that they must be handled correctly.
- Example: Http Headers - Evil!
- Example: Javascript Validation - Evil! (javascript validation is easily circumvented. Treat it as a UI nicety, but do the final checks on the server side!)
- Example: Http Post form values - Evil!
- Example: Url query string parameters - Evil!
- Example: Cookies - Evil!
- Example: File upload - Evil!
- Example: Data in a database - Evil!
-
Prevent Code and Data Confusion Here the term “Code” is used loosely to include anything that gets executed or interpreted. (strategies in order of (my) preference)
-
Strategy: Separate Command and Data
- Example: Parameterize Sql Queries
- Example: Windows Data Execution Prevention
-
Strategy: Encode data
- Example: Html encode all data displayed in a web page
- Example: (for PHP) mysqli_real_escape_string
-
Strategy: Allowed “Safe” input list
- Example: only allowing characters a-z and 1-9 in a user input field
-
Strategy: Disallowed “Dangerous” input list
- Example: Disallowing the single quote in a name field (sorry Chief O’Brien).
-
Corollary: What is data in one context may be code in another
- Strategy: Know your execution context
-
-
Defend the Premise
- Strategy: Understand your assumptions
-
Corollary: Ensure secrets are not guessable
- Strategy: Use cryptographically strong randomness.
- Strategy: Always salt your hash Salted Password Hashing - Doing it Right
-
Abstractions are Leaky
- Strategy: Understand the fundamental operating principles of your abstraction
-
Vulnerabilities can combine
-
Know the difference between Encryption and Encoding
-
Good algorithms can be subverted by bad implementations
- Strategy: Use trusted cryptographic implementations
-
Consider authentication, authorization and auditing
- Consider Action authorization
- Consider Data authorization
- Consider maintaining “who did what when with which information”
-
Consider Pyschology
-
Strategy: Help your users know when they are being spoofed.
- Example: “SiteKey” functionality
- Example: Tell your users what you will and won’t do (e.g. we will never ask for your password over the phone or in an email)
- Example: Use SSL with a cert issued by a CA.
- Example: Avoid blind redirects.
-
-
Know (and defend) your trust entry points
-
The Same Data Can Have Different Representations
- Strategy: Canonicalize before making a security decision
-
Encrypted data can still be used to attack a system
- Strategy: Use Nonces to prevent replay
- Strategy: Use reconciliation to detect replay (e.g. in financial systems)
- Strategy: Use digital signatures to verify identity
- Strategy: Protect your private keys