I've been looking into a legacy application with a web-based user interface. Given its age (nearly 10 years some parts) there's a lot that needs updating and re-architecting, but I'm wondering about a small point regarding how user sessions work.
In a nutshell:
- The entire UI is served via HTTPS.
- Users are authenticated unremarkably by comparing username and password hash with values saved in a database.
- Upon authentication, a browser cookie is set, which contains two values that save the last top-level and second-to-top level section/module the user has accessed, an expiration date, and a value like "loggedin=true". Upon logout, the cookie is reset with "loggedin=false". There is no session token in the cookie.
- The first page loaded after authentication, as well as each subsequent page load, contains a JavaScript variable "sessionToken", which is a base64 encoded string with various parts, some of which encrypted:
var sessionToken = "...."
- Each navigation link generates a HTTP POST request, via a
<form>
element and JavaScript event handlers, with the relevant variables passed into it behind the scenes, along with the sessionToken, which in turn is set again, identically, on the next page load. The user stays logged in if at the same time the cookie has "loggedin=true", and the expiration time hasn't elapsed. - Sessions expire after a configurable time. The expiry happens on the next click on a navigation item after the expiry has elapsed. I believe this is simply by comparing the last time the session token was written out in the backend, but maybe the cookie is used -- I haven't found this out yet. When sessions expire, the "loggedin" value in the cookie is flipped and the user redirected to the login page.
I'm not a security specialist, and have not seen this design before. I'd be interested to know what pitfalls and risks, if any, you can see in it. (Me, I have a bad feeling, but would like some more solid input.)
If this is a standard way in some corner of the web, I'd like to hear about it, too.