Decide whether to store a JWT in localStorage or a cookie
Where a token lives changes how browser code can use it. JavaScript on the same origin can read localStorage, including an injected script.
npm install --save-dev @sitecmd/cli
npx sitecmd audit .
The CLI runs on your computer or in your CI, and your code stays there.
What it finds on a demo project
The audit looks for auth tokens kept in localStorage or sessionStorage, session cookies set without HttpOnly, Secure or SameSite, and forms that use cookie authentication with no CSRF check.
SiteCMD CLI 2.0.0
Demo project: Login route and sign-in component
npx sitecmd audit .
SiteCMD Code Scan - .
Checked: November 9, 2026
Framework: React
Issues: 3 total | critical 0 | high 1 | medium 2 | low 0
High (1)
- [Security · security] No recognized local CSRF defense for a cookie-backed write - src/routes/login.js:12
Medium (2)
- [Security · security] Browser storage uses an authentication-like key - src/components/Login.jsx:7
- [Security · security] Cookie write lacks recognized explicit session hardening flags - src/routes/login.js:12
Your code passes? Now watch your site.
Compare localStorage and cookies for storing a JWT
An HttpOnly cookie keeps its value out of JavaScript cookie APIs. Page code can't read it, but the browser can still send it with requests. MDN's cookie reference explains the attribute.
Plan CSRF protection when you store a JWT in a cookie
For actions that use cookie authentication, use your framework's CSRF defense or a suitable token or origin check validated on the server. Moving a credential into a cookie doesn't decide which cross-site requests the server should accept. Follow OWASP's CSRF guidance.
See where Supabase and Auth0 store browser tokens
The Supabase JavaScript client sets
persistSessionto true by default and attempts to store the session in localStorage.The Auth0 SPA SDK stores tokens in memory by default. If you set
cacheLocationtolocalstorage, that storage persists across page refreshes and browser tabs.
Frequently asked questions
Is localStorage safe for auth tokens?
A successful same-origin script injection can read those tokens. OWASP advises against keeping session identifiers in localStorage. Review the storage and session design your auth library supports before changing where you keep credentials.
Connect token storage to verification and browser cookie settings
Website security
Catch leaked API keys and exposed files before someone uses them against you.
JWT decode vs verify
Separate reading a token from deciding whether to trust its claims.
Cookie security
Choose cookie attributes that fit your sign-in flow and limit unnecessary exposure.