jpskill.com
🛠️ 開発・MCP コミュニティ

sast-semgrep

Semgrepを活用し、OWASPやCWEといったセキュリティフレームワークに沿って、コードの脆弱性検出やセキュアなコーディング指導を行い、CI/CDパイプラインへの統合や組織独自のルール適用も実現するSkill。

📜 元の英語説明(参考)

Static application security testing (SAST) using Semgrep for vulnerability detection, security code review, and secure coding guidance with OWASP and CWE framework mapping. Use when: (1) Scanning code for security vulnerabilities across multiple languages, (2) Performing security code reviews with pattern-based detection, (3) Integrating SAST checks into CI/CD pipelines, (4) Providing remediation guidance with OWASP Top 10 and CWE mappings, (5) Creating custom security rules for organization-specific patterns, (6) Analyzing dependencies for known vulnerabilities.

🇯🇵 日本人クリエイター向け解説

一言でいうと

Semgrepを活用し、OWASPやCWEといったセキュリティフレームワークに沿って、コードの脆弱性検出やセキュアなコーディング指導を行い、CI/CDパイプラインへの統合や組織独自のルール適用も実現するSkill。

※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。

⚡ おすすめ: コマンド1行でインストール(60秒)

下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。

🍎 Mac / 🐧 Linux
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o sast-semgrep.zip https://jpskill.com/download/17039.zip && unzip -o sast-semgrep.zip && rm sast-semgrep.zip
🪟 Windows (PowerShell)
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/17039.zip -OutFile "$d\sast-semgrep.zip"; Expand-Archive "$d\sast-semgrep.zip" -DestinationPath $d -Force; ri "$d\sast-semgrep.zip"

完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。

💾 手動でダウンロードしたい(コマンドが難しい人向け)
  1. 1. 下の青いボタンを押して sast-semgrep.zip をダウンロード
  2. 2. ZIPファイルをダブルクリックで解凍 → sast-semgrep フォルダができる
  3. 3. そのフォルダを C:\Users\あなたの名前\.claude\skills\(Win)または ~/.claude/skills/(Mac)へ移動
  4. 4. Claude Code を再起動

⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。

🎯 このSkillでできること

下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。

📦 インストール方法 (3ステップ)

  1. 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
  2. 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
  3. 3. 展開してできたフォルダを、ホームフォルダの .claude/skills/ に置く
    • · macOS / Linux: ~/.claude/skills/
    • · Windows: %USERPROFILE%\.claude\skills\

Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。

詳しい使い方ガイドを見る →
最終更新
2026-05-18
取得日時
2026-05-18
同梱ファイル
9

📖 Skill本文(日本語訳)

※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。

SAST with Semgrep

概要

高速なオープンソースの静的解析ツールである Semgrep を使用して、包括的な静的アプリケーションセキュリティテストを実行します。このスキルは、自動化された脆弱性検出、セキュリティコードレビューワークフロー、および OWASP Top 10 および CWE 標準にマッピングされた修正ガイダンスを提供します。

クイックスタート

コードベースのセキュリティ脆弱性をスキャンします。

semgrep --config=auto --severity=ERROR --severity=WARNING /path/to/code

OWASP Top 10 ルールセットで実行します。

semgrep --config="p/owasp-top-ten" /path/to/code

コアワークフロー

ワークフロー 1: 初期セキュリティスキャン

  1. コードベースの主要な言語を特定します
  2. 適切なルールセットで scripts/semgrep_scan.py を実行します
  3. 検出結果を解析し、重要度 (CRITICAL、HIGH、MEDIUM、LOW) で分類します
  4. 検出結果を OWASP Top 10 および CWE カテゴリにマッピングします
  5. 優先順位付けされた修正レポートを生成します

ワークフロー 2: セキュリティコードレビュー

  1. プルリクエストまたはコミットの場合、変更されたファイルに対してターゲットを絞ったスキャンを実行します
  2. semgrep --diff を使用して、変更されたコードのみをスキャンします
  3. 重大な検出結果をブロックする問題としてフラグを立てます
  4. references/remediation_guide.md からインライン修正ガイダンスを提供します
  5. 検出結果を安全なコーディングパターンにリンクします

ワークフロー 3: カスタムルール開発

  1. 組織固有の検出するセキュリティパターンを特定します
  2. assets/rule_template.yaml を使用して、YAML 形式でカスタム Semgrep ルールを作成します
  3. 既知の脆弱なコードサンプルに対してルールをテストします
  4. カスタムルールを CI/CD パイプラインに統合します
  5. references/custom_rules.md にルールを文書化します

