If you set cookie httpOnly, Javascript cannot see it. So some malicious third party library or XSS attacker cannot steal session. It can still do requests and cookies would be included, so stealing is the main difference.
Re:Stop using JWT for sessions (2016)
by deathanatos on Thursday November 01, 2018 @10:51AM
(#18354400)
https://portswigger.net/blog/web-storage-the-lesser-evil-for...
(It not only explains what others have said about httpOnly, but it also goes more in depth on the tradeoffs between the two.)
Re:Stop using JWT for sessions (2016)
by labourcurious on Thursday November 01, 2018 @10:48AM
(#18354376)
The author glosses over this but what they mean is that you can set the HttpOnly flag on cookies to prevent them from being accessed via JavaScript.
Re:Stop using JWT for sessions (2016)
by akarambir on Thursday November 01, 2018 @11:29AM
(#18354860)
But is it still sent automatically on ajax requests by browsers?
Re:Stop using JWT for sessions (2016)
by SahAssar on Thursday November 01, 2018 @03:01PM
(#18357269)
Yes.
> You can access cookies from Javascript, so how is localstorage worse?
You can access it via JS only if you don't set the httpOnly flag on the cookie.
edit: Thanks for the answers - httponly, makes sense.