Hacker News new | ask | show | jobs
by SeoxyS 4773 days ago
I wrote this comment with the assumption that we all understand the security implications of what's going on, which is why I probably did a poor job of making my point.

However, I think that relying on a single easy-to-compromise security token as a single point of failure for your app's security is terrible practice.

A secure user authentication system is usually built by having a users database that contains [user_id, nonce, password_key = pbkdf2(password, nonce)]. When logging the user in, you should store this information in a cookie: [user_id, login_timestamp, authentication_token = hmac-sha256(nonce, login_timestamp, password_key)]. Then, on every subsequent request, you would verify that the authentication_token matches what you'd expect based on the login_timestamp and user_id that the client has provided. (Substitute this for any equivalent-security scheme and crypto primitives.)

Now, if you have such a scheme in place, a secret token would provide no additional security. You really shouldn't be storing session information in cookies, but if you must, you can use a key derived from the nonce to sign the cookie, removing the need for an app-global secret. But really, don't do that, you should use a server side datastore for session information (like shopping carts, etc.).

If you do not have such a scheme in place, you app is much more vulnerable to attack. Something based on one global secret token (which by default is checked in to your source code) opens up many more attack vectors that might compromise the security of your app.

1 comments

That's a completely valid route, for sure, but if your app's owned, your database is owned and this is going to be blown as wide open as a secret token.