Your conception about how sessionStorage
works is probably wrong. From your question:
However the below scenario doesn't work properly consider a new sessionStorage allocated to a new window (Incorrect behavior):
This could be considered wrong behavior depending on how a browser actually implements it. From the above MDN entry:
... data stored in sessionStorage
gets cleared when the page session ends. A page session lasts for as long as the browser is open and survives over page reloads and restores. Opening a page in a new tab or window will cause a new session to be initiated, which differs from how session cookies work.
There is no mechanism to have an expiery after an amount of time for that kind of cache. As such my assumption is that you're already using a mechanism to actively keep track of that time (e.g. Expiry of sessionStorage).
You said the browser is some version of internet explorer but you didn't detail the configuration or user interaction. So my assumption is that the user restores the crashed session rather than open the page anew. The Microsoft documentatoin says that at least for IE 8 the cache should be discarded but it could be different for other versions. So you would have to inquire Microsoft and possibly open a bug with them. On the other hand with the MDN documentation and the official specificitons the behavior is perfectly valid:
The lifetime of a browsing context can be unrelated to the lifetime of the actual user agent process itself, as the user agent may support resuming sessions after a restart.
If you look for other questions regarding sessionStorage
and how it actually works you could get a better understanding of it. A good question with great answer seems to be the following: What is the difference between localStorage, sessionStorage, session and cookies?
Now for you question on how to handle it in a crashed browser: You can only handle it if the browser doesn't crash. Alternatively you could probably change your expiry mechanism to ignore sessions that are older than X but that would open you up different kinds of attacks so without getting into more detail what you actually do in your application, what that token consists of and what its role is there isn't much help that can be provided. If you are in control of the machine with the browser you could try to automate what's being detailed under "Security and Privacy » Clearing the Storage Area":
Clearing the Storage Areas
Session state is released as soon as the last window to reference that data is closed. However, users can clear storage areas at any time by selecting Delete Browsing History from the Tools menu in Internet Explorer, selecting the Cookies check box, and clicking OK. This clears session and local storage areas for all domains that are not in the Favorites folder and resets the storage quotas in the registry. Clear the Preserve Favorite Site Data check box to delete all storage areas, regardless of source.
To delete key/value pairs from a storage list, iterate over the collection with removeItem or use clear to remove all items at once. Keep in mind that changes to a local storage area are saved to disk asynchronously.