本文へスキップ
Skillpedia
セキュリティ75k · #3059

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がスキルを読んで指示に従います。

貼り付け用メッセージ

このスキルを使って手伝ってください:https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/token-storage-security/SKILL.md このリンクのSKILL.mdファイルを読んで、私の作業でその指示に従ってください。
こういうスキルを、AIが自分で見つけてくれたら?無料のSkillpedia MCPをインストール。1行で、作業の前に15,000+のスキルから探してくれます。1分でインストール →

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.

repo: thedaviddias/Front-End-Checklist

人気

GitHubのスター
75k
ランキング
#3059
ライセンス
MIT
更新日
2026/10/31

このスキルは役に立ちますか?

0

ログイン して投票しましょう。

コメント

  • …

このリポジトリの他のスキル

似ているスキル