5 ms·
I'm storing hashed password in the database. I'm writing POST http handler and storing user info in the session information. I don't know why would I use framew
by vbezhenar 7y ago
I'm storing hashed password in the database. I'm writing POST http handler and storing user info in the session information. I don't know why would I use framework or even service, it's just few dozens of simple lines of code. I don't use frameworks for simple things. I guess it might make sense when one need to support login via Google, Facebook, etc, I'm working on enterprise websites which don't need that.
- Kiro 7y agoI use Firebase since I don't want to be responsible for user data. I don't trust my security skills enough.
- sammorrowdrums 7y agoAre you using salts, and what hash algo are you using? For a security comment on DIY I'd hope that you be more specific as I don't want somebody reading it and thinking they can just MD5 passwords with no salt and expect their system to be safe...
- vbezhenar 7y agoI'm using salt for every password with PBKDF2WithHmacSHA256 algorithm. It's an old algorithm, but it's not broken and it's supported in Java without any additional crypto libraries. I think that modern alternatives are bcrypt, scrypt and argon 2.
- sammorrowdrums 7y agoThanks for that, I agree simple password authentication doesn't require a library, but there are still pitfalls and mistakes so I don't mind encouraging libraries as at least there is (for the popular libs) some responsibility taken for quality of implementation, and things like password reset mechanisms etc. As you mention handling multiple Oauth providers and stuff that is usually not worth the effort without a library, but anyway. Just looking out for people like the younger me (who would probably have tried to roll out things they shouldn't have, naively).
- rmdashrfstar 7y agoSince you hadn’t mentioned PBKDF2 or SHA256 (or higher), a usage of salts, nor handling authentication across service boundaries in an enterprise context, this is essentially an advertisement for using a third-party service.
- anonymoushn 7y agoIf you are handling salts yourself, you should probably use something else D:
- XMPPwocky 7y agoPresumably checking user passwords for security is out of scope? How do you mitigate credential stuffing attacks? Throttling per account? Globally? By source IP? A user leaves their company. How do you automatically deactivate their account? You're using password hashes. Cool. A secure password hash function, right? Scrypt, argon2, maybe bcrypt? (MD5, SHA1, and SHA2 are not password hashes.) You're comparing them in constant time, right? Are you sure? The compiler hasn't "optimized" you into problems here? You're working with enterprise websites. You obviously support 2FA; and you're probably going to want to support SSO with SAML2, and definitely integrate with Active Directory over LDAP. And your password reset flow- just send an email with a magic link? do you generate the magic link's token with a CSPRNG? Is it long enough? When does it expire? And admins probably have to be able to reset anybody's password, but with strong auditing and accountability features... You store user info in the session information- basically caching it out of the database? How do you invalidate sessions after a user changes their password or has their account disabled? Can somebody put Unicode in their password? You're writing a POST handler. You protect against CSRF, right? (yes, tricking somebody into logging in as another user can be very useful!) Doesn't seem so simple to me...
- fredsted 7y agoGood points. Difficult and unforeseen issues like these are exactly why you'd use a framework of some kind, where thousands of users have already tested and fixed various issues.
- foota 7y agoNit: I don't believe that comparing hashes in constant time is important, as long as you accept the user's password and then hash it, since being able to find the prefix of the hash is computationally just as hard as reversing the hash. Though it doesn't hurt to do anyway :) It is important when comparing (some forms of) auth tokens, such as csrf tokens.
- thephyber 7y agoSide note: Using the language the correct way to compare hashes is important. Researchers found that PHP can coerce strings into scientific notation if the hash begins with “0e...” and using the == != operators, thereby causing a massive error space[1] [1] http://www.darkreading.com/vulnerabilities---threats/php-hash-comparison-weakness-a-threat-to-websites-researcher-says-/d/d-id/1320353 http://www.darkreading.com/vulnerabilities---threats/php-has...
- onion2k 7y agoI'd use a framework even for very simple authentication. There's just so much to supporting a decent UX that people expect now; - limiting login attempts with a die off time between tries - blocking automated brute force login attacks - verifying accounts by email on sign up / invitation - verifying username and password changes by email - a friendly forgotten password workflow - supporting even one basic 2FA factor (especially important on enterprise) - logging user activity - permission management You could easily write all those things yourself. None of them are very complicated. But if you get any of them wrong it's very, very bad. Why wouldn't you use something that thousands of people have tested already?
- wwweston 7y agoWithout disagreeing with your point, I'll make an attempt to answer this question: > Why wouldn't you use something that thousands of people have tested already? I think some of us find the most portable thing between projects -- across languages and platforms -- are outlines of what some part of an application has to be able to do and an ability to implement it from scratch. There's certainly always some level at which off-the-shelf is a more productive and reliable choice. A DIY approach tends to yield more dividends to the degree that constraints or requirements in play would compel you to work against the grain of off-the-shelf stuff (thereby having to deal in the details anyway, not only for the problem, but for how the frameworks does things), and fewer dividends (or outright liabilities) to the extent that off-the-shelf will more than cover you. Additionally, it's good to remember that something like Bob Martin's observation can apply: "framework authors are out to screw you -- that's not quite true, they're not exactly out to screw you, but they will screw you because the framework authors have their interests in mind, not yours." The language is a little bit over the top but it's true that dependencies are not solid foundation points, they're viscous potential points of future instability because they're projects driven by incentives that are not always aligned with yours. And the closer they are to the center of your app the more that might matter at some point. What happens with authentication if/when you decide to migrate frameworks? Or if your framework-supported application is only one of several (not all based on the same stack!) providing service in front of a common datastore? It's worth reckoning with the overhead and hazards of DIY for sure, it's just also worth reckoning with the sometimes more subtle costs of framework buy-in. I'll also add that while there are times I'm an enthusiastic supporter of framework use, I can't imagine being anything other than skeptical about outsourcing authentication to a third party service. Maybe there's a circumstance in which I'd find that would make more sense someday, but placing such a core thing in third-party hands gives me the shivers.
- thephyber 7y agoIf this were a tech interview and you had ever had a job in industry on your resume, I would likely end consideration of you a candidate and switch to mentor mode to help you understand what to study before your next interview (at a different company). I dislike when developers insist on “not invented here” mentality and anything concerning security should not be an excuse to reinvent the wheel and make the same mistakes a million other developers already made. Auth is ridiculously complex, is the source of MANY critical security defects, has plenty of frameworks which solve significant parts of it, and always seems easy until someone explains to you what all you didn’t know you needed. Components: - login page - two factor state - password reset form - username lookup form - logic for 401 status - logic for 403 status - throttling, is ban, user lockouts, and/or captchas for the forms you don’t want attacked at scale - if you are storing credentials on your server (like password hashes), you better know what the options are for hashes, what a salt is, have investigated bcrypt and scrypt, know what happened when any of the thousands of large websites had their user databases leaked - maybe support warning users that their credentials in your DB matches a record in HaveIBeenPwned and lock down their account until they password reset using their email address - have a plan for when the hash you chose is deprecated in a few years while you aren’t paying attention and need to spent days re-coding to support new hash and legacy hash users, auto-migrating the legacies on next login - want to support multiple 3rd party IDPs as well as local password auth? That starts to explode complexity and the number of forms. - want to support SSO for enterprise? Use a framework that already supports SAML integration
- javajosh 7y agoThere are roughly 3 phases in your career. In the first, you don't know much and do things simply, naively. In the second, you know quite a lot, and like it or not you will be quite attached to your own expertise, it will be part of your identity. Your solutions tend to be complex, but you believe they must be that way, and you have evidence this is so. In the third phase, you begin to perceive systems as ephemeral results of some causal chain, and have a sense of how they became the way that they are. This depth of understanding allows you to embrace simplicity again, but this time you understand precisely the limits of that complexity. I think a lot of professionals (not just programmers) get stuck in phase 2. This is where, in our field, most of the code comes from: capable, smart people writing new code furiously, and with the not incosequential fact that it provably works. Sure, it has bugs, but you can get to those eventually. It also happens to be the most "defensible" phase, where you get to speak down to others - you have concrete experience, real knowledge, so you are justified. I would guess this is also the bulk of working programmers. So, the OP's solution could be coming from a phase 1 or phase 3 place. You are certainly coming from phase 2. I would encourage you to stretch a bit and consider when the OP's simple solution makes sense, and when it doesn't. I would hope you would do this in an interview as well, because you'll find phase 3 people saying all kinds of whacky things, which might not make sense to you unless you ask. (A careful phase 3 will make sure to preface his simple solution with his limits, and to not do so is a little bit sloppy, but personally I don't think that's a deal-breaker.)
- tus88 7y ago> I don't know why would I use framework or even service, it's just few dozens of simple lines of code Oh...oh god...oh god nooooooo!