Web App Security Best Practices
coffeeonthekeyboard.com
coffeeonthekeyboard.com
The idea (for any system) is to start with understanding an adversary's perspective by:
- Listing application entry points (where does data enter into the application?)
- Cataloguing assets (what's being protected?)
- Identifying trust levels (who needs access to what?)
Then defining the security of the app/system by:
- Defining use scenarios
- Identifying implementation assumptions (parameter-based SQL?) and external dependencies (payment system?)
- Modelling the application/solution (data flow diagram that shows interactions with external entities, and machine and process boundaries)
The final stage is identifying threats, analysing them, and determining vulnerabilities. Threats typically fall into one of 6 categories:
- Spoofing
- Tampering
- Repudiation
- Information disclosure
- Denial of service
- Elevation of privilege
That stuff I've just written doesn't begin to do threat modelling justice, but it's enough to start some research.
And before anyone starts suggesting that it's not important/requires big design up front/we need to pivot/etc consider that exactly those arguments are what landed the likes of LinkedIn, Sony, etc. in hot water.
Maybe it's worth adding that the basics are just the basics, not a substitute for real threat modeling and analysis. But there's always a real-world cost/benefit factor.
So, no, let's keep raising awareness of the basics until finally everyone gets it. Then, once the OWASP top ten is filled with MITM, timing and social engineering attacks, that's when we can move on to the broader approach.
The framework isn't fool proof (no one can protect developers from themselves). But I feel that Django does what it needs to do when it comes to protecting its users.
The "last mile" is just making sure your code is using all those tools correctly.
And yet that example may only be the last item in a threat tree, which may have a zero-day vulnerability at its root.
Relying on tools or, in fact, any code you've not written yourself makes your system vulnerable. If you understand how an attacker might compromise a system (ref. STRIDE) you can mitigate.
Writing everything yourself, as opposed to widely, community tested open-source alternatives, makes your system vulnerable.
Your example seems to be at the farthest possible end of the spectrum from what I'm talking about.
Not that you shouldn't understand the potential vectors against your site, or shouldn't read how to use these tools correctly, but a widely tested and used tool or framework, just like a widely researched crytpo algorithm, is better than one with no other eyes on it.
Anything that makes engaging harder (2-factor auth, captchas, which I'll get to sometime next week) will cost conversions and engagement. You have to weigh those things realistically. Security doesn't exist in a vacuum where User Experience doesn't matter.
Does the value of the asset merit the cost of the second factor (considering the 2factor is a per-user cost)?
Google Authenticator is free for the user, and the algorithm used (TOTP/OATH - not to be confused with OAuth) is open and easy to implement: it's essentially just feeding the current unix time and a per-user secret to an HMAC-SHA1.
Imagine the route that token takes - from your server across the internet to an SMS service (a channel you might secure using TLS/SSL).
From there to any one of an arbitrary number of network operators, again over the public internet. You've no control over this leg. From there the token travels through the network operator's network, to a switch, and then over the GSM network to the handset.
There are at least two places there where you can launch a man in the middle attack.
Which brings me back to the threat model - understanding the value of the asset you're protecting will tell you whether the cost [1] of such an authentication scheme is worth it. Oh, and the cellphone-based OTP is of course an additional asset this authentication scheme introduces.
[1] Cost is not just the cost/per SMS. It's also the cost of developing/aquiring the technology, and then maintaining it and the infrastructure that supports it.
It essentially generates a code based on a pre-shared secret and the current time.
As for the costs, as I said there's plenty of free client applications (Google Authenticator is just the most well known), and not only there are plenty of libraries that you can use on your server, as the RFC that details TOTP provides an implementation in less than 50 short lines of code (+ Java boilerplate); see http://tools.ietf.org/html/rfc6238
And you just need that, plus an extra field in your data store for each user (to store the secret) and a textbox in the login page.
Using a phone is a great solution. Except when the app that requires TOTP authN is also on the phone. That's a shame.
Either way, thanks for positing the link, and clarifying. I learnt something today.
Well, it uses a 30 second window, so it can cope with small drifts; as long as the phone's RTC isn't broken, you should rarely need to re-sync.
I use it with a J2ME application on a Nokia S60 without an internet plan and it works fine.