amey-thakur/ai-skills/browser-storage-safety
Claude Code and agent skill by amey-thakur/ai-skills
- community
Checking that the SKILL.md file is still in the repository.
Decide where a web app keeps tokens and state by reasoning about the XSS blast radius of each store, not by convenience. Use when choosing how to persist session tokens, auth state, or any value an attacker on your origin would want to read.
Install
npx vskill@latest install amey-thakur/ai-skills/browser-storage-safetySKILL.md
The same SKILL.md was published earlier as amey-thakur/ai-skills/browser-storage-safety.
Browser storage safety
Every storage choice is a wager on the day your page runs attacker JavaScript. localStorage is readable by any script on the origin; a cookie can be closed to scripts entirely. The tempting default, a JWT in localStorage, hands your sessions to the first cross-site scripting flaw and lets the token walk out to be replayed later. Choose the store by how much a single injection can steal.
Method
- Keep the session token in an HttpOnly cookie. With
HttpOnlyset,
injected script cannot read the token through document.cookie. An XSS can still act while the tab is open, but it cannot lift the token and reuse it from another machine an hour later.
- Refuse localStorage for anything secret.
localStorageand
sessionStorage are cleartext and origin-readable, so one line of injected script reads every key at once. Reserve them for non-secret UI state: theme, last tab, a draft whose leak would not matter.
- Set the full cookie attribute set. Add
Secureso it rides only HTTPS,
SameSite=Lax or Strict to blunt cross-site request forgery, and a __Host- prefix to bind it to the exact origin with no Domain widening. Keep Path no broader than the routes that need it.
- Add a CSRF token where SameSite does not reach.
SameSitecuts most
cross-site forgery but not every case, so verify a per-session anti-CSRF token or require a custom request header on state-changing calls.
- Consider an in-memory access token for SPAs. Hold a short-lived access
token in a JavaScript variable and refresh it from an HttpOnly cookie: it never touches disk and dies on reload. The cost is a refresh call on each page load.
- Fix the XSS, because storage only caps the damage. A strict
Content-Security-Policy, output encoding, and framework auto-escaping stop the injection that makes storage moot. Cookie flags shrink the blast radius; they do not close the hole that opened it.
Litmus tests
- If an attacker runs one line of script on your origin, can they exfiltrate
the long-lived token, or only act while the tab is open?
- Is the session cookie
HttpOnly,Secure,SameSite, and__Host-
prefixed where possible?
- Does
localStoragehold only values whose leak would not compromise anyone? - Do state-changing requests carry protection beyond SameSite alone?
Boundaries
This limits XSS blast radius through storage choice; it does not prevent XSS (that is encoding and CSP) or design the token lifecycle (see jwt-handling). Native apps and server-rendered sessions follow other models. When an auth library sets its own cookie policy, verify the flags rather than trust them.
Security
- Security scanPassed, 95 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/security/browser-storage-safety/SKILL.md
Popularity
- Repository stars
- 10
- Repository forks
- 2
- 7-day trend score
- 17
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/amey-thakur/ai-skills/browser-storage-safety)