I've heard the discussion many times of whether storing credentials or other sensitive info in localStorage or document.cookie is more secure. But I'm currently building a platform and I was wondering, which is actually more secure for storing a session token in: localStorage or document.cookie?
The reason I ask is because by my understanding (probably wrong though):
- LocalStorage can't be seen over HTTP requests, unlike document.cookie.
- LocalStorage is easier to set and view data than cookies.
- LocalStorage is much more simple (e.g. no expire times or anything like that)
But then if localStorage is so much better than document.cookie, I wonder why popular websites tend to use cookies instead.
Which one should I use and why?