mcpField
D
dependency-scanning

dependency-scanning

github.com/bagelholeセキュリティ1.2k364 回インストール23 週間前に更新
リポジトリ

dependency-scanning について

dependency-scanningは、サードパーティライブラリの脆弱性を特定するためのセキュリティスキルです。サプライチェーン対策、コンプライアンス、自動スキャンに向け、多言語のスキャナー例、CI/CD設定、SBOM生成をまとめています。

主な機能

  1. 01依存関係スキャンツールの比較
  2. 02言語別監査コマンドの紹介
  3. 03CI/CDスキャン設定例
  4. 04CycloneDXまたはSPDX形式のSBOM生成
  5. 05脆弱性アラートと例外対応の説明

活用シーン

  1. 01ビルド時の依存関係スキャン
  2. 02ソフトウェア構成分析要件への対応
  3. 03SBOMの生成と追跡
  4. 04未修正の脆弱性や誤検知への対処

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/bagelhole/devops-security-agent-skills --skill dependency-scanning

インストール後、Claude Code で/dependency-scanningを入力して読み込まれたか確認します。

詳細

依存関係のスキャン

サードパーティの依存関係やライブラリに含まれる脆弱性を特定します。

このスキルを使用するタイミング

次のような場合に、このスキルを使用します。

  • サードパーティの依存関係を管理する
  • ソフトウェア構成分析を実装する
  • コンプライアンス要件に対応する
  • ソフトウェアサプライチェーンを保護する
  • 脆弱性の検出を自動化する

前提条件

  • パッケージマニフェストファイル(package.json、requirements.txt など)
  • CI/CD パイプラインへのアクセス
  • 依存関係スキャンツール

ツールの比較

ツール種類言語最適な用途
Snyk商用/無料多数包括的な SCA
Dependabot無料(GitHub)多数PR の自動作成
OWASP Dep-CheckOSS多数無料のスキャン
npm audit組み込みNode.js手軽なチェック
pip-auditOSSPythonPython プロジェクト
TrivyOSS多数コンテナの依存関係

Snyk

CLI の使用方法
# Install
npm install -g snyk

# Authenticate
snyk auth

# Test project
snyk test

# Monitor project (track over time)
snyk monitor

# Test specific manifest
snyk test --file=package.json
snyk test --file=requirements.txt

# Output formats
snyk test --json > snyk-results.json
snyk test --sarif > snyk-results.sarif

# Fix vulnerabilities
snyk fix

# Ignore vulnerability
snyk ignore --id=SNYK-JS-LODASH-567746 --expiry=2024-12-31 --reason="No exploit path"
CI との統合
# .github/workflows/snyk.yml
name: Snyk Security

on:
  push:
    branches: [main]
  pull_request:

jobs:
  snyk:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Run Snyk to check for vulnerabilities
        uses: snyk/actions/node@master
        env:
          SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
        with:
          args: --severity-threshold=high

      - name: Upload results to GitHub
        uses: github/codeql-action/upload-sarif@v3
        with:
          sarif_file: snyk.sarif
ポリシーファイル
# .snyk
version: v1.25.0
ignore:
  SNYK-JS-LODASH-567746:
    - '*':
        reason: No user input reaches this function
        expires: 2024-12-31
        created: 2024-01-15

  'snyk:lic:npm:gpl-3.0':
    - '*':
        reason: Internal use only
        
patch: {}

GitHub Dependabot

設定
# .github/dependabot.yml
version: 2
updates:
  # JavaScript/Node.js
  - package-ecosystem: "npm"
    directory: "/"
    schedule:
      interval: "weekly"
      day: "monday"
    open-pull-requests-limit: 10
    reviewers:
      - "security-team"
    labels:
      - "dependencies"
      - "security"
    ignore:
      - dependency-name: "aws-sdk"
        update-types: ["version-update:semver-major"]
    groups:
      development-dependencies:
        dependency-type: "development"
        update-types:
          - "minor"
          - "patch"

  # Python
  - package-ecosystem: "pip"
    directory: "/"
    schedule:
      interval: "daily"
    
  # Docker
  - package-ecosystem: "docker"
    directory: "/"
    schedule:
      interval: "weekly"
    
  # GitHub Actions
  - package-ecosystem: "github-actions"
    directory: "/"
    schedule:
      interval: "weekly"
セキュリティアラート
# Automated security updates
# Enable in repository Settings > Security > Dependabot

# Dependabot will automatically:
# - Create PRs for vulnerable dependencies
# - Update to patched versions
# - Provide CVE details in PR description

OWASP Dependency-Check

インストール
# Download
wget https://github.com/jeremylong/DependencyCheck/releases/download/v9.0.0/dependency-check-9.0.0-release.zip
unzip dependency-check-9.0.0-release.zip

