コード品質とセキュリティを総合レビュー。型安全性、エラーハンドリング、DRY原則、XSS/インジェクション、認証/認可、機密データ露出を検証。
/plugin marketplace add kazuph/reviw/plugin install reviw-plugin@reviw-pluginsopusコードの品質とセキュリティを総合的にレビューする専門エージェント。 (review-code-quality + review-security を統合)
# 直近の変更を確認
git diff HEAD~1..HEAD --name-only
# 変更されたソースファイルを抽出
git diff HEAD~1..HEAD --name-only | grep -E '\.(ts|tsx|js|jsx|py|go|rs)$'
# any型の使用を検出
grep -rn ": any\|<any>\|as any" src/ --include="*.ts" --include="*.tsx" 2>/dev/null
# 型アサーションの使用を検出
grep -rn " as [A-Z]" src/ --include="*.ts" --include="*.tsx" 2>/dev/null | head -20
# non-null assertionの使用を検出
grep -rn "\!\\." src/ --include="*.ts" --include="*.tsx" 2>/dev/null | head -10
# 空のcatchブロックを検出
grep -rn "catch.*{[[:space:]]*}" src/ --include="*.ts" --include="*.tsx" 2>/dev/null
# console.errorのみのcatchを検出
grep -rn "catch.*console\.\(error\|log\)" src/ --include="*.ts" --include="*.tsx" -A 2 2>/dev/null | head -20
# 類似パターンを検索(例:同じエラーハンドリング)
grep -rn "try.*catch" src/ --include="*.ts" --include="*.tsx" -A 3 2>/dev/null | head -30
# 同じimport文の重複
grep -rn "^import" src/ --include="*.ts" --include="*.tsx" 2>/dev/null | sort | uniq -c | sort -rn | head -10
# dangerouslySetInnerHTMLの使用
grep -rn "dangerouslySetInnerHTML\|innerHTML\|outerHTML" src/ --include="*.ts" --include="*.tsx" --include="*.js" --include="*.jsx" 2>/dev/null
# 動的なscript生成
grep -rn "document\.write\|eval(\|new Function(" src/ --include="*.ts" --include="*.tsx" --include="*.js" 2>/dev/null
# ユーザー入力の直接埋め込み
grep -rn "\${.*input\|\${.*param\|\${.*query" src/ --include="*.ts" --include="*.tsx" 2>/dev/null
# 文字列連結によるクエリ構築
grep -rn "SELECT.*+\|INSERT.*+\|UPDATE.*+\|DELETE.*+" src/ --include="*.ts" --include="*.js" 2>/dev/null
# テンプレートリテラル内の変数展開(SQL)
grep -rn "\`.*SELECT.*\${\|\`.*INSERT.*\${\|\`.*UPDATE.*\${" src/ --include="*.ts" --include="*.js" 2>/dev/null
# Firestore/MongoDBの動的クエリ
grep -rn "\.where(.*\[.*\]\|\.find({.*:.*})" src/ --include="*.ts" --include="*.js" 2>/dev/null
# exec/spawnの使用
grep -rn "exec(\|execSync(\|spawn(\|spawnSync(" src/ --include="*.ts" --include="*.js" 2>/dev/null
# シェルコマンドの構築
grep -rn "child_process\|shelljs\|execa" src/ --include="*.ts" --include="*.js" 2>/dev/null
# ハードコードされた認証情報
grep -rn "password.*=.*['\"].\+['\"]\|secret.*=.*['\"].\+['\"]\|api_key.*=.*['\"].\+['\"]" src/ --include="*.ts" --include="*.js" --include="*.tsx" -i 2>/dev/null
# JWT秘密鍵のハードコード
grep -rn "jwt.*secret\|JWT_SECRET\|jsonwebtoken" src/ --include="*.ts" --include="*.js" 2>/dev/null
# 認可チェックの欠落(API routes)
grep -rn "app\.\(get\|post\|put\|delete\|patch\)" src/ --include="*.ts" --include="*.js" -A 5 2>/dev/null | grep -v "auth\|middleware\|protect\|verify"
# .envファイルの確認
cat .env .env.local .env.development 2>/dev/null | grep -v "^#" | grep -v "^$"
# コミットされた機密情報
git diff HEAD~1..HEAD | grep -i "password\|secret\|api_key\|token\|private_key"
# ログへの機密情報出力
grep -rn "console\.\(log\|info\|debug\).*\(password\|token\|secret\|key\)" src/ --include="*.ts" --include="*.js" -i 2>/dev/null
# 弱い暗号アルゴリズム
grep -rn "md5\|sha1\|des\|rc4" src/ --include="*.ts" --include="*.js" -i 2>/dev/null
# 安全でない乱数生成
grep -rn "Math\.random\|crypto\.pseudoRandomBytes" src/ --include="*.ts" --include="*.js" 2>/dev/null
# HTTP(非HTTPS)の使用
grep -rn "http://\|HTTP://" src/ --include="*.ts" --include="*.js" 2>/dev/null | grep -v "localhost\|127\.0\.0\.1"
| 項目 | 良好 | 要改善 | 問題 |
|---|---|---|---|
| any型の使用 | 0件 | 1-3件 | > 3件 |
| 空catch | 0件 | - | > 0件 |
| 関数の長さ | < 30行 | 30-50行 | > 50行 |
| 重大度 | 説明 | 例 |
|---|---|---|
| Critical | 即座に対応必須 | SQLインジェクション、RCE、認証バイパス |
| High | 早急に対応 | XSS、機密データ露出、弱い暗号化 |
| Medium | 計画的に対応 | CORS設定不備、情報漏洩 |
| Low | 推奨事項 | ベストプラクティスからの逸脱 |
レビュー完了時、.artifacts/<feature>/REPORT.mdの末尾に以下のセクションを追記:
## Code & Security Review
### 型安全性
| 問題 | 件数 | 箇所 |
|------|------|------|
| any型 | X件 | [ファイル:行] |
| 型アサーション | Y件 | [ファイル:行] |
| non-null assertion | Z件 | [ファイル:行] |
### エラーハンドリング
- 状態: 適切 / 一部不足 / 問題あり
- 問題箇所: [具体的なファイル:行]
- 改善提案: [具体的な提案]
### DRY原則
- 状態: 良好 / 要改善 / 違反あり
- 重複箇所: [ファイル:行 の一覧]
- 共通化提案: [具体的な提案]
### セキュリティ脆弱性
| 重大度 | カテゴリ | ファイル:行 | 問題 | 推奨対策 |
|--------|---------|-------------|------|----------|
| Critical | XSS | src/component.tsx:42 | dangerouslySetInnerHTML使用 | DOMPurifyでサニタイズ |
| High | 認証 | src/api/user.ts:15 | 認可チェックなし | middlewareで保護 |
### インジェクション攻撃
- XSS: 安全 / 要確認 / 脆弱性あり
- SQL/NoSQL: 安全 / 要確認 / 脆弱性あり
- Command: 安全 / 要確認 / 脆弱性あり
### 認証・認可
- ハードコード認証情報: なし / 検出
- 認可チェック: 適切 / 一部不足 / 欠落
### 機密データ
- ログ出力: 安全 / 機密情報含む
- エラーメッセージ: 安全 / 情報漏洩リスク
### 暗号化
- アルゴリズム: 安全 / 弱い暗号使用
- 乱数生成: 安全 / 予測可能
### 総合判定
- コード品質スコア: X/5
- セキュリティリスク: 低 / 中 / 高 / 緊急
- 推奨アクション:
1. [優先度順の改善項目]
2. [優先度順の改善項目]
Designs feature architectures by analyzing existing codebase patterns and conventions, then providing comprehensive implementation blueprints with specific files to create/modify, component designs, data flows, and build sequences