3 ms·
I'm currently implementing auth with JWTs. I've settled on shortlived access tokens and long lived refresh tokens. The refresh tokens get validated against a bl
by poxrud 6y ago
I'm currently implementing auth with JWTs. I've settled on shortlived access tokens and long lived refresh tokens. The refresh tokens get validated against a blacklist. This way you get the best of both worlds, you minimize db access while at the same time have the ability to revoke tokens.
Another thing one must be aware of with JWTs is protecting your users against XSS and CSRF's. Make sure your shortlived token is stored on localStorage and the refresh one is stored in a cookie.
- zacksinclair 6y agoWhy not store short lived token in a cookie as well?
- poxrud 6y agoBecause then you can be vulnerable to csrf attack. For example if someone tricks you into clicking www.mysite.com/api/delete-account
- deleted 6y ago[deleted]
- anaxag0ras 6y agoCSRF attacks can be prevented using same-site policy with cookies.
- poxrud 6y agoThat is true but it will not protect against all forms of CSRF, for example you'll be vulnerable if you have user generated content that's not sanitized properly. On the refresh_token cookie I have sameSite and httpOnly set.