ワークフロー 4: CI/CD 統合

  1. assets/ci_config_examples/ を使用して、Semgrep を CI/CD パイプラインに追加します
  2. プルリクエストのベースラインスキャンを設定します
  3. 重要度のしきい値を設定します (CRITICAL/HIGH で失敗)
  4. セキュリティダッシュボード用の SARIF 出力を生成します
  5. メトリクス (検出された脆弱性、修正率、誤検知) を追跡します

セキュリティに関する考慮事項

  • 機密データの取り扱い: Semgrep はローカルでコードをスキャンします。スキャン結果がシークレットまたは独自のコードパターンをリークしないようにしてください。出力を制限するには、--max-lines-per-finding を使用します。

  • アクセス制御: Semgrep スキャンにはソースコードへの読み取りアクセスが必要です。スキャン結果へのアクセスを、承認されたセキュリティチームおよび開発チームに制限します。

  • 監査ログ: コンプライアンス監査のために、タイムスタンプ、ユーザー、コミットハッシュ、および検出結果数を含むすべてのスキャン実行をログに記録します。

  • コンプライアンス: SAST スキャンは、SOC2、PCI-DSS、および GDPR コンプライアンス要件をサポートします。スキャン履歴と修正追跡を維持します。

  • 安全なデフォルト: バランスの取れた検出には、--config=auto を使用します。セキュリティが重要なアプリケーションの場合は、包括的なカバレッジのために --config="p/security-audit" を使用します。

言語サポート

Semgrep は、次の 30 以上の言語をサポートしています。

  • Web: JavaScript、TypeScript、Python、Ruby、PHP、Java、C#、Go
  • モバイル: Swift、Kotlin、Java (Android)
  • インフラストラクチャ: Terraform、Dockerfile、YAML、JSON
  • その他: C、C++、Rust、Scala、Solidity

バンドルされたリソース

スクリプト

  • scripts/semgrep_scan.py - OWASP/CWE マッピングとレポートを備えたフル機能のスキャン
  • scripts/baseline_scan.sh - CI/CD 用のクイックベースラインスキャン
  • scripts/diff_scan.sh - 変更されたファイルのみをスキャンします (PR 用)

参考文献

  • references/owasp_cwe_mapping.md - Semgrep ルールを使用した OWASP Top 10 から CWE へのマッピング
  • references/remediation_guide.md - カテゴリ別の脆弱性修正パターン
  • references/rule_library.md - 厳選された便利な Semgrep ルールセットのリスト

アセット

  • assets/rule_template.yaml - カスタム Semgrep ルールを作成するためのテンプレート
  • assets/ci_config_examples/ - CI/CD 統合の例 (GitHub Actions、GitLab CI)
  • assets/semgrep_config.yaml - 推奨される Semgrep 構成

一般的なパターン

パターン 1: 毎日のセキュリティベースラインスキャン

# 包括的なスキャンを実行し、レポートを生成します
scripts/semgrep_scan.py --config security-audit \
  --output results.json \
  --format json \
  --severity HIGH CRITICAL

パターン 2: プルリクエストセキュリティゲート

# 変更されたファイルのみをスキャンし、HIGH/CRITICAL で失敗します
scripts/diff_scan.sh --fail-on high \
  --base-branch main \
  --output sarif

パターン 3: 脆弱性調査

# 特定の脆弱性パターンを検索します
semgrep --config "r/javascript.lang.security.audit.xss" \
  --json /path/to/code | jq '.results'

パターン 4: カスタムルール検証

# 脆弱なサンプルに対してカスタムルールをテストします
semgrep --config assets/custom_rules.yaml \
  --test tests/vulnerable_samples/

統合ポイント

CI/CD 統合

  • GitHub Actions: SARIF アップロードで semgrep/semgrep-action@v1 を使用します
  • GitLab CI: アーティファクトレポートを使用して、セキュリティスキャンジョブとして実行します
  • Jenkins: 品質ゲート統合を使用して、ビルドステップとして実行します
  • pre-commit hooks: ステージングされたファイルに対して軽量スキャンを実行します

すぐに使用できる構成については、assets/ci_config_examples/ を参照してください。

セキュリティツール統合

  • SIEM/SOAR: 取り込みのために JSON/SARIF で検出結果をエクスポートします
  • 脆弱性管理: Jira、DefectDojo、または ThreadFix と統合します
  • IDE 統合: リアルタイム検出のために Semgrep IDE プラグインを使用します
  • シークレットスキャン: trufflehog、gitleaks などのツールと組み合わせます

