linkedlist:

Cookie best-practices on the Frontend

#34 · · security, cookies, JWT

There seems to be some confusion about where to store authentication keys on the frontend. Do not use localstorage for that as it makes you susceptible to Cross-Site Scripting (XSS) attacks. Instead, you should use cookies. They have certain security measures that make stealing sensitive data less likely. When creating cookies, you should add the following attributes:

Also note that whether or not you are using JWT does not change that. JSON Web Tokens do not have to be stored in localstorage and they do not have to be transferred in an HTTP header. The JWT Specification does not mention any preferred way of transfer at all. A JWT absolutely can be securely stored in cookies.