Communityコーディング&開発github.com

mindrally/jwt-security

JWT認証を実装するためのガイドライン。トークンの生成、検証、保存に関するセキュリティベストプラクティスを提供します。

jwt-security とは?

このスキルは、JWT(JSON Web Token)認証を安全に実装するための包括的なガイドラインを提供します。トークンの生成、検証、保存におけるセキュリティベストプラクティスを網羅しており、開発者がよく陥りがちな脆弱性(署名検証の欠如、秘密鍵の漏洩、トークンの不正利用など)を防ぐのに役立ちます。主にWebアプリケーションやAPIの認証システムに適用でき、Claude CodeやCursorなどのAIエージェント向けに設計されています。このスキルは、JWTの署名アルゴリズムの選択、有効期限の設定、安全なキー管理、トークンの安全な保存方法、そしてクライアント側およびサーバー側での適切な検証手順を詳細に説明します。また、リフレッシュトークンの安全な実装方法や、JWTのペイロードに含めるべきではない機密情報についてもアドバイスを提供し、セキュアな認証フローの構築を支援します。

対応~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/mindrally/skills/tree/main/skills/jwt-security

Installed? Explore more コーディング&開発 skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

お気に入りのAIに質問する

このエージェントスキルを事前に読み込んだ状態で新しいチャットを開きます。

ドキュメント

jwt-security は何をしますか?

JWT認証を実装するためのガイドライン。トークンの生成、検証、保存に関するセキュリティベストプラクティスを提供します。

概要

このスキルは、JSON Web Token(JWT)を使用した認証システムの安全な実装を支援します。一般的なセキュリティの落とし穴を回避し、堅牢な認証フローを構築するための具体的なガイドラインを示します。

対象プラットフォーム

  • Claude Code
  • Cursor
  • Codex
  • その他のAIエージェント

セキュリティベストプラクティス

1. トークンの生成

  • 署名アルゴリズムにはRS256またはES256を使用する(HS256は避けること)
  • 秘密鍵は安全な場所(環境変数またはシークレット管理サービス)に保存する
  • トークンには最小限のクレーム(例:sub、exp、iat、jti)のみを含める
  • ペイロードに機密情報(パスワード、個人情報など)を含めない

2. トークンの検証

  • 署名検証は常にサーバー側で行う
  • 有効期限(exp)を厳密にチェックする
  • 発行者(iss)と対象者(aud)を検証する
  • アルゴリズム固定攻撃を防ぐため、受け入れるアルゴリズムを明示的に指定する

3. トークンの保存

  • クライアント側では、アクセストークンをHttpOnly Cookieに保存する(localStorageは避ける)
  • リフレッシュトークンはより長い有効期限を持つが、適切なローテーションを行う
  • トークンをログやエラーメッセージに含めない

4. 実装例

const jwt = require('jsonwebtoken');

// トークンの生成
function generateToken(userId) {
  const payload = {
    sub: userId,
    iat: Math.floor(Date.now() / 1000),
    exp: Math.floor(Date.now() / 1000) + (60 * 60), // 1時間
    jti: require('crypto').randomUUID()
  };
  return jwt.sign(payload, process.env.JWT_SECRET, { algorithm: 'RS256' });
}

// トークンの検証
function verifyToken(token) {
  try {
    const decoded = jwt.verify(token, process.env.JWT_PUBLIC_KEY, {
      algorithms: ['RS256'],
      issuer: 'my-app'
    });
    return decoded;
  } catch (err) {
    throw new Error('Invalid token');
  }
}

参考リンク

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

mindrally/accessibility-a11y

Implement web accessibility (a11y) best practices following WCAG guidelines to create inclusive, accessible user interfaces.

mindrally/chrome-extension-development

Expert guidelines for Chrome extension development with Manifest V3, covering security, performance, and best practices. Use when building browser extensions, creating popup UIs, implementing content scripts, working with Chrome APIs, managing extension permissions, or publishing to Chrome Web Store.

mindrally/computer-vision-opencv

Expert guidance for computer vision development using OpenCV, PyTorch, and modern deep learning techniques for image and video processing.

mindrally/data-analysis-jupyter

Expert guidance for data analysis, visualization, and Jupyter Notebook development with pandas, matplotlib, seaborn, and numpy.

mindrally/deep-learning-pytorch

Expert guidance for deep learning, transformers, diffusion models, and LLM development with PyTorch, Transformers, Diffusers, and Gradio.

mindrally/expo-react-native-typescript

Expert in Expo React Native TypeScript mobile development with best practices

mindrally/fastapi-python

Expert in FastAPI Python development with best practices for APIs and async operations

mindrally/framer-motion

Expert guidelines for building performant animations with Framer Motion/Motion library in React applications

mindrally/htmx

HTMX development guidelines for building dynamic web applications with minimal JavaScript using HTML attributes.

mindrally/machine-learning

Machine learning development with JAX, functional programming patterns, and high-performance computing.

mindrally/mysql-best-practices

MySQL development best practices for schema design, query optimization, and database administration

mindrally/nextjs-react-typescript

Expert in TypeScript, Node.js, Next.js App Router, React, Shadcn UI, Radix UI and Tailwind

mindrally/nextjs-typescript-tailwindcss-supabase

Full-stack Next.js 14 development with TypeScript, TailwindCSS, and Supabase for building production-ready web applications.

mindrally/odoo-development

Expert guidance for Odoo ERP development including Python ORM, XML views, and module architecture

mindrally/puppeteer-automation

Expert guidance for browser automation using Puppeteer with best practices for web scraping, testing, screenshot capture, and JavaScript execution in headless Chrome.

mindrally/redis-best-practices

Redis development best practices for caching, data structures, and high-performance key-value operations

mindrally/scrapy-web-scraping

Expert guidance for building web scrapers and crawlers using the Scrapy Python framework with best practices for spider development, data extraction, and pipeline management.

mindrally/scss-best-practices

SCSS/Sassy CSS best practices and coding guidelines for maintainable, scalable stylesheets

mindrally/typeorm

Guidelines for developing with TypeORM, a full-featured ORM for TypeScript and JavaScript supporting multiple databases

mindrally/web-scraping

Expert in web scraping and data extraction with Python tools

関連スキル