Joey Masip Romeu
1 min readJul 9, 2019

--

A JWT needs to be stored in a safe place inside the user’s browser.

If you store it inside localStorage, it’s accessible by any script inside your page (which is as bad as it sounds as an XSS attack can let an external attacker get access to the token).

Don’t store it in local storage (or session storage). If any of the 3rd part scripts you include in your page gets compromised, it can access all your users’ tokens.

The JWT needs to be stored inside an HttpOnly cookie, a special kind of cookie that’s only sent in HTTP requests to the server, and it’s never accessible (both for reading or writing) from JavaScript running in the browser.

Taken from this JWT best practices blog post

--

--

Joey Masip Romeu
Joey Masip Romeu

Written by Joey Masip Romeu

Coder, Entrepreneur, Co-founder at SlowCode

No responses yet