Hint
localStorage is XSS-vulnerable; HttpOnly cookies are inaccessible to JS but need CSRF protection
localStorage
document.cookie — wait, actually localStorage.getItem('token').Authorization: Bearer <token>.HttpOnly cookie
HttpOnly flag prevents JavaScript from reading the cookie — XSS cannot steal it.Secure flag ensures it only travels over HTTPS.SameSite=Strict/Lax prevents CSRF — cookie not sent on cross-origin requests.Set-Cookie: token=<jwt>; HttpOnly; Secure; SameSite=Strict; Path=/
Verdict: HttpOnly cookies are strictly more secure. The main downside is CSRF risk (mitigated by SameSite) and that the token is sent on every request (including non-API routes) — use a short Path to scope it.