Persistent Login Cookie Best Practice
fishbowl.pastiche.org
fishbowl.pastiche.org
The reason why encrypted connections are not the norm is a purely artificial one, because technically we could easily have the encryption aspect of HTTPS enabled by default, just as SSH does it today. We don't have that because browser makers and certificate authorities are happily running a money-making scheme that makes authentication mandatory if a site wants to use encryption. Droves of web developers and users have been brainwashed into thinking that encryption without an URL identity mechanism is somehow worse than having an unencrypted link.
However, this all has nothing to do with cookies, the connection is just incidental.
Encryption without confirming the identity of the other side is only slightly better than no encryption at all.
I agree that in theory it's a bad that thing many people think encryption with authentication is worse than no encryption at all, but in practice it doesn't matter. You cannot trust either of those options anyway.
In case it wasn't obvious: I love SSH because it doesn't rely on cert authorities and because it's ridiculously easy to establish a reasonably secure connection; it empowers users and server admins to no end. Is it exploitable? Yes! But I do believe it's difficult and far less likely than exploiting an unencrypted connection. And I'll say it again: denying users access to this basic mechanism was not a nice maneuver.
My experience of trying to cache on the client side, data ( from a php script ) requested via GET over https doesnt happen. This is done by design of the browsers as I believe they see it as the better of two evils. ( Not wanting to store secure data and then being attacked for that and losing market share ).
The approach I am using ( which is far from ideal ) is to make use of javascript, which can be cached.
Certificates aren't an elaborate money-making scheme. They're the tie breaking vote between Bank of America and the man-in-the-middle proxy pretending to be Bank of America.
Key agreement without some form of tie-breaker (be it key continuity, web-of-trust, or anchor keys, which is what SSL certificates use) is a fundamental problem familiar to anyone who has ever built any working cryptosystem. Among competent engineers, this isn't a debate. If you think anchor keys aren't the right solution to SSL, the onus is on you to suggest a viable alternative. "Nothing" is not a viable alternative; key agreement doesn't work with "nothing".
I'm not suggesting a new encryption standard for online banking, I want better default security for otherwise unprotected web traffic.
> There is no such thing as meaningful encryption without authentication; it's like a car with an engine but no steering wheel. Encryption without authentication is, at best, a trivial form of obfuscation (it's trivial because everybody knows how to reverse it).
In the context of my comment I was referring to the top-down cert authority structure (sorry if that wasn't clear), I didn't mean to imply that a webserver shouldn't have any certificate at all. I guess it comes down to disagreeing with you about self-signed certificates. I believe they would have been a good idea as a default mechanism for connecting to web servers and I still think they're way more secure than having nothing at all.
I believe that giving people exactly two choices, between cryptographic perfection and making transfers completely public, is wrong. And asserting that self-signed certificates are worse than no protection at all seems misguided to me. But in the end, you're the competent engineer and I'm just some guy posting inane comments on a message board over an unsecured link. And in any case, it's not like we'll change the way browser-based encryption works in the foreseeable future, so I kinda regret starting this whole discussion.
> If you think anchor keys aren't the right solution to SSL, the onus is on you to suggest a viable alternative. "Nothing" is not a viable alternative;
I'm sorry to say this but I suspect you are, maybe inadvertently, attacking a straw man here...
Every single free and commercial web security testing tool already does this on the fly. We are not talking about some complex, unlikely-to-occur threat. It's a pushbutton attack.
So... what's the point of a self-signed cert?
The problem is that encryption without key agreement isn't better default security. It's worse because people will expect it to be secure when it cannot be.
You're probably thinking that it's really hard to get between you and random web servers, but you are sadly mistaken.
Cookie = (user id, timestamp of cookie, random number, hash(rest of cookie contents, user password from database (in whatever encrypted form it's there))
With hash being something like HMAC-SHA1 with per-application key. Purpose of signing encrypted password together with all other data is to invalidate persistent login cookies when user changes password. Timestamp is there as to accommodate expiration of cookies in secure manner. This system has large advantage in that you don't have to store any additional data pertaining to persistent logins.
(2) I don't know what the value in having structured data, encoded or not, in a front-end security cookie; you are virtually always better with an opaque random number token.
(3) If you are going to play thermonuclear chicken with cryptography (point me to any code you wrote to generate and verify that token), I don't know what the point of a per-app HMAC key is; you are better off with a server-side per-cookie HMAC key.
(4) You haven't protected the timestamp, and so cannot do secure cookie expiration.
(5) The random number in that design doesn't appear to do anything.
And yes, the random number does not do anything significant and is probably useless. My reasoning was that it makes the structure of plain-text data slightly less evident from the cookie contents.
Virtually everybody reading this thread would be far better served by `head /dev/random | openssl sha1` than by any other scheme.
Second you take your security advice from a professional not someone who does not seem to know what they are talking about.
I use Devise, based on Warden, for Ruby on Rails. Depending on your platform, that may not work for you.
I use Warden and saw there was a rememberable strategy in Devise that I could use.
I also read I can secure the cookies to be only send over SSL. I was hoping some further explanations on that since Devise doesn't seem to do it.
Unfortunately, most Rails apps run without SSL, so that's not going to be the default any year soon. At this point, you really do have to pay money for a good SSL certificate, or self-sign and then people have to click through an ominous-looking dialog to use your site.
Why not just use a random number on its own? There's no reason I can see to bother with the username.
However, if the cookie consists of a username and a random number, the previous strategy is no longer feasible. The Cartesian product of usernames and random numbers from a large field is too great a set to consider attacking. An attacker's only hope in this implementation would be sniffing or MitM attacks (which I should add are much scarier than brute force attacks).
Once you push the odds of some event below the noise threshold of CPU error, it ceases mattering, because you've pushed past the point where you can't do anything about it anyhow anymore. CPUs are very reliable but their failure probability is not 0.
> When the cookie does not contain the username, you, the server, need to look up in your table to whom you gave the random number.
When the cookie does contain the username, I have to look up whether that random number is valid for the given username. How is that better?
If you want links to work, you need a more-persistent way of being identified. That's where cookies some in.
tail -f /dev/mind > blog
If you change that to 'tail -F', it will seamlessly pick up again if you replace (change?) your mind.