A JWT in localStorage was read by injected script
Locate the failed assumption, reproduce it, then repair the cause.
What actually caused it
An access token in localStorage is an ordinary string. Any script that runs on that origin can read it. There is no HttpOnly flag for localStorage, and document.cookie is a different store. When an attacker gets a script onto the page, through an unsanitized title, a compromised script tag, or a dependency that writes HTML, that script calls localStorage.getItem and sends the token to another host. The signature on the JWT does not stop this. The signature proves the identity provider minted the token. It does not control who in the browser is allowed to read the string. The attacker then calls your as the user until the token expires. A short lifetime limits the window. It does not close the read.
Minimal reproduction
Token written where script can read it
localStorage.setItem('access_token', jwt);
Page script, including injected script, can read this key.
The fix
Put the access token in a cookie marked HttpOnly, Secure, and SameSite. HttpOnly tells the browser to omit that cookie from document.cookie and from every script , while still sending it on requests to your origin. Do not also copy the same token into localStorage so a frontend helper can see it. That copy is the hole again. Keep the access token short-lived and rotate the refresh token on use. If a library's default storage is localStorage, change the default before the login page ships. Escaping HTML remains necessary, because script on your origin can still act as the user, but it can no longer lift the token out of the cookie jar.
Token stays in an HttpOnly cookie
res.json({ setCookie: 'access_token=' + jwt + '; HttpOnly; Secure; SameSite=Lax' });
The browser stores the cookie and does not expose it to script.