This article from Auth0 recommend storing the JWT locally in a local storage (or cookie). But this article from OWASP recommend not to story any sensitive data locally (not even sessionStorage)
So, is it safe to store the JWT token locally or not?
This article from Auth0 recommend storing the JWT locally in a local storage (or cookie). But this article from OWASP recommend not to story any sensitive data locally (not even sessionStorage)
So, is it safe to store the JWT token locally or not?
How bizarre! I asked basically the same question about a month ago.
In the end, we decided that using localstorage for the JWT token was ok, as long as we also did the following on the HTTP level:
localhost:4200
The above will give you an A/A+ on securityheaders.io, and will prevent the most common attacks (somebody embedding your website in an iframe, and extracting data from localstorage, for example).
Well it depends. If you have an XSS vulnerability within your application an attacker can extract and use the JWT from your local storage.
A method I've used and I think Auth0 indicate is to use the cookie as the JWT storage and use the flags HTTP Only and Secure this way if you have an XSS vulnerability the cookie cannot be read and is only transported in a secure manner. CSRF is less of a risk these days as all the modern frameworks include CSRF mitigation.
This would mean validation extracts the JWT from the cookie on the server side to validate. My personal view is to use a cookie as storage as CSRF is easier to find and mitigate when compared to XSS attacks which have a large attack surface.