# 基本スキャン
npm audit
# 自動修正(互換性維持)
npm audit fix
# JSON形式レポート
npm audit --json > report.json
# 本番依存のみチェック
npm audit --production
# 基本スキャン
yarn audit
# 重要度フィルタ
yarn audit --level=high
# インストール・設定
npm install -g snyk
snyk auth
# チェックと監視
snyk test
snyk monitor
.github/dependabot.yml
:
version: 2
updates:
- package-ecosystem: "npm"
directory: "/"
schedule:
interval: "weekly"
open-pull-requests-limit: 10
.github/workflows/security-audit.yml
:
name: Security Audit
on:
push:
branches: [ main ]
schedule:
- cron: '0 0 * * 0' # 毎週日曜実行
jobs:
security:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '18'
- run: npm ci
- run: npm audit --audit-level=high
{
"scripts": {
"security-check": "npm audit --json > security-report.json",
"security-fix": "npm audit fix && npm audit fix --force --production"
}
}
# 1. 詳細確認
npm audit
# 2. パッケージ更新
npm update vulnerable-package@^2.0.0
# 3. テスト実行
npm test
# 4. 再チェック
npm audit
// package.json
{
"overrides": {
"<vulnerable-package>": "<secure-version>"
}
}
Next.js 14.x および Node.js 18.x 以上を基準としています。