|
|
|
|
|
by mooreds
545 days ago
|
|
But when you can use them, cookies are demonstrably better. XSS is the main argument against localstorage. Even this article[0], which pillories cookies, starts off with: ...if your website is vulnerable to XSS attacks, where a third party can run arbitrary scripts, your users’ tokens can be easily stolen [when stored in localstorage].
The reasons to avoid cookies:* APIs might require an authorization header in the browser fetch call. * APIs might live on a different domain, rendering cookies useless. CSRF is a danger, that's true. can be worked around. My understanding is that XSS has a wider scope and that many modern frameworks come with CSRF protection built in[1]. Whereas XSS is a risk any time you (or anyone in the future) includes any JS code on your website. 0: https://pilcrowonpaper.com/blog/local-storage-cookies/ 1: https://cheatsheetseries.owasp.org/cheatsheets/Cross-Site_Re... |
|
That's when you implement a BFF which manages your tokens and shares a session cookie with your frontend while proxying all requests to your APIs. And as said, you "just" have to setup a way for your BFF to share CSRF tokens with your frontend.