System Design · Middle · Question 13 of 75
Where is it safer to store a session token in the browser?
- ✓Correct answer: In a cookie with
HttpOnly,SecureandSameSite - 2In
localStorageso it's easy to read from JavaScript - 3In a global variable
window.token
Explanation
An HttpOnly cookie is inaccessible to scripts, so XSS can't steal it directly. SameSite reduces CSRF risk, Secure means HTTPS only. A token in localStorage can be read by any injected script. There's no fully safe storage under XSS - XSS protection is mandatory.