A similar question: the question of setting up GWT, Cookies and a web page .
One important thing you should remember: do not rely solely on cookies - pass the session identifier / token in the request payload and compare it with the server-side cookie value. This will prevent XSRF attacks. This is what you should worry about.
The policy on how to handle session identifiers depends on how seriously you take security in your application and what type of application it is. For example, you can log in with the same token on GMail from different IP addresses - I suppose they resolved this, because the common thing is that the user's IP address changes in sessions. However, they have added a feature that allows you to see which IP addresses you have logged into recently. And do not forget about users with dynamic IP addresses (quite a large number). If you keep track of tokens and IP addresses, you basically prevent these users from conducting a session between sessions.
What should I do on the server so that the Session ID is still legal and pulls up all the necessary information about the user?
You must keep track of login IDs / pairs in your database.
What will change the session id?
Either it expires, or the user tries to log in with a token that is not associated with their IP. You can also add your own rules - for example, the number of logins, etc. For added security, you can generate a new session identifier / token for each new login / session (the user authenticates with the old token, the server checks its validity and sends a new token back to the user, which he / she should use from now on).
Igor Klimer
source share