token-storage-security
できること
このスキルは、ウェブアプリがログイントークンをどこに保存し、スクリプトに盗まれる可能性があるかを確認します。サインインの仕組みを作ったりレビューしたりする開発者向けです。
使う場面
- ✓ウェブアプリがログイントークンを localStorage や sessionStorage に保存しているとき。
- ✓ウェブサイトの新しいサインインの仕組みを作るとき。
- ✓セキュリティレビューで、注入されたスクリプトがログイントークンを盗めるかが問われたとき。
スキルのリンク
https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/token-storage-security/SKILL.mdコピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。
使い方
いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。
貼り付け用メッセージ
Claude Code、Codex、Cursorの場合:プロジェクトのフォルダで実行するとスキルがインストールされます。
SKILL.mdをダウンロードして、エージェントのスキル用フォルダに入れてください。
AIへの頼み方の例
“私のアプリはログイントークンを localStorage に保存しています。これは安全ですか。どのように変えるべきですか。”
毎週5つの新しいスキル。1分で読めます。
仕組み
エージェントは、トークンの保存場所と、変更を伴うリクエストが偽造から守られているかを確認します。JavaScript で読めない安全な Cookie にトークンを移すことを提案します。
技術的な内容(元のSKILL.md)
作者による元のテキスト(英語)を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
よくある質問
localStorage がトークンにとって危険なのはなぜですか?
ページ上のどの JavaScript でも読めるため、一つの注入されたスクリプトですべてのトークンを奪われる可能性があるからです。
推奨する Cookie の設定は何ですか?
httpOnly と Secure、さらに SameSite を Strict か Lax にすることを推奨しています。
安全な Cookie だけで十分ですか?
いいえ。データを変更するリクエストには、CSRF と呼ばれる偽造リクエストへの対策も必要だとこのスキルは説明しています。
詳細
作者による元の説明
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.
人気
- GitHubのスター
- 75k
- ランキング
- #3059
- ライセンス
- MIT
- 更新日
- 2026/10/31
コメント
- …
このリポジトリの他のスキル
frontendchecklist
75kコマンドラインツールを使って、フロントエンドのコードとライブページを、アクセシビリティ、速度、SEO、セキュリティに関する380以上のルールと照らし合わせて確認します。
frontend-checklist-global
75kフロントエンドのプロジェクトを、386のFront-End Checklistのルールすべてと照らし合わせて監査し、見つかった問題ごとに具体的な修正方法を示します。
404-page
75k見つからないページの画面に役立つリンクがあり、本物の404ステータスを返すかを確認し、迷った訪問者が目的のページを見つけられるようにします。
about-page
75kサイトの運営者が誰かを説明する、分かりやすいAboutページがあるかを確認し、訪問者と検索エンジンからの信頼を高めます。
似ているスキル
reverse-engineer-anything
422kREAツールを使って、出荷済みのアプリやパッケージの中身を調べ、機能の説明、版の比較、再構築の手順をエージェントが支援します。
1password
394k1Password CLIをセットアップし、サインインして、秘密情報の値を会話に表示せずに読み取ったり注入したりするようエージェントを支援します。
healthcheck
394kOpenClawを動かすコンピューターやサーバーを、SSH、ファイアウォール、更新、バックアップなどのセキュリティリスクについて監査し、安全な修正案を提案するようエージェントを支援します。