Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the accepted techniques for staying logged on to a web site?

Most web sites you can log on to also provide the feature so it remembers you between sessions. What's the accepted and secure techniques for implementing that ? (What do you put in the cookies and how do you handle it on the server/db?)

like image 714
nos Avatar asked Jul 17 '09 11:07

nos


2 Answers

This recent 2009 chapter in Spring Security 3.0 discusses Remember-Me type authentication. The general concepts are not specific to Spring Security so you should be able to benefit from it even if you are not using it. The chapter also cites a Barry Jaspan's 2006 blog posting which is an improvement over the techniques described in Charles Miller's 2004 blog posting.

The blog entry basically comes down to:

  1. When the user successfully logs in with Remember Me checked, a login cookie is issued in addition to the standard session management cookie.

    • The login cookie contains the user's username, a series identifier, and a token. The series and token are unguessable random numbers from a suitably large space. All three are stored together in a database table.

    • When a non-logged-in user visits the site and presents a login cookie, the username, series, and token are looked up in the database.

    • If the triplet is present, the user is considered authenticated. The used token is removed from the database. A new token is generated, stored in database with the username and the same series identifier, and a new login cookie containing all three is issued to the user.
    • If the username and series are present but the token does not match, a theft is assumed. The user receives a strongly worded warning and all of the user's remembered sessions are deleted.
    • If the username and series are not present, the login cookie is ignored.
like image 145
0sumgain Avatar answered Sep 24 '22 17:09

0sumgain


Signed cookies that can not be tampered with can be a good idea when you don't require a whole server-side state ... lean mean and efficient.

You still run the risk of cookie theft but you can always sign the cookie using IP address, User-agent and other things to help minimize the threat.

like image 44
Aiden Bell Avatar answered Sep 26 '22 17:09

Aiden Bell