Skip to content
Skillpedia
Security75k · #3059

token-storage-security

What it does

This skill checks how a web app stores login tokens and whether scripts could steal them. It is for developers building or reviewing sign-in systems.

When to use it

  • ✓When a web app stores login tokens in localStorage or sessionStorage.
  • ✓When someone sets up a new sign-in system for a website.
  • ✓When a security review asks whether injected scripts could steal login tokens.

Skill link

https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/token-storage-security/SKILL.md

Copy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.

How to use

The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.

Ready-to-paste message

Use this skill to help me: https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/token-storage-security/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
Want your AI to find skills like this on its own?Install the free Skillpedia MCP: one line, and it searches 15,000+ skills before each task.Install in 1 minute →

Example of what to ask your AI

“My app keeps the user's login token in localStorage. Is that safe, and how should I change it?”

5 new skills a week. 1 minute to read.

How it works

The agent checks where tokens are stored and whether changing requests are protected against forgery. It suggests moving tokens into secure cookies that JavaScript cannot read.

Technical content (original SKILL.md)

Original text by the author, straight from GitHub.

Store authentication tokens securely

localStorage is accessible to any JavaScript running on the page. A single XSS vulnerability — including one in a third-party script — can exfiltrate all tokens silently. httpOnly cookies are completely invisible to JavaScript; even if an attacker executes arbitrary code on the page, they cannot read the cookie. This single architectural choice eliminates the most common token theft vector.

Quick Reference

  • Store session tokens and JWTs in httpOnly cookies — not localStorage
  • localStorage is readable by any JavaScript on the page, including injected XSS code
  • Combine httpOnly with Secure and SameSite=Strict (or Lax) cookie flags
  • Use short-lived access tokens and rotate refresh tokens on each use
  • Protect every state-changing request with CSRF defenses, not cookie flags alone

Check

Check whether authentication tokens are stored in httpOnly cookies or in JavaScript-accessible storage like localStorage. Verify that POST, PUT, PATCH, and DELETE requests also require a CSRF token or an equivalent anti-forgery control.

Fix

Move token storage from localStorage/sessionStorage to httpOnly cookies set by the server, and ensure the cookies have Secure and SameSite flags. Add CSRF protection to every state-changing route that relies on browser-sent credentials.

Explain

Explain why localStorage is vulnerable to XSS token theft and how httpOnly cookies mitigate this attack vector.

Code Review

Review authentication flows, token storage calls, and API client code. Flag any use of localStorage.setItem, sessionStorage.setItem, or document.cookie for storing access tokens, JWTs, or session identifiers. Also flag credentialed mutations that lack a CSRF token, Origin check, or same-site enforcement.


For full implementation details, code examples, and framework-specific guidance, see references/rule.md.

Rule page: https://frontendchecklist.io/rules/security/token-storage-security

FAQ

Why is localStorage risky for tokens?

Any JavaScript on the page can read it, so one injected script can take every token.

Which cookie settings does the skill recommend?

It recommends httpOnly and Secure, plus SameSite set to Strict or Lax.

Are secure cookies enough on their own?

No. The skill says requests that change data still need protection against forged requests, called CSRF protection.

Details

Original description by the author

Use when reviewing authentication implementation, setting up a new auth system, or evaluating whether the current token storage approach exposes the application to XSS-based token theft.

repo: thedaviddias/Front-End-Checklist

Popularity

GitHub stars
75k
Ranking position
#3059
License
MIT
Updated
10/31/2026

Is this skill useful?

0

Sign in to vote.

Comments

  • …

More skills from this repository

Similar skills