I am trying to add the Remember Me feature in my web application to allow the user to stay on between browser restarts. I think I got most of this. I use the Google engine for the backend, which allows me to use Java servlets. Here is some kind of pseudo code to demonstrate:
public class MyServlet {
public void handleRequest() {
if (getThreadLocalRequest().getSession().getAttribute("user") != null) {
}
else {
Cookie[] cookies = getThreadLocalRequest().getCookies();
if (cookies.find("rememberMePlz").exists()) {
String cookieid = cookies.find("rememberMePlz").value();
User user = DataStore.getUserByCookieId(cookieid);
if (user != null) {
getThreadLocalRequest().getSession()
.setAttribute("user", user);
}
else {
}
}
}
}
}
public class CookieLong {
private String mCookieId;
private String mUserId;
private long mExpirationDate;
}
Well, all of this makes sense. The only frightening thing is what happens if someone finds out the value of cookies? An attacker can set this cookie in his browser and gain access to my site and, in effect, log in as a user associated with it!
, , cookie , - cookie - cookie cookie, , ?
, , cookie, , , , + cookieid DataStore.
, . , - , ,