SDLC 統合

  • 要件フェーズ: セキュリティ要件とカスタムルールを定義します
  • 開発: IDE プラグインはリアルタイムフィードバックを提供します
  • コードレビュー: PR ワークフローでの自動化されたセキュリティレビュー
  • テスト: セキュリティテストフレームワークと統合します
  • デプロイメント: 本番環境前の最終セキュリティゲート

重要度分類

Semgrep の検出結果は、重要度によって分類されます。

  • CRITICAL: 悪用可能な脆弱性 (SQLi、RCE、認証バイパス)
  • HIGH: 重大なセキュリティリスク (XSS、CSRF、機密データ漏洩)
  • MEDIUM: セキュリティの脆弱性 (脆弱な暗号化、検証の欠落)
  • LOW: セキュリティへの影響があるコード品質の問題
  • INFO: セキュリティのベストプラクティスの推奨事項

パフォーマンスの最適化

大規模なコードベースの場合:

# 並列スキャンには --jobs を使用します
semgrep --co
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開

SAST with Semgrep

Overview

Perform comprehensive static application security testing using Semgrep, a fast, open-source static analysis tool. This skill provides automated vulnerability detection, security code review workflows, and remediation guidance mapped to OWASP Top 10 and CWE standards.

Quick Start

Scan a codebase for security vulnerabilities:

semgrep --config=auto --severity=ERROR --severity=WARNING /path/to/code

Run with OWASP Top 10 ruleset:

semgrep --config="p/owasp-top-ten" /path/to/code

Core Workflows

Workflow 1: Initial Security Scan

  1. Identify the primary languages in the codebase
  2. Run scripts/semgrep_scan.py with appropriate rulesets
  3. Parse findings and categorize by severity (CRITICAL, HIGH, MEDIUM, LOW)
  4. Map findings to OWASP Top 10 and CWE categories
  5. Generate prioritized remediation report

Workflow 2: Security Code Review

  1. For pull requests or commits, run targeted scans on changed files
  2. Use semgrep --diff to scan only modified code
  3. Flag high-severity findings as blocking issues
  4. Provide inline remediation guidance from references/remediation_guide.md
  5. Link findings to secure coding patterns

Workflow 3: Custom Rule Development

  1. Identify organization-specific security patterns to detect
  2. Create custom Semgrep rules in YAML format using assets/rule_template.yaml
  3. Test rules against known vulnerable code samples
  4. Integrate custom rules into CI/CD pipeline
  5. Document rules in references/custom_rules.md

Workflow 4: CI/CD Integration

  1. Add Semgrep to CI/CD pipeline using assets/ci_config_examples/
  2. Configure baseline scanning for pull requests
  3. Set severity thresholds (fail on CRITICAL/HIGH)
  4. Generate SARIF output for security dashboards
  5. Track metrics: vulnerabilities found, fix rate, false positives

Security Considerations

  • Sensitive Data Handling: Semgrep scans code locally; ensure scan results don't leak secrets or proprietary code patterns. Use --max-lines-per-finding to limit output.

  • Access Control: Semgrep scans require read access to source code. Restrict scan result access to authorized security and development teams.

  • Audit Logging: Log all scan executions with timestamps, user, commit hash, and findings count for compliance auditing.

  • Compliance: SAST scanning supports SOC2, PCI-DSS, and GDPR compliance requirements. Maintain scan history and remediation tracking.

  • Safe Defaults: Use --config=auto for balanced detection. For security-critical applications, use --config="p/security-audit" for comprehensive coverage.

Language Support

Semgrep supports 30+ languages including:

  • Web: JavaScript, TypeScript, Python, Ruby, PHP, Java, C#, Go
  • Mobile: Swift, Kotlin, Java (Android)
  • Infrastructure: Terraform, Dockerfile, YAML, JSON
  • Other: C, C++, Rust, Scala, Solidity

Bundled Resources

Scripts

  • scripts/semgrep_scan.py - Full-featured scanning with OWASP/CWE mapping and reporting
  • scripts/baseline_scan.sh - Quick baseline scan for CI/CD
  • scripts/diff_scan.sh - Scan only changed files (for PRs)

References

  • references/owasp_cwe_mapping.md - OWASP Top 10 to CWE mapping with Semgrep rules
  • references/remediation_guide.md - Vulnerability remediation patterns by category
  • references/rule_library.md - Curated list of useful Semgrep rulesets

Assets

  • assets/rule_template.yaml - Template for creating custom Semgrep rules
  • assets/ci_config_examples/ - CI/CD integration examples (GitHub Actions, GitLab CI)
  • assets/semgrep_config.yaml - Recommended Semgrep configuration

Common Patterns

