A comprehensive guide to authentication security in modern web applications, covering the progression from localStorage JWT storage (vulnerable to XSS exfiltration) through in-memory tokens, httpOnly cookies with CSRF defenses, server-side sessions vs JWTs, OAuth refresh token rotation, and the Backend for Frontend (BFF) pattern. Key recommendations: store sessions in httpOnly cookies backed by a server-side session store, use CSRF tokens plus SameSite and Origin header checks, and for OAuth flows move all token handling behind a BFF so the browser never holds tokens. Also covers the emerging infostealer/pass-the-cookie threat and Chrome's Device Bound Session Credentials (DBSC) as a hardware-level defense. Includes React-specific code for collapsing concurrent refresh requests into a single in-flight promise.
Table of contents
The version from every tutorial πWhat XSS does to that token πβIf they can run JS, youβre already deadβ πAttempt two: hold it in memory πAttempt three: the httpOnly cookie πCSRF πSessions vs JWTs πWhere JWTs work πOAuth πCan we make it more secure? πThe NEW threat πApps overview πReferences π31.3K Impressions1 Comment