csrf-protection
フォームやデータの変更処理を構築する際に、トークンやCookie、送信元の確認によって、悪意のあるサイトからの不正なリクエストを防ぎ、セキュリティを向上させるSkill。
📜 元の英語説明(参考)
Implement Cross-Site Request Forgery (CSRF) protection using tokens, SameSite cookies, and origin validation. Use when building forms and state-changing operations.
🇯🇵 日本人クリエイター向け解説
フォームやデータの変更処理を構築する際に、トークンやCookie、送信元の確認によって、悪意のあるサイトからの不正なリクエストを防ぎ、セキュリティを向上させるSkill。
※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。
下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o csrf-protection.zip https://jpskill.com/download/21384.zip && unzip -o csrf-protection.zip && rm csrf-protection.zip
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/21384.zip -OutFile "$d\csrf-protection.zip"; Expand-Archive "$d\csrf-protection.zip" -DestinationPath $d -Force; ri "$d\csrf-protection.zip"
完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。
💾 手動でダウンロードしたい(コマンドが難しい人向け)
- 1. 下の青いボタンを押して
csrf-protection.zipをダウンロード - 2. ZIPファイルをダブルクリックで解凍 →
csrf-protectionフォルダができる - 3. そのフォルダを
C:\Users\あなたの名前\.claude\skills\(Win)または~/.claude/skills/(Mac)へ移動 - 4. Claude Code を再起動
⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。
🎯 このSkillでできること
下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。
📦 インストール方法 (3ステップ)
- 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
- 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
- 3. 展開してできたフォルダを、ホームフォルダの
.claude/skills/に置く- · macOS / Linux:
~/.claude/skills/ - · Windows:
%USERPROFILE%\.claude\skills\
- · macOS / Linux:
Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。
詳しい使い方ガイドを見る →- 最終更新
- 2026-05-18
- 取得日時
- 2026-05-18
- 同梱ファイル
- 7
📖 Skill本文(日本語訳)
※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。
CSRF 保護
目次
概要
シンクロナイザートークン、ダブルサブミットクッキー、SameSite クッキー属性、およびカスタムヘッダーを使用して、包括的な Cross-Site Request Forgery 保護を実装します。
使用する状況
- フォーム送信
- 状態変更操作
- 認証システム
- 決済処理
- アカウント管理
- すべての POST/PUT/DELETE リクエスト
クイックスタート
最小限の動作例:
// csrf-protection.js
const crypto = require("crypto");
const csrf = require("csurf");
class CSRFProtection {
constructor() {
this.tokens = new Map();
this.tokenExpiry = 3600000; // 1 hour
}
/**
* Generate CSRF token
*/
generateToken() {
return crypto.randomBytes(32).toString("hex");
}
/**
* Create token for session
*/
createToken(sessionId) {
const token = this.generateToken();
const expiry = Date.now() + this.tokenExpiry;
this.tokens.set(sessionId, {
// ... (see reference guides for full implementation)
リファレンスガイド
references/ ディレクトリにある詳細な実装:
| ガイド | 内容 |
|---|---|
| Node.js/Express CSRF Protection | Node.js/Express CSRF 保護 |
| Double Submit Cookie Pattern | ダブルサブミットクッキーパターン |
| Python Flask CSRF Protection | Python Flask CSRF 保護 |
| Frontend CSRF Implementation | フロントエンド CSRF 実装 |
| Origin and Referer Validation | Origin および Referer 検証 |
ベストプラクティス
✅ 実施すべきこと
- すべての状態変更操作に CSRF トークンを使用する
- クッキーに SameSite=Strict を設定する
- Origin/Referer ヘッダーを検証する
- 安全でランダムなトークンを使用する
- トークンの有効期限を実装する
- HTTPS のみを使用する
- AJAX リクエストにトークンを含める
- CSRF 保護をテストする
❌ 実施すべきでないこと
- 認証済みリクエストの CSRF をスキップする
- 状態変更に GET を使用する
- Origin ヘッダーのみを信頼する
- トークンを再利用する
- トークンを localStorage に保存する
- 検証なしで CORS で資格情報を許可する
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開
CSRF Protection
Table of Contents
Overview
Implement comprehensive Cross-Site Request Forgery protection using synchronizer tokens, double-submit cookies, SameSite cookie attributes, and custom headers.
When to Use
- Form submissions
- State-changing operations
- Authentication systems
- Payment processing
- Account management
- Any POST/PUT/DELETE requests
Quick Start
Minimal working example:
// csrf-protection.js
const crypto = require("crypto");
const csrf = require("csurf");
class CSRFProtection {
constructor() {
this.tokens = new Map();
this.tokenExpiry = 3600000; // 1 hour
}
/**
* Generate CSRF token
*/
generateToken() {
return crypto.randomBytes(32).toString("hex");
}
/**
* Create token for session
*/
createToken(sessionId) {
const token = this.generateToken();
const expiry = Date.now() + this.tokenExpiry;
this.tokens.set(sessionId, {
// ... (see reference guides for full implementation)
Reference Guides
Detailed implementations in the references/ directory:
| Guide | Contents |
|---|---|
| Node.js/Express CSRF Protection | Node.js/Express CSRF Protection |
| Double Submit Cookie Pattern | Double Submit Cookie Pattern |
| Python Flask CSRF Protection | Python Flask CSRF Protection |
| Frontend CSRF Implementation | Frontend CSRF Implementation |
| Origin and Referer Validation | Origin and Referer Validation |
Best Practices
✅ DO
- Use CSRF tokens for all state-changing operations
- Set SameSite=Strict on cookies
- Validate Origin/Referer headers
- Use secure, random tokens
- Implement token expiration
- Use HTTPS only
- Include tokens in AJAX requests
- Test CSRF protection
❌ DON'T
- Skip CSRF for authenticated requests
- Use GET for state changes
- Trust Origin header alone
- Reuse tokens
- Store tokens in localStorage
- Allow credentials in CORS without validation
同梱ファイル
※ ZIPに含まれるファイル一覧。`SKILL.md` 本体に加え、参考資料・サンプル・スクリプトが入っている場合があります。
- 📄 SKILL.md (2,537 bytes)
- 📎 references/double-submit-cookie-pattern.md (1,885 bytes)
- 📎 references/frontend-csrf-implementation.md (2,844 bytes)
- 📎 references/nodejsexpress-csrf-protection.md (3,154 bytes)
- 📎 references/origin-and-referer-validation.md (796 bytes)
- 📎 references/python-flask-csrf-protection.md (2,202 bytes)
- 📎 scripts/security-checklist.sh (734 bytes)