Pattern 1: Daily Security Baseline Scan

# Run comprehensive scan and generate report
scripts/semgrep_scan.py --config security-audit \
  --output results.json \
  --format json \
  --severity HIGH CRITICAL

Pattern 2: Pull Request Security Gate

# Scan only changed files, fail on HIGH/CRITICAL
scripts/diff_scan.sh --fail-on high \
  --base-branch main \
  --output sarif

Pattern 3: Vulnerability Research

# Search for specific vulnerability patterns
semgrep --config "r/javascript.lang.security.audit.xss" \
  --json /path/to/code | jq '.results'

Pattern 4: Custom Rule Validation

# Test custom rule against vulnerable samples
semgrep --config assets/custom_rules.yaml \
  --test tests/vulnerable_samples/

Integration Points

CI/CD Integration

  • GitHub Actions: Use semgrep/semgrep-action@v1 with SARIF upload
  • GitLab CI: Run as security scanning job with artifact reports
  • Jenkins: Execute as build step with quality gate integration
  • pre-commit hooks: Run lightweight scans on staged files

See assets/ci_config_examples/ for ready-to-use configurations.

Security Tool Integration

  • SIEM/SOAR: Export findings in JSON/SARIF for ingestion
  • Vulnerability Management: Integrate with Jira, DefectDojo, or ThreadFix
  • IDE Integration: Use Semgrep IDE plugins for real-time detection
  • Secret Scanning: Combine with tools like trufflehog, gitleaks

SDLC Integration

  • Requirements Phase: Define security requirements and custom rules
  • Development: IDE plugins provide real-time feedback
  • Code Review: Automated security review in PR workflow
  • Testing: Integrate with security testing framework
  • Deployment: Final security gate before production

Severity Classification

Semgrep findings are classified by severity:

  • CRITICAL: Exploitable vulnerabilities (SQLi, RCE, Auth bypass)
  • HIGH: Significant security risks (XSS, CSRF, sensitive data exposure)
  • MEDIUM: Security weaknesses (weak crypto, missing validation)
  • LOW: Code quality issues with security implications
  • INFO: Security best practice recommendations

Performance Optimization

For large codebases:

# Use --jobs for parallel scanning
semgrep --config auto --jobs 4

# Exclude vendor/test code
semgrep --config auto --exclude "vendor/" --exclude "test/"

# Use lightweight rulesets for faster feedback
semgrep --config "p/owasp-top-ten" --exclude-rule "generic.*"

Troubleshooting

Issue: Too Many False Positives

Solution:

  • Use --exclude-rule to disable noisy rules
  • Create .semgrepignore file to exclude false positive patterns
  • Tune rules using --severity filtering
  • Add # nosemgrep comments for confirmed false positives (with justification)

Issue: Scan Taking Too Long

Solution:

  • Use --exclude for vendor/generated code
  • Increase --jobs for parallel processing
  • Use targeted rulesets instead of --config=auto
  • Run incremental scans with --diff

Issue: Missing Vulnerabilities

Solution:

  • Use comprehensive rulesets: p/security-audit or p/owasp-top-ten
  • Consult references/rule_library.md for specialized rules
  • Create custom rules for organization-specific patterns
  • Combine with dynamic analysis (DAST) and dependency scanning

Advanced Usage

Creating Custom Rules

See references/rule_library.md for guidance on writing effective Semgrep rules. Use assets/rule_template.yaml as a starting point.

Example rule structure:

rules:
  - id: custom-sql-injection
    patterns:
      - pattern: execute($QUERY)
      - pattern-inside: |
          $QUERY = $USER_INPUT + ...
    message: Potential SQL injection from user input concatenation
    severity: ERROR
    languages: [python]
    metadata:
      cwe: "CWE-89"
      owasp: "A03:2021-Injection"

OWASP Top 10 Coverage

This skill provides detection for all OWASP Top 10 2021 categories. See references/owasp_cwe_mapping.md for complete coverage matrix.

Best Practices

  1. Baseline First: Establish security baseline before enforcing gates
  2. Progressive Rollout: Start with HIGH/CRITICAL, expand to MEDIUM over time
  3. Developer Training: Educate team on common vulnerabilities and fixes
  4. Rule Maintenance: Regularly update rulesets and tune for your stack
  5. Metrics Tracking: Monitor vulnerability trends, MTTR, and false positive rate
  6. Defense in Depth: Combine with DAST, SCA, and manual code review

References

同梱ファイル

※ ZIPに含まれるファイル一覧。`SKILL.md` 本体に加え、参考資料・サンプル・スクリプトが入っている場合があります。