A practical security guide for web developers
The first thing jumped out is:<p><i>Store password hashes using Bcrypt (no salt necessary - Bcrypt does it for you)</i><p>A better approach would be recommending storing password with password-based key derivation functions (recommendation: scrypt or bcrypt).<p>I don&#x27;t want to start the whole debate of scrypt vs bcrypt, GPU vs FPGA here (not qualified and we keep repeating the conversation every time the vs is on the table).<p>-<p><i>When parsing Signup&#x2F;Login input, sanitize for javascript:&#x2F;&#x2F;, data:&#x2F;&#x2F;, CRLF characters.</i><p>Not familiar with why only &quot;signup &#x2F; login&quot; input.<p>-<p><i>Serially iterable resource id should be avoided. Use &#x2F;me&#x2F;orders instead of &#x2F;user&#x2F;37153&#x2F;orders. This acts as a sanity check in case you forgot to check for authorization token.</i><p>Had to re-think twice. A stronger argument in favor of &#x2F;me&#x2F;orders over &#x2F;user&#x2F;37153&#x2F;orders is to avoid enumeration attack.<p>-<p><i>Any upload feature should sanitize the filename provided by the user.</i><p>I like this tip very much, but if the requirement is to keep the filename (think DropBox), you should sanitize filename before storing in the database.<p>-<p><i>Add CSRF header to prevent cross site request forgery.</i><p>I don&#x27;t believe there is a standard header to do this. I had to look up &quot;csrf header&quot;. Correct me if I am wrong. I think this is framework specific (if and only if framework supports it). A better recommendation would be to enable CSRF protection and consult with the framework you use. Most modern frameworks would have CSRF protection built-in (but implementation of CSRF protection varies!!!!!!)<p>-<p><i>Add HSTS header to prevent SSL stripping attack.</i><p>Simply put, after the user has visited a site with both HTTPS and HSTS header present, user agent like Firefox will honor the header and always attempt to load resource (HTML, JS, CSS) over HTTPS up to the max-age declared in the header. The caveat is you must have visited the HTTPS site first. To actually implement HSTS 100%, you should always redirect user (301) to HTTPS from HTTP.<p>-<p><i>Use random CSRF tokens and expose business logic APIs as HTTP POST requests.</i><p>Needs clarification on what &quot;business logic&quot; mean and why POST only? What about PUT and PATCH which also allow body to be used? GET I kind of get it.<p>-<p><i>If you are small and inexperienced, evaluate using AWS elasticbeanstalk or a PaaS to run your code.</i><p>Again, caveat is doing everything right. PaaS and IaaS shields you away from some common mistakes, but not all. You can have a remote code execution on an EC2 with instance profile with full access to the entire VPC and the execution is to remove all instances except the one it is on. Perfect.<p>-<p><i>Use a decent provisioning script to create VMs in the cloud.</i><p>I have to be a little picky... don&#x27;t say decent. This is so ambiguous. Did you mean don&#x27;t reinvent the wheel, or did you mean have a solid engineering process (code review, testing), treating infrastructure automation as software engineering as opposed to an ad-hoc scripting shop.<p>-<p><i>Check for no&#x2F;default passwords for databases especially MongoDB &amp; Redis. BTW MongoDB sucks, avoid it.</i><p>I get it. You own the article you write whatever you want. Professionally, if you want someone to take this serious, please don&#x27;t say that. I have seem people running Oracle just as good as running PostgreSQL. I have heard companies running Apache as successfully as running Nginx. I have heard horror story about Cassandra and success story about Cassandra. MongoDB has a few old mistakes like default to listen on 0.0.0.0 (I heard it is fixed by now?). BTW, I have used and have managed MongoDB, I know some of the pains, but half of that came out of not knowing what the hell I was doing.<p>-<p><i>Modify server config to use TLS 1.2 for HTTPS and disable all other schemes. (The tradeoff is good)</i><p>Right tradeoff is to use data and figure out whether or not you need to support legacy systems like those stuck with XP. It may not be critical, but there are companies that do. Use data first before making a decision like this.<p>-<p>Four other thoughts.<p>1. sanitization of inputs - context matters. The same sanitation technique for HTML doesn&#x27;t work for XML. That to me is one of the most complicated part in securing application. I am not surprised XSS is still #1 (or at least top 3).<p>2. Run code in sandbox mode. Not necessarily Docker or a container, but chroot and restrict application access to the available system resource. That&#x27;s very important.<p>3. Always use reputable framework. As a young adult I love inventing shit, but whatever you invent for your work you are now responsible and the next person picking up your work after you leave is also responsible. So think twice. I am not picking on Node developers because I have seen Python developers doing the same thing - before you import a random package that does a few thing, look at the standard library. Sometimes maintaining a 100-line code yourself vs doing in two lines after an import from the code is written by a random open source lover and is mostly won&#x27;t be maintained a few years from now is dangerous.<p>4. Always upgrade your framework, the toolsets you use, database server you use, etc.<p>I also think every framework should publish security best practice like <a href="https:&#x2F;&#x2F;docs.djangoproject.com&#x2F;en&#x2F;1.9&#x2F;topics&#x2F;security&#x2F;" rel="nofollow">https:&#x2F;&#x2F;docs.djangoproject.com&#x2F;en&#x2F;1.9&#x2F;topics&#x2F;security&#x2F;</a> and even more details. Security is one of those things I&#x27;d wish I had more time to experiment and address. I am no longer active in that space of automation sadly, but from time to time I think about is the fault really on development practice and developers? Can we make everyone&#x27;s life easier by having strong framework standard? Are we not making tools available? With so many formats being invented every year, we need to think about is our security flaws a result of our own creativity? Unfortunately, we can only hope for the best that we continue to improve security of our framework and we continue to add strong defaults. Also think about security testing. The low hanging fruit like detecting existence of certain security headers is trivial, but fuzzing and getting real good result of vulnerability within an app is extremely custom AND extremely hard to do (so many states, so little knowledge)...  you&#x27;ve got very expensive consultants and then very inexpensive but also very general purpose security testing tools that may not do much and can expose common mistakes. One thought would be sampling and either repeating or mimicking user traffic and run simulations. Perhaps some machine learning stuff could help - not sure.