5 ms·
Note that the article buries a much easier way to deal with this problem: "some websites don’t verify the user’s authentication on each request (i.e. there is
by bryanlarsen 10y ago
Note that the article buries a much easier way to deal with this problem:
"some websites don’t verify the user’s authentication on each request (i.e. there is no way to revoke the session cookie once issued)"
Which implies that if you do verify the session on the server and have a mechanism for invalidating these sessions on password change, etc, you can just use very long cookies and you're done.
There are very good reasons for doing that anyways, so no need for this hack.
- mountaineer22 10y agoWould there ever be a reason to have the cookie expire at all? If the password is changed, you can invalidate the session, but the cookie remains?
- jessaustin 10y agoThe point is that verifying on the server can be a pain. TFA's proposal avoids doing so, much of the time. One could imagine rolling out any number of parallel "service workers" to perform this task without needing to complicate the server with concerns about a single user's requests hitting multiple servers that therefore need to stay on the same page with respect to token revocation.
- ddalex 10y agoThe session has to be fetched from cache/hot memory on every request, right? Authenticating the session per request may be expensive, but actually clearing the session cache so the request can't even get the session data - that's much better. So you don't need to invalidate the auth tokens. You just need to be able to delete a session from the cache to do revocation on long sessions. And this works with just backend changes, no client hockey-pokey needed.
- mark242 10y ago"The session has to be fetched from cache/hot memory on every request, right?" Nope. Let's say you have a rest endpoint that accepts a Pokemon id to add to your collection. If you cryptographically sign a cookie that says "I am this user id" you can assume the request to add the Pokemon to your collection is valid. There's other business logic to perform, sure, but "I am this user" is taken care of for you. What Google is proposing is the ability to save a long-term cookie that says "I am this user" and a short-term cookie that says "I'm signed in". The requests periodically say "am I still signed in/am I still this user" and the server can periodically (eg not every request) look that up in cache/database.
- ddalex 10y agoMy point is that at some point, you have the control on the server. Of course, you can encrypt the session information in the cookie, and decrypt it on the server end, verify signature, and certify that the user is who they say it is. This just moves the problem a bit - if you want to log out a user, you can just erase the cookie key from the server side; the cookie will be just random noise at that point. This approach, of course, assumes that your keys are user specific, possibly generated from the password.
- jessaustin 10y agoYou're right, if every authenticated cookie must also be validated against the DB, there is no point to using authenticated cookies. TFA describes short-lived authenticated cookies, which need not be validated against a DB, used in conjunction with longer-lived DB sessions, which are only validated against the DB when the short-term cookie has expired. Those DB sessions end on logout or reset or whatever.
- skybrian 10y agoActually a good reason might be scalability. Authenticating every single request creates a big load on your authentication service. That's a lot of RPC's, particularly if you're using single sign-on and those RPC's are coming from every web app you run.
- mark242 10y agoYou don't need to verify the session on the server all the time. Session verification very quickly becomes a bottleneck to app performance, since you're doing a separate database/cache lookup for each rest endpoint request. It's far easier, and provides much better performance, to just cryptographically sign a cookie that says "I'm this user". This is where the short/long-term cookie comes into play, and is actually a neat idea to take care of the "how do I periodically check that the user hasn't logged out/changed their password/invalidated their sessions/etc" problem that the cryptographically-signed cookie brings up.
- bradleyjg 10y agoThat sounds like a time-space trade-off to me. I'd think cryptographic signature verification would be more expensive computationally than a cache lookup and compare, but not require much space. Also, and maybe this is the key part, it would be more distributable since you don't need shared state.
- mark242 10y agoYes; and CPU is cheap as hell. Round trips to a cache are expensive.
- cpeterso 10y agoAlso, CPU tasks like authenticating a message are cheap to scale horizontally. A cache is a centralized bottleneck.
- carterehsmith 10y agoThat depends on where your cache is. If your cache is on a separate box and you have to make a network round trip, yeah it is expensive. But if your cache is in-process, the access is cheap.
- tptacek 10y agoCryptographic signature verification can be expensive, but the previous commenter (and, to be fair, pretty much the whole software industry) is abusing the term "signature". Really, what we're talking about is cryptographically authenticated messages. Verifying an authenticator is extremely fast.