What is the best place to store JSON Web Tokens for authentication in SPA with NodeJS and (for example) AngularJS?
What I got so far:
Possible places:
- HTML5 Web Storage (localStorage / sessionStorage)
- Cookies
Web storage (localStorage / sessionStorage) is accessible via JavaScript in the same domain. This means that any JavaScript running on your site will have access to the web store and may therefore be vulnerable to cross-site scripting (XSS) attacks.
localStorage has a different expiration time, sessionStorage will be available only when and through the created window is open. localStorage lasts until you delete it or the user removes it.
Cookies when used with the HttpOnly cookie flag are not accessible via JavaScript and are not XSS responsive. Cookies, however, are vulnerable to sub-forgery (CSRF).
So what is the safest way to store JWT
Ole spaarmann
source share