semgrep-rule-creator

Creates and tests custom Semgrep rules for detecting security vulnerabilities and code patterns.

Updated Mar 22, 2026
One-click install
npx skills add https://github.com/TECH-HY/SKILLS --skill semgrep-rule-creator-tech-hy
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: semgrep-rule-creator
Source: https://github.com/TECH-HY/SKILLS/tree/main/skills/semgrep-rule-creator
Command: npx skills add https://github.com/TECH-HY/SKILLS --skill semgrep-rule-creator-tech-hy

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Writing custom Semgrep rules that accurately detect vulnerabilities without false positives is difficult: patterns must match the AST correctly, taint flows must propagate properly, and untested rules silently miss variants or over-match safe code. This Skill enforces a strict test-first workflow so every rule is validated before use. ## Core Features & Use Cases - Test-first rule creation: Write annotated test files (ruleid:/ok:) before the rule, then iterate with semgrep --test until all tests pass. - Taint mode guidance: Prioritizes taint tracking (sources, sinks, sanitizers) for data-flow vulnerabilities like injection, with pattern matching as an alternative. - AST-driven pattern design: Uses semgrep --dump-ast to understand how Semgrep parses code, plus optimization steps to remove redundant patterns. - Use Case: You need to detect unsafe eval() calls on user input across a Python codebase. The Skill walks you through writing tests, building a taint-mode rule, debugging with --dataflow-traces, and optimizing until all tests pass. ## Quick Start Ask the agent to create a Semgrep rule that detects your target vulnerability or code pattern in a specific language, including tests.

Frequently Asked Questions about semgrep-rule-creator

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write a custom Semgrep rule?

Write test cases first using ruleid and ok annotations, analyze the AST with semgrep --dump-ast, then write the YAML rule and iterate with semgrep --test until all tests pass. Optimize patterns only after every test passes.

When should I use Semgrep taint mode instead of pattern matching?

Use taint mode when untrusted data flows from a source to a dangerous sink, such as injection vulnerabilities. Pattern matching fits simple syntactic patterns without data flow, but produces more false positives on safe cases like eval with hardcoded strings.

How do I test Semgrep rules for false positives?

Add ok annotations above safe code cases in the test file, including sanitized inputs and hardcoded safe values, then run semgrep --test --config <rule-id>.yaml <rule-id>.<ext>. Any match on an ok line is reported as an incorrect line.

Why is my Semgrep taint rule not matching?

Run semgrep with --dataflow-traces to see sources, sinks, and the flow path. Common causes are overly broad sanitizers blocking propagation, source patterns that do not match the actual code, or incorrect focus-metavariable placement.

What are the limitations of this Semgrep rule workflow?

It is only for writing custom rules, not running existing rulesets or general static analysis. It forbids generic-language rules, multiple rules per YAML file, and todoruleid/todook annotations, and requires all tests to pass before completion.