🛠️ Semgrep Rule Creator
セキュリティ脆弱性やバグパターンを検出するSemgrepルールを、カスタムで自動生成するSkill。
📺 まず動画で見る(YouTube)
▶ 【衝撃】最強のAIエージェント「Claude Code」の最新機能・使い方・プログラミングをAIで効率化する超実践術を解説! ↗
※ jpskill.com 編集部が参考用に選んだ動画です。動画の内容と Skill の挙動は厳密には一致しないことがあります。
📜 元の英語説明(参考)
Creates custom Semgrep rules for detecting security vulnerabilities, bug patterns, and code patterns. Use when writing Semgrep rules or building custom static analysis detections.
🇯🇵 日本人クリエイター向け解説
セキュリティ脆弱性やバグパターンを検出するSemgrepルールを、カスタムで自動生成するSkill。
※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。
下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o semgrep-rule-creator.zip https://jpskill.com/download/3437.zip && unzip -o semgrep-rule-creator.zip && rm semgrep-rule-creator.zip
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/3437.zip -OutFile "$d\semgrep-rule-creator.zip"; Expand-Archive "$d\semgrep-rule-creator.zip" -DestinationPath $d -Force; ri "$d\semgrep-rule-creator.zip"
完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。
💾 手動でダウンロードしたい(コマンドが難しい人向け)
- 1. 下の青いボタンを押して
semgrep-rule-creator.zipをダウンロード - 2. ZIPファイルをダブルクリックで解凍 →
semgrep-rule-creatorフォルダができる - 3. そのフォルダを
C:\Users\あなたの名前\.claude\skills\(Win)または~/.claude/skills/(Mac)へ移動 - 4. Claude Code を再起動
⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。
🎯 このSkillでできること
下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。
📦 インストール方法 (3ステップ)
- 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
- 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
- 3. 展開してできたフォルダを、ホームフォルダの
.claude/skills/に置く- · macOS / Linux:
~/.claude/skills/ - · Windows:
%USERPROFILE%\.claude\skills\
- · macOS / Linux:
Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。
詳しい使い方ガイドを見る →- 最終更新
- 2026-05-17
- 取得日時
- 2026-05-17
- 同梱ファイル
- 1
💬 こう話しかけるだけ — サンプルプロンプト
- › Semgrep Rule Creator を使って、最小構成のサンプルコードを示して
- › Semgrep Rule Creator の主な使い方と注意点を教えて
- › Semgrep Rule Creator を既存プロジェクトに組み込む方法を教えて
これをClaude Code に貼るだけで、このSkillが自動発動します。
📖 Skill本文(日本語訳)
※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。
[スキル名] semgrep-rule-creator
Semgrep ルールクリエーター
適切なテストと検証を行い、本番環境で利用できる品質の Semgrep ルールを作成します。
使用するタイミング
理想的なシナリオ:
- 特定のバグパターンに対する Semgrep ルールを作成する場合
- コードベースのセキュリティ脆弱性を検出するルールを作成する場合
- データフローの脆弱性に対する taint モードのルールを作成する場合
- コーディング標準を強制するルールを作成する場合
使用しないタイミング
このスキルは以下の目的には使用しないでください。
- 既存の Semgrep ルールセットを実行する場合
- カスタムルールなしの一般的な静的解析(
static-analysisスキルを使用してください)
却下すべき合理化
Semgrep ルールを作成する際、以下の一般的な近道は却下してください。
- 「パターンは完成しているように見える」 →
semgrep --test --config <rule-id>.yaml <rule-id>.<ext>を実行して検証してください。テストされていないルールには、隠れた誤検知/誤検知漏れがあります。 - 「脆弱なケースに一致する」 → 脆弱性に一致させるのは仕事の半分です。安全なケースが一致しないこと(誤検知は信頼を損ないます)を確認してください。
- 「これには taint モードはやりすぎだ」 → ユーザー入力から危険なシンクにデータが流れる場合、taint モードはパターンマッチングよりも優れた精度を提供します。
- 「テストは1つで十分だ」 → 異なるコーディングスタイル、サニタイズされた入力、安全な代替手段、境界条件など、エッジケースを含めてください。
- 「まずパターンを最適化する」 → まず正しいパターンを作成し、すべてのテストがパスした後に最適化してください。時期尚早な最適化は回帰を引き起こします。
- 「AST ダンプは複雑すぎる」 → AST は Semgrep がコードをどのように見ているかを正確に示します。これをスキップすると、構文のバリエーションを見逃すパターンにつながります。
アンチパターン
広すぎる - すべてに一致し、検出には役に立ちません。
# BAD: 任意の関数呼び出しに一致
pattern: $FUNC(...)
# GOOD: 特定の危険な関数
pattern: eval(...)
テストで安全なケースが欠落している - 未検出の誤検知につながります。
# BAD: 脆弱なケースのみをテスト
# ruleid: my-rule
dangerous(user_input)
# GOOD: 誤検知がないことを確認するために安全なケースを含める
# ruleid: my-rule
dangerous(user_input)
# ok: my-rule
dangerous(sanitize(user_input))
# ok: my-rule
dangerous("hardcoded_safe_value")
過度に具体的なパターン - バリエーションを見逃します。
# BAD: 正確な形式のみに一致
pattern: os.system("rm " + $VAR)
# GOOD: taint トラッキングを使用してすべての os.system 呼び出しに一致
mode: taint
pattern-sinks:
- pattern: os.system(...)
厳格性レベル
このワークフローは厳格です。手順をスキップしないでください。
- まずドキュメントを読む: Semgrep ルールを作成する前に、「ドキュメント」を参照してください。
- テストファーストは必須: テストなしでルールを作成しないでください。
- 100% のテスト合格が必須: 「ほとんどのテストが合格」は許容されません。
- 最適化は最後: すべてのテストが合格した後にのみパターンを簡素化してください。
- 一般的なパターンを避ける: ルールは具体的でなければならず、広範なパターンに一致させてはいけません。
- taint モードを優先する: データフローの脆弱性の場合。
- 1つの YAML ファイル - 1つの Semgrep ルール: 各 YAML ファイルには1つの Semgrep ルールのみを含める必要があります。複数のルールを1つのファイルに結合しないでください。
- 一般的なルールなし: Semgrep ルールで特定の言語をターゲットにする場合、一般的なパターンマッチング(
languages: generic)は避けてください。 todookおよびtodoruleidテストアノテーションは禁止: 将来のルール改善のためのテストファイル内のtodoruleid: <rule-id>およびtodook: <rule-id>アノテーションは禁止されています。
概要
このスキルは、セキュリティ脆弱性やコードパターンを検出する Semgrep ルールの作成をガイドします。ルールは反復的に作成されます。問題を分析し、まずテストを作成し、AST 構造を分析し、ルールを作成し、すべてのテストが合格するまで反復し、ルールを最適化します。
アプローチの選択:
- Taint モード(優先): 信頼できない入力が危険なシンクに到達するデータフローの問題
- パターンマッチング: データフロー要件のない単純な構文パターン
なぜ taint モードを優先するのか? パターンマッチングは構文を見つけますが、コンテキストを見逃します。パターン eval($X) は eval(user_input)(脆弱)と eval("safe_literal")(安全)の両方に一致します。Taint モードはデータフローを追跡するため、信頼できないデータが実際にシンクに到達した場合にのみ警告を発します。これにより、インジェクションの脆弱性に対する誤検知が劇的に減少します。
アプローチ間の反復: 実験することは問題ありません。taint モードから始めてうまくいかない場合(例: taint が期待どおりに伝播しない、誤検知/誤検知漏れが多すぎる)、パターンマッチングに切り替えてください。逆に、パターンマッチングが安全なケースで誤検知を多発する場合、代わりに taint モードを試してください。目標は機能するルールであり、1つのアプローチに固執することではありません。
出力構造 - ルール ID にちなんで名付けられたディレクトリに正確に2つのファイル:
<rule-id>/
├── <rule-id>.yaml # Semgrep ルール
└── <rule-id>.<ext> # ruleid/ok アノテーション付きのテストファイル
クイックスタート
rules:
- id: insecure-eval
languages: [python]
severity: HIGH
message: User input passed to eval() allows code execution
mode: taint
pattern-sources:
- pattern: request.args.get(...)
pattern-sinks:
- pattern: eval(...)
テストファイル(insecure-eval.py):
# ruleid: insecure-eval
eval(request.args.get('code'))
# ok: insecure-eval
eval("print('safe')")
テストの実行(ルールディレクトリから): semgrep --test --config <rule-id>.yaml <rule-id>.<ext>
クイックリファレンス
- コマンド、パターン演算子、taint モードの構文については、quick-reference.md を参照してください。
- 詳細なワークフローと例については、workflow.md を必ず参照してください。
ワークフロー
このチェックリストをコピーして進捗を追跡してください。
Semgrep ルールの進捗:
- [ ] ステップ1: 問題を分析する
- [ ] ステップ2: まずテストを作成する
- [ ] ステップ3: AST 構造を分析する
- [ ] ステップ4: ルールを作成する
- [ ] ステップ5: すべてのテストが合格するまで反復する (semgrep --test)
- [ ] ステップ6: ルールを最適化する (冗長性を削除し、再テストする)
- [ ] ステップ7: 最終実行
ドキュメント
必須: ルールを作成する前に、WebFetch を使用して Semgrep ドキュメントのこれら4つのリンクすべてを読んでください。
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開
Semgrep Rule Creator
Create production-quality Semgrep rules with proper testing and validation.
When to Use
Ideal scenarios:
- Writing Semgrep rules for specific bug patterns
- Writing rules to detect security vulnerabilities in your codebase
- Writing taint mode rules for data flow vulnerabilities
- Writing rules to enforce coding standards
When NOT to Use
Do NOT use this skill for:
- Running existing Semgrep rulesets
- General static analysis without custom rules (use
static-analysisskill)
Rationalizations to Reject
When writing Semgrep rules, reject these common shortcuts:
- "The pattern looks complete" → Still run
semgrep --test --config <rule-id>.yaml <rule-id>.<ext>to verify. Untested rules have hidden false positives/negatives. - "It matches the vulnerable case" → Matching vulnerabilities is half the job. Verify safe cases don't match (false positives break trust).
- "Taint mode is overkill for this" → If data flows from user input to a dangerous sink, taint mode gives better precision than pattern matching.
- "One test is enough" → Include edge cases: different coding styles, sanitized inputs, safe alternatives, and boundary conditions.
- "I'll optimize the patterns first" → Write correct patterns first, optimize after all tests pass. Premature optimization causes regressions.
- "The AST dump is too complex" → The AST reveals exactly how Semgrep sees code. Skipping it leads to patterns that miss syntactic variations.
Anti-Patterns
Too broad - matches everything, useless for detection:
# BAD: Matches any function call
pattern: $FUNC(...)
# GOOD: Specific dangerous function
pattern: eval(...)
Missing safe cases in tests - leads to undetected false positives:
# BAD: Only tests vulnerable case
# ruleid: my-rule
dangerous(user_input)
# GOOD: Include safe cases to verify no false positives
# ruleid: my-rule
dangerous(user_input)
# ok: my-rule
dangerous(sanitize(user_input))
# ok: my-rule
dangerous("hardcoded_safe_value")
Overly specific patterns - misses variations:
# BAD: Only matches exact format
pattern: os.system("rm " + $VAR)
# GOOD: Matches all os.system calls with taint tracking
mode: taint
pattern-sinks:
- pattern: os.system(...)
Strictness Level
This workflow is strict - do not skip steps:
- Read documentation first: See Documentation before writing Semgrep rules
- Test-first is mandatory: Never write a rule without tests
- 100% test pass is required: "Most tests pass" is not acceptable
- Optimization comes last: Only simplify patterns after all tests pass
- Avoid generic patterns: Rules must be specific, not match broad patterns
- Prioritize taint mode: For data flow vulnerabilities
- One YAML file - one Semgrep rule: Each YAML file must contain only one Semgrep rule; don't combine multiple rules in a single file
- No generic rules: When targeting a specific language for Semgrep rules - avoid generic pattern matching (
languages: generic) - Forbidden
todookandtodoruleidtest annotations:todoruleid: <rule-id>andtodook: <rule-id>annotations in tests files for future rule improvements are forbidden
Overview
This skill guides creation of Semgrep rules that detect security vulnerabilities and code patterns. Rules are created iteratively: analyze the problem, write tests first, analyze AST structure, write the rule, iterate until all tests pass, optimize the rule.
Approach selection:
- Taint mode (prioritize): Data flow issues where untrusted input reaches dangerous sinks
- Pattern matching: Simple syntactic patterns without data flow requirements
Why prioritize taint mode? Pattern matching finds syntax but misses context. A pattern eval($X) matches both eval(user_input) (vulnerable) and eval("safe_literal") (safe). Taint mode tracks data flow, so it only alerts when untrusted data actually reaches the sink—dramatically reducing false positives for injection vulnerabilities.
Iterating between approaches: It's okay to experiment. If you start with taint mode and it's not working well (e.g., taint doesn't propagate as expected, too many false positives/negatives), switch to pattern matching. Conversely, if pattern matching produces too many false positives on safe cases, try taint mode instead. The goal is a working rule—not rigid adherence to one approach.
Output structure - exactly 2 files in a directory named after the rule-id:
<rule-id>/
├── <rule-id>.yaml # Semgrep rule
└── <rule-id>.<ext> # Test file with ruleid/ok annotations
Quick Start
rules:
- id: insecure-eval
languages: [python]
severity: HIGH
message: User input passed to eval() allows code execution
mode: taint
pattern-sources:
- pattern: request.args.get(...)
pattern-sinks:
- pattern: eval(...)
Test file (insecure-eval.py):
# ruleid: insecure-eval
eval(request.args.get('code'))
# ok: insecure-eval
eval("print('safe')")
Run tests (from rule directory): semgrep --test --config <rule-id>.yaml <rule-id>.<ext>
Quick Reference
- For commands, pattern operators, and taint mode syntax, see quick-reference.md.
- For detailed workflow and examples, you MUST see workflow.md
Workflow
Copy this checklist and track progress:
Semgrep Rule Progress:
- [ ] Step 1: Analyze the Problem
- [ ] Step 2: Write Tests First
- [ ] Step 3: Analyze AST structure
- [ ] Step 4: Write the rule
- [ ] Step 5: Iterate until all tests pass (semgrep --test)
- [ ] Step 6: Optimize the rule (remove redundancies, re-test)
- [ ] Step 7: Final Run
Documentation
REQUIRED: Before writing any rule, use WebFetch to read all of these 4 links with Semgrep documentation:
Limitations
- Use this skill only when the task clearly matches the scope described above.
- Do not treat the output as a substitute for environment-specific validation, testing, or expert review.
- Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.