# Or via Homebrew
brew install dependency-check
使用方法
# Scan project
dependency-check --project "MyProject" \
  --scan /path/to/project \
  --out /path/to/reports \
  --format HTML \
  --format JSON

# With specific analyzers
dependency-check --project "MyProject" \
  --scan . \
  --enableExperimental \
  --disableRetireJS

# CI configuration
dependency-check --project "MyProject" \
  --scan . \
  --format JSON \
  --failOnCVSS 7 \
  --suppression suppression.xml
抑制ファイル

<?xml version="1.0" encoding="UTF-8"?>
<suppressions xmlns="https://jeremylong.github.io/DependencyCheck/dependency-suppression.1.3.xsd">
  <suppress>
    <notes>False positive - not using vulnerable function</notes>
    <packageUrl regex="true">^pkg:npm/lodash@.*$</packageUrl>
    <cve>CVE-2021-23337</cve>
  </suppress>
  
  <suppress until="2024-12-31">
    <notes>Risk accepted - mitigated by WAF</notes>
    <cpe>cpe:/a:apache:struts:2.5.0</cpe>
    <vulnerabilityName>CVE-2023-12345</vulnerabilityName>
  </suppress>
</suppressions>
Maven との統合

<plugin>
  <groupId>org.owasp</groupId>
  <artifactId>dependency-check-maven</artifactId>
  <version>9.0.0</version>
  <configuration>
    <failBuildOnCVSS>7</failBuildOnCVSS>
    <suppressionFiles>
      <suppressionFile>suppression.xml</suppressionFile>
    </suppressionFiles>
  </configuration>
  <executions>
    <execution>
      <goals>
        <goal>check</goal>
      </goals>
    </execution>
  </executions>
</plugin>

言語別ツール

Node.js(npm audit)
# Run audit
npm audit

# JSON output
npm audit --json

# Fix automatically
npm audit fix

# Fix with breaking changes
npm audit fix --force

# Production only
npm audit --production
Python(pip-audit)
# Install
pip install pip-audit

# Scan installed packages
pip-audit

# Scan requirements file
pip-audit -r requirements.txt

# Output formats
pip-audit --format json
pip-audit --format cyclonedx-json

# Fix vulnerabilities
pip-audit --fix
Go(govulncheck)
# Install
go install golang.org/x/vuln/cmd/govulncheck@latest

# Scan project
govulncheck ./...

# JSON output
govulncheck -json ./...
Ruby(bundler-audit)
# Install
gem install bundler-audit

# Update database
bundle-audit update

# Run audit
bundle-audit check

# Output format
bundle-audit check --format json

SBOM の生成

CycloneDX
# Node.js
npx @cyclonedx/cyclonedx-npm --output-file sbom.json

# Python
pip install cyclonedx-bom
cyclonedx-py -o sbom.json

# Go
go install github.com/CycloneDX/cyclonedx-gomod/cmd/cyclonedx-gomod@latest
cyclonedx-gomod mod -json > sbom.json
Syft
# Install
curl -sSfL https://raw.githubusercontent.com/anchore/syft/main/install.sh | sh -s

# Generate SBOM
syft dir:/path/to/project -o cyclonedx-json > sbom.json
syft dir:/path/to/project -o spdx-json > sbom-spdx.json

# From container
syft myimage:latest -o cyclonedx-json > sbom.json

CI/CD パイプライン

# Comprehensive dependency scanning
name: Dependency Security

on:
  push:
    branches: [main]
  pull_request:
  schedule:
    - cron: '0 8 * * *'

jobs:
  scan:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: npm audit
        run: npm audit --audit-level=high

      - name: Snyk scan
        uses: snyk/actions/node@master
        env:
          SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
        with:
          args: --severity-threshold=high
          
      - name: Generate SBOM
        run: npx @cyclonedx/cyclonedx-npm --output-file sbom.json

      - name: Upload SBOM
        uses: actions/upload-artifact@v4
        with:
          name: sbom
          path: sbom.json

よくある問題

問題:アラートが多すぎる

問題:脆弱性の数に圧倒される
解決策:悪用可能性に基づいて優先順位を付け、深刻度で絞り込みます。

問題:修正プログラムがない

問題:脆弱な依存関係にパッチがない
解決策:代替手段を検討し、代替策となるセキュリティ対策を実施します。

問題:更新による破損

問題:セキュリティ修正によって機能が壊れる
解決策:変更履歴を確認し、十分にテストして、ロックファイルを使用します。

ベストプラクティス

  • ビルドのたびにスキャンする
  • 再現性を確保するためにロックファイルを使用する
  • 深刻度のしきい値を設定する
  • SBOM を生成して追跡する
  • 例外を適切に記録する
  • 依存関係を定期的に更新する
  • 新たな脆弱性を監視する
  • 更新用 PR の作成を自動化する

関連スキル

コメント