Skip to content
Discussion options

You must be logged in to vote

I've used both approaches and the biggest issue with localStorage is token theft through XSS.

If an attacker can run JavaScript in your application, they can usually read anything stored in localStorage and send it elsewhere.

HttpOnly cookies help because the browser sends them automatically, but JavaScript can't read them directly.

That doesn't magically solve all security problems though. If you're using cookies, you still need to think about CSRF protection.

For internal tools and small projects I've seen localStorage used quite often because it's simple.

For applications handling sensitive user data, I'd generally prefer HttpOnly cookies with SameSite enabled and short-lived access to…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by karthikh4ck
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants