- Use something able to auto-escape SQL queries, unlike things done at hand like with PHP mysql_escape_string()
- Check user input _a lot_ for sanity. Write utility functions to access get/post vars able to make sure data type and range are ok, like, getintparam("foo") or if you aspect a value between 1 and 10 getintparam("foo",1,10). Similar functions with strings where you can specify the valid set of chars are also helpful.
- Remember to output html entities not only when you are outputting text, but also in html tag attributes like foo="bar". "bar" requires to be converted in HTML entities of course.
- Create a solid authentication scheme, for example write in the user table a 256bit authentication random number got from /dev/urandom, and set it as user cookie.
- When there are load problems use HMACs to "sign" important data and store it in user's cookies. It's possible to check for integrity of the data without to access the DB at all. Fast & Safe.
- Remember that if a user is logged in, an external site can have code like img src="http://yoursite/op.cgi?delete=all" To avoid this attack make sure to:
1) use HMAC-ed IDs for importante objects. "ff83729A2" instead of "41". Require that IDs of objects target of operations or other auth tokes the external site can't guess are required in order to perform operations.
2) for very important operations the system may require the user to type the password.
- Make sure you are not using algorithms with some worst case time complexity that can be triggered from outside. It will be very easy to turn this into a DOS.
And... of course: wirte simple code that's simple to check for corner cases. Computers aren't currently able to audit code, so you need to optimize for humans even for security.
You shouldn't be using GET for anything that has side effects.
POST requests aren't safe from tricks by third-party sites either, as is mentioned here for example: http://www.owasp.org/index.php/Cross-Site_Request_Forgery
(Open Web Application Security Project looks interesting otherwise too.)
Then if/when you become a mainstream site start doing planned security auditing from time to time.
I see a conflict between the entrepreneurial extreme concentration on what the users want and the need to follow good security practices consistently during all life stages of the product.
Of course, all entrepreneurs should already live in the relativity of risk, effort and reward. In that sense, I hope that startups understand to avoid some of the insane security risks that some enterprises seem to have. Likewise, Reddit has provided full HTML features with zero effort this far. Perhaps this exploit wasn't that bad to them or the users?
Reading some good books on security philosophy might help, especially if you don't have the time to follow and learn from Schneier's Crypto-Gram Newsletters and the various security announcement lists. More security with less effort is one more reason to run Linux or even OpenBSD. And, validate all inputs in your software. I wonder if there's a security checklist for startups.