I wanted to implement login system using flask framework. I managed to do this using sessions and set them to expire after 31 days and it works (sessions are created using server secret key, timestamp and cryptography by flask).
But there is one thing that is concerning me and that is session id that was created before can still be used before it is expired e.g:
- User logs in and session id is: e.g:eyJ1c2VybmFtZSI6InBhbWl4In0.ZcIFkA.9VeEJ4_nxQgCNkijO6GLtSNse3c
- User logs out which means that session is deleted but only locally because cryptography will make it expire after 31 days since the creation, it means previous token is still valid.
- User logs in and session id is newly generated. But the problem is that session from first step is still valid and I can use it again.
I believe vulnerability that I'm describing is called replay attack. I have few questions regarding that topic:
- Should I even worry about it?
- If it is considered vulnerablity,how can I try to get rid of this?
- Is it good idea to create new column in database in User table(the same that stores credentials like username and password) called 'session id'? That way I can store the latest valid session id so when user makes request it can compare the session id that he sent with the one in the database. I am not sure if it is good idea because of efficiency reasons.